Merge "pre-commit: Migrate from black to ruff format"

This commit is contained in:
Zuul
2024-09-11 21:16:47 +00:00
committed by Gerrit Code Review
26 changed files with 54 additions and 59 deletions

View File

@@ -19,16 +19,12 @@ repos:
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: ['--py38-plus'] args: ['--py38-plus']
- repo: https://github.com/psf/black
rev: 24.8.0
hooks:
- id: black
args: ['-S', '-l', '79']
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.2 rev: v0.6.2
hooks: hooks:
- id: ruff - id: ruff
args: ['--fix'] args: ['--fix']
- id: ruff-format
- repo: https://github.com/PyCQA/bandit - repo: https://github.com/PyCQA/bandit
rev: 1.7.9 rev: 1.7.9
hooks: hooks:

View File

@@ -12,6 +12,7 @@
# #
"""Base API Library""" """Base API Library"""
from keystoneauth1 import exceptions as ks_exceptions from keystoneauth1 import exceptions as ks_exceptions
from keystoneauth1 import session as ks_session from keystoneauth1 import session as ks_session
from osc_lib import exceptions from osc_lib import exceptions

View File

@@ -33,7 +33,7 @@ class APIv2(image_v1.APIv1):
private=False, private=False,
community=False, community=False,
shared=False, shared=False,
**filter **filter,
): ):
"""Get available images """Get available images

View File

@@ -89,7 +89,7 @@ class APIv1(api.BaseAPI):
marker=None, marker=None,
end_marker=None, end_marker=None,
prefix=None, prefix=None,
**params **params,
): ):
"""Get containers in an account """Get containers in an account
@@ -116,7 +116,7 @@ class APIv1(api.BaseAPI):
marker=marker, marker=marker,
end_marker=end_marker, end_marker=end_marker,
prefix=prefix, prefix=prefix,
**params **params,
) )
while listing: while listing:
marker = listing[-1]['name'] marker = listing[-1]['name']
@@ -125,7 +125,7 @@ class APIv1(api.BaseAPI):
marker=marker, marker=marker,
end_marker=end_marker, end_marker=end_marker,
prefix=prefix, prefix=prefix,
**params **params,
) )
if listing: if listing:
data.extend(listing) data.extend(listing)
@@ -306,7 +306,7 @@ class APIv1(api.BaseAPI):
end_marker=None, end_marker=None,
delimiter=None, delimiter=None,
prefix=None, prefix=None,
**params **params,
): ):
"""List objects in a container """List objects in a container
@@ -341,7 +341,7 @@ class APIv1(api.BaseAPI):
end_marker=end_marker, end_marker=end_marker,
prefix=prefix, prefix=prefix,
delimiter=delimiter, delimiter=delimiter,
**params **params,
) )
while listing: while listing:
if delimiter: if delimiter:
@@ -355,7 +355,7 @@ class APIv1(api.BaseAPI):
end_marker=end_marker, end_marker=end_marker,
prefix=prefix, prefix=prefix,
delimiter=delimiter, delimiter=delimiter,
**params **params,
) )
if listing: if listing:
data.extend(listing) data.extend(listing)

View File

@@ -87,7 +87,7 @@ class CreateProject(command.ShowOne):
parsed_args.name, parsed_args.name,
description=parsed_args.description, description=parsed_args.description,
enabled=enabled, enabled=enabled,
**kwargs **kwargs,
) )
except ks_exc.Conflict: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:

View File

@@ -11,7 +11,7 @@
# under the License. # under the License.
# #
"""Identity v2 Assignment action implementations """ """Identity v2 Assignment action implementations"""
from osc_lib.command import command from osc_lib.command import command
from osc_lib import exceptions from osc_lib import exceptions

View File

@@ -133,7 +133,7 @@ class CreateIdentityProvider(command.ShowOne):
description=parsed_args.description, description=parsed_args.description,
domain_id=domain_id, domain_id=domain_id,
enabled=parsed_args.enabled, enabled=parsed_args.enabled,
**kwargs **kwargs,
) )
idp._info.pop('links', None) idp._info.pop('links', None)

View File

@@ -125,7 +125,7 @@ class CreateProject(command.ShowOne):
description=parsed_args.description, description=parsed_args.description,
enabled=enabled, enabled=enabled,
options=options, options=options,
**kwargs **kwargs,
) )
except ks_exc.Conflict: except ks_exc.Conflict:
if parsed_args.or_show: if parsed_args.or_show:

View File

@@ -245,7 +245,7 @@ class SetConntrackHelper(command.Command):
client.update_conntrack_helper( client.update_conntrack_helper(
parsed_args.conntrack_helper_id, parsed_args.conntrack_helper_id,
attrs.pop('router_id'), attrs.pop('router_id'),
**attrs **attrs,
) )

