Skip to content

Commit

Permalink
pre-commit: Migrate pyupgrade to ruff-format
Browse files Browse the repository at this point in the history
openstack/tests/unit/cloud/test_stack.py needs some manual fixes but
this is otherwise auto-generated.

Change-Id: If0d202ece232181c16ee4990eb428e9ad6e91cd5
Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Nov 12, 2024
1 parent 33b5bfa commit 399dfcc
Show file tree
Hide file tree
Showing 125 changed files with 967 additions and 1,838 deletions.
7 changes: 1 addition & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ repos:
rev: v1.1.2
hooks:
- id: doc8
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.0
hooks:
- id: pyupgrade
args: ['--py38-plus']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
hooks:
- id: ruff
args: ['--fix']
args: ['--fix', '--unsafe-fixes']
- id: ruff-format
- repo: https://opendev.org/openstack/hacking
rev: 7.0.0
Expand Down
8 changes: 2 additions & 6 deletions examples/compute/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def create_keypair(conn):
raise e

with open(PRIVATE_KEYPAIR_FILE, 'w') as f:
f.write("%s" % keypair.private_key)
f.write(str(keypair.private_key))

os.chmod(PRIVATE_KEYPAIR_FILE, 0o400)

Expand All @@ -71,8 +71,4 @@ def create_server(conn):

server = conn.compute.wait_for_server(server)

print(
"ssh -i {key} root@{ip}".format(
key=PRIVATE_KEYPAIR_FILE, ip=server.access_ipv4
)
)
print(f"ssh -i {PRIVATE_KEYPAIR_FILE} root@{server.access_ipv4}")
5 changes: 3 additions & 2 deletions openstack/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@

def show_version(args):
print(
"OpenstackSDK Version %s"
% pbr.version.VersionInfo('openstacksdk').version_string_with_vcs()
"OpenstackSDK Version {}".format(
pbr.version.VersionInfo('openstacksdk').version_string_with_vcs()
)
)


Expand Down
2 changes: 1 addition & 1 deletion openstack/accelerator/v2/deployable.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _commit(
call = getattr(session, method.lower())
except AttributeError:
raise exceptions.ResourceFailure(
"Invalid commit method: %s" % method
f"Invalid commit method: {method}"
)

request.url = request.url + "/program"
Expand Down
9 changes: 3 additions & 6 deletions openstack/baremetal/configdrive.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def populate_directory(
# Strictly speaking, user data is binary, but in many cases
# it's actually a text (cloud-init, ignition, etc).
flag = 't' if isinstance(user_data, str) else 'b'
with open(
os.path.join(subdir, 'user_data'), 'w%s' % flag
) as fp:
with open(os.path.join(subdir, 'user_data'), f'w{flag}') as fp:
fp.write(user_data)

yield d
Expand Down Expand Up @@ -147,15 +145,14 @@ def pack(path: str) -> str:
raise RuntimeError(
'Error generating the configdrive. Make sure the '
'"genisoimage", "mkisofs" or "xorrisofs" tool is installed. '
'Error: %s' % error
f'Error: {error}'
)

stdout, stderr = p.communicate()
if p.returncode != 0:
raise RuntimeError(
'Error generating the configdrive.'
'Stdout: "%(stdout)s". Stderr: "%(stderr)s"'
% {'stdout': stdout.decode(), 'stderr': stderr.decode()}
f'Stdout: "{stdout.decode()}". Stderr: "{stderr.decode()}"'
)

tmpfile.seek(0)
Expand Down
9 changes: 3 additions & 6 deletions openstack/baremetal/v1/_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ def _get_with_fields(self, resource_type, value, fields=None):
kwargs['fields'] = _common.fields_type(fields, resource_type)
return res.fetch(
self,
error_message="No {resource_type} found for {value}".format(
resource_type=resource_type.__name__, value=value
),
error_message=f"No {resource_type.__name__} found for {value}",
**kwargs,
)

Expand Down Expand Up @@ -560,9 +558,8 @@ def wait_for_nodes_provision_state(
try:
for count in utils.iterate_timeout(
timeout,
"Timeout waiting for nodes %(nodes)s to reach "
"target state '%(state)s'"
% {'nodes': log_nodes, 'state': expected_state},
f"Timeout waiting for nodes {log_nodes} to reach "
f"target state '{expected_state}'",
):
nodes = [self.get_node(n) for n in remaining]
remaining = []
Expand Down
5 changes: 2 additions & 3 deletions openstack/baremetal/v1/allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,13 @@ def wait(self, session, timeout=None, ignore_error=False):
return self

for count in utils.iterate_timeout(
timeout, "Timeout waiting for the allocation %s" % self.id
timeout, f"Timeout waiting for the allocation {self.id}"
):
self.fetch(session)

if self.state == 'error' and not ignore_error:
raise exceptions.ResourceFailure(
"Allocation %(allocation)s failed: %(error)s"
% {'allocation': self.id, 'error': self.last_error}
f"Allocation {self.id} failed: {self.last_error}"
)
elif self.state != 'allocating':
return self
Expand Down
4 changes: 1 addition & 3 deletions openstack/baremetal/v1/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,6 @@ def call_vendor_passthru(
retriable_status_codes=_common.RETRIABLE_STATUS_CODES,
)

msg = "Failed call to method {method} on driver {driver_name}".format(
method=method, driver_name=self.name
)
msg = f"Failed call to method {method} on driver {self.name}"
exceptions.raise_from_response(response, error_message=msg)
return response
Loading

0 comments on commit 399dfcc

Please sign in to comment.