Skip to content

Commit 2ba9058

Browse files
committed
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>
1 parent 869b07e commit 2ba9058

File tree

11 files changed

+48
-38
lines changed

11 files changed

+48
-38
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ repos:
2424
hooks:
2525
- id: black
2626
args: ['-S', '-l', '79']
27+
- repo: https://github.com/astral-sh/ruff-pre-commit
28+
rev: v0.6.2
29+
hooks:
30+
- id: ruff
31+
args: ['--fix']
2732
- repo: https://github.com/PyCQA/bandit
2833
rev: 1.7.9
2934
hooks:

openstackclient/common/quota.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def get_network_quotas(
176176
default=False,
177177
):
178178
def _network_quota_to_dict(network_quota, detail=False):
179-
if type(network_quota) is not dict:
179+
if not isinstance(network_quota, dict):
180180
dict_quota = network_quota.to_dict()
181181
else:
182182
dict_quota = network_quota

openstackclient/compute/v2/flavor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ def take_action(self, parsed_args):
577577
parsed_args.flavor, get_extra_specs=True, ignore_missing=False
578578
)
579579
except sdk_exceptions.ResourceNotFound as e:
580-
raise exceptions.CommandError(_(e.message))
580+
raise exceptions.CommandError(e.message)
581581

582582
result = 0
583583
if parsed_args.properties:

openstackclient/compute/v2/server_migration.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,17 @@ def _get_migration_by_uuid(compute_client, server_id, migration_uuid):
253253
if migration.uuid == migration_uuid:
254254
return migration
255255
else:
256-
msg = _('In-progress live migration %s is not found for server %s.')
257-
raise exceptions.CommandError(msg % (migration_uuid, server_id))
256+
msg = _(
257+
'In-progress live migration %(migration)s is not found for '
258+
'server %(server)s'
259+
)
260+
raise exceptions.CommandError(
261+
msg
262+
% {
263+
'migration': migration_uuid,
264+
'server': server_id,
265+
}
266+
)
258267

259268

260269
class ShowMigration(command.ShowOne):

openstackclient/image/v2/image.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1614,8 +1614,6 @@ def get_parser(self, prog_name):
16141614
metavar='<image>',
16151615
help=_('Image to initiate import process for (name or ID)'),
16161616
)
1617-
# TODO(stephenfin): Uncomment help text when we have this command
1618-
# implemented
16191617
parser.add_argument(
16201618
'--method',
16211619
metavar='<method>',
@@ -1630,8 +1628,6 @@ def get_parser(self, prog_name):
16301628
help=_(
16311629
"Import method used for image import process. "
16321630
"Not all deployments will support all methods. "
1633-
# "Valid values can be retrieved with the 'image import "
1634-
# "methods' command. "
16351631
"The 'glance-direct' method (default) requires images be "
16361632
"first staged using the 'image-stage' command."
16371633
),
@@ -1734,11 +1730,15 @@ def take_action(self, parsed_args):
17341730

17351731
if parsed_args.import_method not in import_methods:
17361732
msg = _(
1737-
"The '%s' import method is not supported by this deployment. "
1738-
"Supported: %s"
1733+
"The '%(method)s' import method is not supported by this "
1734+
"deployment. Supported: %(supported)s"
17391735
)
17401736
raise exceptions.CommandError(
1741-
msg % (parsed_args.import_method, ', '.join(import_methods)),
1737+
msg
1738+
% {
1739+
'method': parsed_args.import_method,
1740+
'supported': ', '.join(import_methods),
1741+
},
17421742
)
17431743

17441744
if parsed_args.import_method == 'web-download':

openstackclient/image/v2/metadef_objects.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,12 @@ def take_action(self, parsed_args):
260260
prop['name'] = parsed_args.property
261261

262262
except KeyError:
263-
msg = _('Property %s not found in object %s.') % (
264-
parsed_args.property,
265-
parsed_args.object,
266-
)
263+
msg = _(
264+
'Property %(property)s not found in object %(object)s.'
265+
) % {
266+
'property': parsed_args.property,
267+
'object': parsed_args.object,
268+
}
267269
raise exceptions.CommandError(msg)
268270

269271
return zip(*sorted(prop.items()))

openstackclient/volume/v2/volume_type.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def get_parser(self, prog_name):
171171
default=False,
172172
help=_(
173173
"Enabled replication for this volume type "
174-
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
174+
"(this is an alias for '--property replication_enabled=<is> True') "
175175
"(requires driver support)"
176176
),
177177
)
@@ -181,7 +181,7 @@ def get_parser(self, prog_name):
181181
dest='availability_zones',
182182
help=_(
183183
"Set an availability zone for this volume type "
184-
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
184+
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
185185
"(repeat option to set multiple availability zones)"
186186
),
187187
)
@@ -535,7 +535,7 @@ def get_parser(self, prog_name):
535535
default=False,
536536
help=_(
537537
"Enabled replication for this volume type "
538-
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
538+
"(this is an alias for '--property replication_enabled=<is> True') "
539539
"(requires driver support)"
540540
),
541541
)
@@ -545,7 +545,7 @@ def get_parser(self, prog_name):
545545
dest='availability_zones',
546546
help=_(
547547
"Set an availability zone for this volume type "
548-
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
548+
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
549549
"(repeat option to set multiple availability zones)"
550550
),
551551
)