View File

@@ -14,6 +14,7 @@
# under the License. # under the License.
"""Router NDP proxy action implementations""" """Router NDP proxy action implementations"""
import logging import logging
from osc_lib.command import command from osc_lib.command import command

View File

@@ -15,6 +15,7 @@
# #
"""Network trunk and subports action implementations""" """Network trunk and subports action implementations"""
import logging import logging
from cliff import columns as cliff_columns from cliff import columns as cliff_columns
@@ -67,8 +68,8 @@ class CreateNetworkTrunk(command.ShowOne):
required_keys=['port'], required_keys=['port'],
help=_( help=_(
"Subport to add. Subport is of form " "Subport to add. Subport is of form "
"\'port=<name or ID>,segmentation-type=<segmentation-type>," "'port=<name or ID>,segmentation-type=<segmentation-type>,"
"segmentation-id=<segmentation-ID>\' (--subport) option " "segmentation-id=<segmentation-ID>' (--subport) option "
"can be repeated" "can be repeated"
), ),
) )
@@ -198,8 +199,8 @@ class SetNetworkTrunk(command.Command):
required_keys=['port'], required_keys=['port'],
help=_( help=_(
"Subport to add. Subport is of form " "Subport to add. Subport is of form "
"\'port=<name or ID>,segmentation-type=<segmentation-type>" "'port=<name or ID>,segmentation-type=<segmentation-type>"
",segmentation-id=<segmentation-ID>\' (--subport) option " ",segmentation-id=<segmentation-ID>' (--subport) option "
"can be repeated" "can be repeated"
), ),
) )

View File

@@ -164,10 +164,13 @@ def _get_external_gateway_attrs(client_manager, parsed_args):
'subnet_id' in ip_spec 'subnet_id' in ip_spec
and ip_net_id not in external_gateways and ip_net_id not in external_gateways
): ):
msg = _( msg = (
_(
'Subnet %s does not belong to any of the networks ' 'Subnet %s does not belong to any of the networks '
'provided for --external-gateway.' 'provided for --external-gateway.'
) % (ip_spec['subnet_id']) )
% (ip_spec['subnet_id'])
)
raise exceptions.CommandError(msg) raise exceptions.CommandError(msg)
for gw_info in external_gateways[ip_net_id]: for gw_info in external_gateways[ip_net_id]:
if 'external_fixed_ips' not in gw_info: if 'external_fixed_ips' not in gw_info:

View File

