pre-commit: Migrate from flake8 to ruff

Well, mostly. We still keep our own flake8 hooks and the hacking hooks
enabled. Everything else can be handled by ruff.

Doing this enables a couple of hacking checks that were previously
unaddressed. It also highlights a few cases that flake8 missed. Both are
addressed.

Change-Id: If81c7055e9ef692425da2789bae18a96d04b104f
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2024-08-29 10:53:30 +01:00
parent 869b07eded
commit 2ba90581d5
11 changed files with 48 additions and 38 deletions

View File

@ -24,6 +24,11 @@ repos:
hooks:
- id: black
args: ['-S', '-l', '79']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.2
hooks:
- id: ruff
args: ['--fix']
- repo: https://github.com/PyCQA/bandit
rev: 1.7.9
hooks:

View File

@ -176,7 +176,7 @@ def get_network_quotas(
default=False,
):
def _network_quota_to_dict(network_quota, detail=False):
if type(network_quota) is not dict:
if not isinstance(network_quota, dict):
dict_quota = network_quota.to_dict()
else:
dict_quota = network_quota

View File

@ -577,7 +577,7 @@ class UnsetFlavor(command.Command):
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
)
except sdk_exceptions.ResourceNotFound as e:
raise exceptions.CommandError(_(e.message))
raise exceptions.CommandError(e.message)
result = 0
if parsed_args.properties:

View File

@ -253,8 +253,17 @@ def _get_migration_by_uuid(compute_client, server_id, migration_uuid):
if migration.uuid == migration_uuid:
return migration
else:
msg = _('In-progress live migration %s is not found for server %s.')
raise exceptions.CommandError(msg % (migration_uuid, server_id))
msg = _(
'In-progress live migration %(migration)s is not found for '
'server %(server)s'
)
raise exceptions.CommandError(
msg
% {
'migration': migration_uuid,
'server': server_id,
}
)
class ShowMigration(command.ShowOne):

View File

@ -1614,8 +1614,6 @@ class ImportImage(command.ShowOne):
metavar='<image>',
help=_('Image to initiate import process for (name or ID)'),
)
# TODO(stephenfin): Uncomment help text when we have this command
# implemented
parser.add_argument(
'--method',
metavar='<method>',
@ -1630,8 +1628,6 @@ class ImportImage(command.ShowOne):
help=_(
"Import method used for image import process. "
"Not all deployments will support all methods. "
# "Valid values can be retrieved with the 'image import "
# "methods' command. "
"The 'glance-direct' method (default) requires images be "
"first staged using the 'image-stage' command."
),
@ -1734,11 +1730,15 @@ class ImportImage(command.ShowOne):
if parsed_args.import_method not in import_methods:
msg = _(
"The '%s' import method is not supported by this deployment. "
"Supported: %s"
"The '%(method)s' import method is not supported by this "
"deployment. Supported: %(supported)s"
)
raise exceptions.CommandError(
msg % (parsed_args.import_method, ', '.join(import_methods)),
msg
% {
'method': parsed_args.import_method,
'supported': ', '.join(import_methods),
},
)
if parsed_args.import_method == 'web-download':

View File

@ -260,10 +260,12 @@ class ShowMetadefObjectProperty(command.ShowOne):
prop['name'] = parsed_args.property
except KeyError:
msg = _('Property %s not found in object %s.') % (
parsed_args.property,
parsed_args.object,
)
msg = _(
'Property %(property)s not found in object %(object)s.'
) % {
'property': parsed_args.property,
'object': parsed_args.object,
}
raise exceptions.CommandError(msg)
return zip(*sorted(prop.items()))

View File

@ -171,7 +171,7 @@ class CreateVolumeType(command.ShowOne):
default=False,
help=_(
"Enabled replication for this volume type "
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
"(this is an alias for '--property replication_enabled=<is> True') "
"(requires driver support)"
),
)
@ -181,7 +181,7 @@ class CreateVolumeType(command.ShowOne):
dest='availability_zones',
help=_(
"Set an availability zone for this volume type "
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
"(repeat option to set multiple availability zones)"
),
)
@ -535,7 +535,7 @@ class SetVolumeType(command.Command):
default=False,
help=_(
"Enabled replication for this volume type "
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
"(this is an alias for '--property replication_enabled=<is> True') "
"(requires driver support)"
),
)
@ -545,7 +545,7 @@ class SetVolumeType(command.Command):
dest='availability_zones',
help=_(
"Set an availability zone for this volume type "
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
"(repeat option to set multiple availability zones)"
),
)

