From 33058cbe8e19195ddace8ad5adad7bf7927c731e Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Tue, 5 Aug 2014 21:35:12 +0200 Subject: [PATCH] Enable several checks and do not check docs/source/conf.py * E265 block comment should start with '# ' * H302 import only modules Do not check docs/source/conf.py. The file is imported from the cookiecutter template. Documented why checks are ignored and if they should be enabled in the future. Change-Id: I367064ecaa6d1fd9d918f7ce003303e2db660647 --- novaclient/shell.py | 8 ++++---- novaclient/tests/test_shell.py | 5 +++-- novaclient/tests/v1_1/fakes.py | 22 ++++++++++++++++------ novaclient/tests/v3/fakes.py | 14 ++++++++++---- novaclient/v1_1/servers.py | 6 ++++-- novaclient/v1_1/shell.py | 4 ++-- novaclient/v3/client.py | 2 +- novaclient/v3/shell.py | 2 +- tox.ini | 23 +++++++++++++++++++---- 9 files changed, 60 insertions(+), 26 deletions(-) diff --git a/novaclient/shell.py b/novaclient/shell.py index 08f5e8c40..984460ed0 100644 --- a/novaclient/shell.py +++ b/novaclient/shell.py @@ -219,7 +219,7 @@ class NovaClientArgumentParser(argparse.ArgumentParser): exits. """ self.print_usage(sys.stderr) - #FIXME(lzyeval): if changes occur in argparse.ArgParser._check_value + # FIXME(lzyeval): if changes occur in argparse.ArgParser._check_value choose_from = ' (choose from' progparts = self.prog.partition(' ') self.exit(2, _("error: %(errmsg)s\nTry '%(mainp)s help %(subp)s'" @@ -360,8 +360,8 @@ class OpenStackComputeShell(object): # thinking usage-list --end is ambiguous; but it # works fine with only --endpoint-type present # Go figure. I'm leaving this here for doc purposes. - #parser.add_argument('--endpoint_type', - # help=argparse.SUPPRESS) + # parser.add_argument('--endpoint_type', + # help=argparse.SUPPRESS) parser.add_argument('--os-compute-api-version', metavar='', @@ -607,7 +607,7 @@ class OpenStackComputeShell(object): must_auth = not (cliutils.isunauthenticated(args.func) or (auth_token and management_url)) - #FIXME(usrleon): Here should be restrict for project id same as + # FIXME(usrleon): Here should be restrict for project id same as # for os_username or os_password but for compatibility it is not. if must_auth: if auth_plugin: diff --git a/novaclient/tests/test_shell.py b/novaclient/tests/test_shell.py index daee60abe..ee08179bb 100644 --- a/novaclient/tests/test_shell.py +++ b/novaclient/tests/test_shell.py @@ -11,7 +11,7 @@ # License for the specific language governing permissions and limitations # under the License. -from distutils.version import StrictVersion +import distutils.version as dist_version import re import sys @@ -200,7 +200,8 @@ class ShellTest(utils.TestCase): # default output of empty tables differs depending between prettytable # versions if (hasattr(prettytable, '__version__') and - StrictVersion(prettytable.__version__) < StrictVersion('0.7.2')): + dist_version.StrictVersion(prettytable.__version__) < + dist_version.StrictVersion('0.7.2')): ex = '\n' else: ex = ( diff --git a/novaclient/tests/v1_1/fakes.py b/novaclient/tests/v1_1/fakes.py index c3fade4a8..f9fc1fd91 100644 --- a/novaclient/tests/v1_1/fakes.py +++ b/novaclient/tests/v1_1/fakes.py @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime +import datetime import six from six.moves.urllib import parse @@ -1495,13 +1495,17 @@ class FakeHTTPClient(base_client.HTTPClient): 'zone': 'nova', 'status': 'enabled', 'state': 'up', - 'updated_at': datetime(2012, 10, 29, 13, 42, 2)}, + 'updated_at': datetime.datetime( + 2012, 10, 29, 13, 42, 2 + )}, {'binary': binary, 'host': host, 'zone': 'nova', 'status': 'disabled', 'state': 'down', - 'updated_at': datetime(2012, 9, 18, 8, 3, 38)}, + 'updated_at': datetime.datetime( + 2012, 9, 18, 8, 3, 38 + )}, ]}) def put_os_services_enable(self, body, **kw): @@ -1785,7 +1789,9 @@ class FakeHTTPClient(base_client.HTTPClient): "nova-compute": {"active": True, "available": True, "updated_at": - datetime(2012, 12, 26, 14, 45, 25, 0)}}}}, + datetime.datetime( + 2012, 12, 26, 14, 45, 25, 0 + )}}}}, {"zoneName": "internal", "zoneState": {"available": True}, "hosts": { @@ -1794,13 +1800,17 @@ class FakeHTTPClient(base_client.HTTPClient): "active": True, "available": True, "updated_at": - datetime(2012, 12, 26, 14, 45, 25, 0)}}, + datetime.datetime( + 2012, 12, 26, 14, 45, 25, 0 + )}}, "fake_host-2": { "nova-network": { "active": True, "available": False, "updated_at": - datetime(2012, 12, 26, 14, 45, 24, 0)}}}}, + datetime.datetime( + 2012, 12, 26, 14, 45, 24, 0 + )}}}}, {"zoneName": "zone-2", "zoneState": {"available": False}, "hosts": None}]}) diff --git a/novaclient/tests/v3/fakes.py b/novaclient/tests/v3/fakes.py index 6d592f0cf..cdc65c8fc 100644 --- a/novaclient/tests/v3/fakes.py +++ b/novaclient/tests/v3/fakes.py @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from datetime import datetime +import datetime from novaclient.openstack.common import strutils from novaclient.tests import fakes @@ -282,7 +282,9 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient): "nova-compute": {"active": True, "available": True, "updated_at": - datetime(2012, 12, 26, 14, 45, 25, 0)}}}}, + datetime.datetime( + 2012, 12, 26, 14, 45, 25, 0 + )}}}}, {"zone_name": "internal", "zone_state": {"available": True}, "hosts": { @@ -291,13 +293,17 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient): "active": True, "available": True, "updated_at": - datetime(2012, 12, 26, 14, 45, 25, 0)}}, + datetime.datetime( + 2012, 12, 26, 14, 45, 25, 0 + )}}, "fake_host-2": { "nova-network": { "active": True, "available": False, "updated_at": - datetime(2012, 12, 26, 14, 45, 24, 0)}}}}, + datetime.datetime( + 2012, 12, 26, 14, 45, 24, 0 + )}}}}, {"zone_name": "zone-2", "zone_state": {"available": False}, "hosts": None}]}) diff --git a/novaclient/v1_1/servers.py b/novaclient/v1_1/servers.py index 8a930e8f9..68313a521 100644 --- a/novaclient/v1_1/servers.py +++ b/novaclient/v1_1/servers.py @@ -28,7 +28,8 @@ from novaclient import base from novaclient import crypto from novaclient.openstack.common.gettextutils import _ from novaclient.openstack.common import strutils -from novaclient.v1_1.security_groups import SecurityGroup +from novaclient.v1_1 import security_groups + REBOOT_SOFT, REBOOT_HARD = 'SOFT', 'HARD' @@ -1147,7 +1148,8 @@ class ServerManager(base.BootingManagerWithFind): """ return self._list('/servers/%s/os-security-groups' % - base.getid(server), 'security_groups', SecurityGroup) + base.getid(server), 'security_groups', + security_groups.SecurityGroup) def evacuate(self, server, host, on_shared_storage, password=None): """ diff --git a/novaclient/v1_1/shell.py b/novaclient/v1_1/shell.py index 7373848c7..011989a96 100644 --- a/novaclient/v1_1/shell.py +++ b/novaclient/v1_1/shell.py @@ -1151,7 +1151,7 @@ def do_image_delete(cs, args): const=1, help=argparse.SUPPRESS) @utils.arg('--tenant', - #nova db searches by project_id + # nova db searches by project_id dest='tenant', metavar='', nargs='?', @@ -2581,7 +2581,7 @@ def _find_keypair(cs, keypair): @utils.arg('--tenant', - #nova db searches by project_id + # nova db searches by project_id dest='tenant', metavar='', nargs='?', diff --git a/novaclient/v3/client.py b/novaclient/v3/client.py index c7928f603..a30f9191e 100644 --- a/novaclient/v3/client.py +++ b/novaclient/v3/client.py @@ -97,7 +97,7 @@ class Client(object): self.tenant_id = tenant_id self.user_id = user_id self.os_cache = os_cache or not no_cache - #TODO(bnemec): Add back in v3 extensions + # TODO(bnemec): Add back in v3 extensions self.agents = agents.AgentsManager(self) self.aggregates = aggregates.AggregateManager(self) self.availability_zones = \ diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py index ce856f119..bf756bb7f 100644 --- a/novaclient/v3/shell.py +++ b/novaclient/v3/shell.py @@ -950,7 +950,7 @@ def do_image_delete(cs, args): const=1, help=argparse.SUPPRESS) @utils.arg('--tenant', - #nova db searches by project_id + # nova db searches by project_id dest='tenant', metavar='', nargs='?', diff --git a/tox.ini b/tox.ini index a409dfda4..40978d654 100644 --- a/tox.ini +++ b/tox.ini @@ -26,8 +26,23 @@ commands = python setup.py testr --coverage --testr-args='{posargs}' downloadcache = ~/cache/pip [flake8] -# TODO fix following rules from hacking 0.9 -# E265,H402,H405,H904 -ignore = E12,E265,F811,F821,H302,H402,H404,H405,H904 +# Following checks should be enabled in the future. +# +# H404 multi line docstring should start without a leading new line +# H405 multi line docstring summary not separated with an empty line +# +# Following checks are ignored on purpose. +# +# H402 one line docstring needs punctuation +# reason: removed in hacking (https://review.openstack.org/#/c/101497/) +# +# H904 wrap long lines in parentheses instead of a backslash +# reason: removed in hacking (https://review.openstack.org/#/c/101701/) +# +# Additional checks are also ignored on purpose: E12, F811, F821 +ignore = E12,F811,F821,H402,H404,H405,H904 show-source = True -exclude=.venv,.git,.tox,dist,*openstack/common*,*lib/python*,*egg,build +exclude=.venv,.git,.tox,dist,*openstack/common*,*lib/python*,*egg,build,doc/source/conf.py + +[hacking] +import_exceptions = novaclient.openstack.common.gettextutils