@@ -26,7 +26,6 @@ from openstackclient.tests.unit import utils
class TestSecurityGroup(utils.TestCase): class TestSecurityGroup(utils.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@@ -227,7 +226,6 @@ class TestSecurityGroup(utils.TestCase):
class TestSecurityGroupRule(utils.TestCase): class TestSecurityGroupRule(utils.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@@ -290,7 +288,6 @@ class TestSecurityGroupRule(utils.TestCase):
class TestNetwork(utils.TestCase): class TestNetwork(utils.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@@ -457,7 +454,6 @@ class TestNetwork(utils.TestCase):
class TestFloatingIP(utils.TestCase): class TestFloatingIP(utils.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()
@@ -547,7 +543,6 @@ class TestFloatingIP(utils.TestCase):
class TestFloatingIPPool(utils.TestCase): class TestFloatingIPPool(utils.TestCase):
def setUp(self): def setUp(self):
super().setUp() super().setUp()

View File

@@ -59,7 +59,6 @@ def _generate_fake_host():
class TestHostList(compute_fakes.TestComputev2): class TestHostList(compute_fakes.TestComputev2):
def setUp(self): def setUp(self):
super().setUp() super().setUp()

View File

@@ -7363,9 +7363,7 @@ class TestServerRemoveSecurityGroup(TestServer):
self.server = compute_fakes.create_one_sdk_server() self.server = compute_fakes.create_one_sdk_server()
self.compute_sdk_client.find_server.return_value = self.server self.compute_sdk_client.find_server.return_value = self.server
self.compute_sdk_client.remove_security_group_from_server.return_value = ( self.compute_sdk_client.remove_security_group_from_server.return_value = None
None
)
# Get the command object to test # Get the command object to test
self.cmd = server.RemoveServerSecurityGroup(self.app, None) self.cmd = server.RemoveServerSecurityGroup(self.app, None)

View File

@@ -90,7 +90,7 @@ class TestLimitCreate(TestLimit):
self.service, self.service,
identity_fakes.limit_resource_name, identity_fakes.limit_resource_name,
resource_limit, resource_limit,
**kwargs **kwargs,
) )
collist = ( collist = (
@@ -154,7 +154,7 @@ class TestLimitCreate(TestLimit):
self.service, self.service,
identity_fakes.limit_resource_name, identity_fakes.limit_resource_name,
resource_limit, resource_limit,
**kwargs **kwargs,
) )
collist = ( collist = (

View File

@@ -42,9 +42,7 @@ class TestMetadefResourceTypeAssociationCreate(
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.image_client.create_metadef_resource_type_association.return_value = ( self.image_client.create_metadef_resource_type_association.return_value = self.resource_type_association
self.resource_type_association
)
self.cmd = metadef_resource_type_association.CreateMetadefResourceTypeAssociation( self.cmd = metadef_resource_type_association.CreateMetadefResourceTypeAssociation(
self.app, None self.app, None
) )
@@ -74,9 +72,7 @@ class TestMetadefResourceTypeAssociationDelete(
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.image_client.delete_metadef_resource_type_association.return_value = ( self.image_client.delete_metadef_resource_type_association.return_value = self.resource_type_association
self.resource_type_association
)
self.cmd = metadef_resource_type_association.DeleteMetadefResourceTypeAssociation( self.cmd = metadef_resource_type_association.DeleteMetadefResourceTypeAssociation(
self.app, None self.app, None
) )

View File

@@ -79,7 +79,7 @@ class TestCreateDefaultSecurityGroupRule(TestDefaultSecurityGroupRule):
default_security_group_rule_attrs.update(attrs) default_security_group_rule_attrs.update(attrs)
self._default_sg_rule = sdk_fakes.generate_fake_resource( self._default_sg_rule = sdk_fakes.generate_fake_resource(
_default_security_group_rule.DefaultSecurityGroupRule, _default_security_group_rule.DefaultSecurityGroupRule,
**default_security_group_rule_attrs **default_security_group_rule_attrs,
) )
self.sdk_client.create_default_security_group_rule.return_value = ( self.sdk_client.create_default_security_group_rule.return_value = (
@@ -956,11 +956,11 @@ class TestListDefaultSecurityGroupRule(TestDefaultSecurityGroupRule):
# The security group rule to be listed. # The security group rule to be listed.
_default_sg_rule_tcp = sdk_fakes.generate_fake_resource( _default_sg_rule_tcp = sdk_fakes.generate_fake_resource(
_default_security_group_rule.DefaultSecurityGroupRule, _default_security_group_rule.DefaultSecurityGroupRule,
**{'protocol': 'tcp', 'port_range_max': 80, 'port_range_min': 80} **{'protocol': 'tcp', 'port_range_max': 80, 'port_range_min': 80},
) )
_default_sg_rule_icmp = sdk_fakes.generate_fake_resource( _default_sg_rule_icmp = sdk_fakes.generate_fake_resource(
_default_security_group_rule.DefaultSecurityGroupRule, _default_security_group_rule.DefaultSecurityGroupRule,
**{'protocol': 'icmp', 'remote_ip_prefix': '10.0.2.0/24'} **{'protocol': 'icmp', 'remote_ip_prefix': '10.0.2.0/24'},
) )
_default_sg_rules = [ _default_sg_rules = [
_default_sg_rule_tcp, _default_sg_rule_tcp,

View File

@@ -153,7 +153,7 @@ class TestCreateFloatingIPPortForwarding(TestFloatingIPPortForwarding):
'internal_port_id': self.new_port_forwarding_with_ranges.internal_port_id, # noqa: E501 'internal_port_id': self.new_port_forwarding_with_ranges.internal_port_id, # noqa: E501
'protocol': self.new_port_forwarding_with_ranges.protocol, 'protocol': self.new_port_forwarding_with_ranges.protocol,
'description': self.new_port_forwarding_with_ranges.description, # noqa: E501 'description': self.new_port_forwarding_with_ranges.description, # noqa: E501
} },
) )
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@@ -334,7 +334,7 @@ class TestCreateFloatingIPPortForwarding(TestFloatingIPPortForwarding):
'internal_port_id': self.new_port_forwarding.internal_port_id, 'internal_port_id': self.new_port_forwarding.internal_port_id,
'protocol': self.new_port_forwarding.protocol, 'protocol': self.new_port_forwarding.protocol,
'description': self.new_port_forwarding.description, 'description': self.new_port_forwarding.description,
} },
) )
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@@ -587,7 +587,7 @@ class TestSetFloatingIPPortForwarding(TestFloatingIPPortForwarding):
self.network_client.update_floating_ip_port_forwarding.assert_called_with( self.network_client.update_floating_ip_port_forwarding.assert_called_with(
self._port_forwarding.floatingip_id, self._port_forwarding.floatingip_id,
self._port_forwarding.id, self._port_forwarding.id,
**attrs **attrs,
) )
self.assertIsNone(result) self.assertIsNone(result)
@@ -648,7 +648,7 @@ class TestSetFloatingIPPortForwarding(TestFloatingIPPortForwarding):
self.network_client.update_floating_ip_port_forwarding.assert_called_with( self.network_client.update_floating_ip_port_forwarding.assert_called_with(
self._port_forwarding.floatingip_id, self._port_forwarding.floatingip_id,
self._port_forwarding.id, self._port_forwarding.id,
**attrs **attrs,
) )
self.assertIsNone(result) self.assertIsNone(result)

View File

@@ -86,7 +86,7 @@ class TestCreateLocalIPAssociation(TestLocalIPAssociation):
self.new_local_ip_association.local_ip_id, self.new_local_ip_association.local_ip_id,
**{ **{
'fixed_port_id': self.new_local_ip_association.fixed_port_id, 'fixed_port_id': self.new_local_ip_association.fixed_port_id,
} },
) )
self.assertEqual(set(self.columns), set(columns)) self.assertEqual(set(self.columns), set(columns))
self.assertEqual(set(self.data), set(data)) self.assertEqual(set(self.data), set(data))
@@ -111,7 +111,7 @@ class TestCreateLocalIPAssociation(TestLocalIPAssociation):
**{ **{
'fixed_port_id': self.new_local_ip_association.fixed_port_id, 'fixed_port_id': self.new_local_ip_association.fixed_port_id,
'fixed_ip': self.new_local_ip_association.fixed_ip, 'fixed_ip': self.new_local_ip_association.fixed_ip,
} },
) )
self.assertEqual(set(self.columns), set(columns)) self.assertEqual(set(self.columns), set(columns))
self.assertEqual(set(self.data), set(data)) self.assertEqual(set(self.data), set(data))