openstackclient/volume/v3/volume.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def get_parser(self, prog_name):
154154
"Cinder cluster on which the existing volume resides; "
155155
"takes the form: cluster@backend-name#pool. This is only "
156156
"used along with the --remote-source option. "
157-
"(supported by --os-volume-api-version 3.16 or above)",
157+
"(supported by --os-volume-api-version 3.16 or above)"
158158
),
159159
)
160160
return parser

openstackclient/volume/v3/volume_group.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def get_parser(self, prog_name):
288288
default=False,
289289
help=_(
290290
'Delete the volume group even if it contains volumes. '
291-
'This will delete any remaining volumes in the group.',
291+
'This will delete any remaining volumes in the group.'
292292
),
293293
)
294294
return parser
@@ -582,18 +582,14 @@ def get_parser(self, prog_name):
582582
action='store_true',
583583
dest='allow_attached_volume',
584584
default=False,
585-
help=_(
586-
'Allow group with attached volumes to be failed over.',
587-
),
585+
help=_('Allow group with attached volumes to be failed over.'),
588586
)
589587
parser.add_argument(
590588
'--disallow-attached-volume',
591589
action='store_false',
592590
dest='allow_attached_volume',
593591
default=False,
594-
help=_(
595-
'Disallow group with attached volumes to be failed over.',
596-
),
592+
help=_('Disallow group with attached volumes to be failed over.'),
597593
)
598594
parser.add_argument(
599595
'--secondary-backend-id',

openstackclient/volume/v3/volume_type.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def get_parser(self, prog_name):
172172
default=False,
173173
help=_(
174174
"Enabled replication for this volume type "
175-
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
175+
"(this is an alias for '--property replication_enabled=<is> True') "
176176
"(requires driver support)"
177177
),
178178
)
@@ -182,7 +182,7 @@ def get_parser(self, prog_name):
182182
dest='availability_zones',
183183
help=_(
184184
"Set an availability zone for this volume type "
185-
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
185+
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
186186
"(repeat option to set multiple availability zones)"
187187
),
188188
)
@@ -448,7 +448,7 @@ def get_parser(self, prog_name):
448448
default=False,
449449
help=_(
450450
"List only volume types with replication enabled "
451-
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
451+
"(this is an alias for '--property replication_enabled=<is> True') "
452452
"(supported by --os-volume-api-version 3.52 or above)"
453453
),
454454
)
@@ -458,7 +458,7 @@ def get_parser(self, prog_name):
458458
dest='availability_zones',
459459
help=_(
460460
"List only volume types with this availability configured "
461-
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
461+
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
462462
"(repeat option to filter on multiple availability zones)"
463463
),
464464
)
@@ -617,7 +617,7 @@ def get_parser(self, prog_name):
617617
default=False,
618618
help=_(
619619
"Enabled replication for this volume type "
620-
"(this is an alias for '--property replication_enabled=<is> True') " # noqa: E501
620+
"(this is an alias for '--property replication_enabled=<is> True') "
621621
"(requires driver support)"
622622
),
623623
)
@@ -627,7 +627,7 @@ def get_parser(self, prog_name):
627627
dest='availability_zones',
628628
help=_(
629629
"Set an availability zone for this volume type "
630-
"(this is an alias for '--property RESKEY:availability_zones:<az>') " # noqa: E501
630+
"(this is an alias for '--property RESKEY:availability_zones:<az>') "
631631
"(repeat option to set multiple availability zones)"
632632
),
633633
)

0 commit comments

Comments
 (0)