View File

@ -154,7 +154,7 @@ class CreateVolume(volume_v2.CreateVolume):
"Cinder cluster on which the existing volume resides; "
"takes the form: cluster@backend-name#pool. This is only "
"used along with the --remote-source option. "
"(supported by --os-volume-api-version 3.16 or above)",
"(supported by --os-volume-api-version 3.16 or above)"
),
)
return parser

View File

@ -288,7 +288,7 @@ class DeleteVolumeGroup(command.Command):
default=False,
help=_(
'Delete the volume group even if it contains volumes. '
'This will delete any remaining volumes in the group.',
'This will delete any remaining volumes in the group.'
),
)
return parser
@ -582,18 +582,14 @@ class FailoverVolumeGroup(command.Command):
action='store_true',
dest='allow_attached_volume',
default=False,
help=_(
'Allow group with attached volumes to be failed over.',
),
help=_('Allow group with attached volumes to be failed over.'),
)
parser.add_argument(
'--disallow-attached-volume',
action='store_false',
dest='allow_attached_volume',
default=False,
help=_(
'Disallow group with attached volumes to be failed over.',
),
help=_('Disallow group with attached volumes to be failed over.'),
)
parser.add_argument(
'--secondary-backend-id',

View File

@ -172,7 +172,7 @@ class CreateVolumeType(command.ShowOne):
default=False,
help=_(
"Enabled replication for this volume type "
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
"(this is an alias for '--property replication_enabled=<is> True') "
"(requires driver support)"
),
)
@ -182,7 +182,7 @@ class CreateVolumeType(command.ShowOne):
dest='availability_zones',
help=_(
"Set an availability zone for this volume type "
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
"(repeat option to set multiple availability zones)"
),
)
@ -448,7 +448,7 @@ class ListVolumeType(command.Lister):
default=False,
help=_(
"List only volume types with replication enabled "
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
"(this is an alias for '--property replication_enabled=<is> True') "
"(supported by --os-volume-api-version 3.52 or above)"
),
)
@ -458,7 +458,7 @@ class ListVolumeType(command.Lister):
dest='availability_zones',
help=_(
"List only volume types with this availability configured "
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
"(repeat option to filter on multiple availability zones)"
),
)
@ -617,7 +617,7 @@ class SetVolumeType(command.Command):
default=False,
help=_(
"Enabled replication for this volume type "
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
"(this is an alias for '--property replication_enabled=<is> True') "
"(requires driver support)"
),
)
@ -627,7 +627,7 @@ class SetVolumeType(command.Command):
dest='availability_zones',
help=_(
"Set an availability zone for this volume type "
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
"(repeat option to set multiple availability zones)"
),
)

View File

@ -113,11 +113,9 @@ commands =
[flake8]
show-source = true
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,tools,releasenotes
# E203 Black will put spaces after colons in list comprehensions
# E501 Black takes care of line length for us
# E704 Black will occasionally put multiple statements on one line
# We only enable the hacking (H) checks
select = H
# H301 Black will put commas after imports that can't fit on one line
# W503 and W504 are disabled since they're not very useful
ignore = E203, E501, E701, H301, W503, W504
ignore = H301
import-order-style = pep8
application_import_names = openstackclient