View File

@@ -137,7 +137,7 @@ class TestCreateNetworkQosRuleMinimumBandwidth(TestNetworkQosRule):
**{ **{
'min_kbps': self.new_rule.min_kbps, 'min_kbps': self.new_rule.min_kbps,
'direction': self.new_rule.direction, 'direction': self.new_rule.direction,
} },
) )
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@@ -244,7 +244,7 @@ class TestCreateNetworkQosRuleMinimumPacketRate(TestNetworkQosRule):
**{ **{
'min_kpps': self.new_rule.min_kpps, 'min_kpps': self.new_rule.min_kpps,
'direction': self.new_rule.direction, 'direction': self.new_rule.direction,
} },
) )
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)
@@ -473,7 +473,7 @@ class TestCreateNetworkQosRuleBandwidtLimit(TestNetworkQosRule):
**{ **{
'max_kbps': self.new_rule.max_kbps, 'max_kbps': self.new_rule.max_kbps,
'direction': self.new_rule.direction, 'direction': self.new_rule.direction,
} },
) )
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(expected_data, data) self.assertEqual(expected_data, data)
@@ -507,7 +507,7 @@ class TestCreateNetworkQosRuleBandwidtLimit(TestNetworkQosRule):
'max_kbps': self.new_rule.max_kbps, 'max_kbps': self.new_rule.max_kbps,
'max_burst_kbps': self.new_rule.max_burst_kbits, 'max_burst_kbps': self.new_rule.max_burst_kbits,
'direction': self.new_rule.direction, 'direction': self.new_rule.direction,
} },
) )
self.assertEqual(self.columns, columns) self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data) self.assertEqual(self.data, data)

View File

@@ -1006,7 +1006,7 @@ class TestSetSubnetPool(TestSubnetPool):
self._subnet_pool, self._subnet_pool,
**{ **{
'default_quota': 20, 'default_quota': 20,
} },
) )
self.assertIsNone(result) self.assertIsNone(result)

View File

@@ -352,7 +352,7 @@ class TestObjectShow(TestObject):
c_mock.assert_called_with( c_mock.assert_called_with(
container=object_fakes.container_name, container=object_fakes.container_name,
object=object_fakes.object_name_1, object=object_fakes.object_name_1,
**kwargs **kwargs,
) )
collist = ('bytes', 'content_type', 'hash', 'last_modified', 'name') collist = ('bytes', 'content_type', 'hash', 'last_modified', 'name')

View File

@@ -93,7 +93,7 @@ def make_client(instance):
region_name=instance.region_name, region_name=instance.region_name,
endpoint_override=endpoint_override, endpoint_override=endpoint_override,
api_version=version, api_version=version,
**kwargs **kwargs,
) )
return client return client

View File

@@ -21,7 +21,6 @@ from openstackclient.volume.v2 import service as service_v2
class ListService(service_v2.ListService): class ListService(service_v2.ListService):
def take_action(self, parsed_args): def take_action(self, parsed_args):
service_client = self.app.client_manager.volume service_client = self.app.client_manager.volume

6
pyproject.toml Normal file
View File

@@ -0,0 +1,6 @@
[tool.ruff]
line-length = 79
[tool.ruff.format]
quote-style = "preserve"
docstring-code-format = true