Update hacking for Python3
The repo is Python 3 now, so update hacking to version 3.0 which supports Python 3. Fix problems found. Update local hacking checks for new flake8. Change-Id: I41a5518f1210c9a1b6d5217bbbcd99bbaa3c9b53
This commit is contained in:
parent
8877fa1a37
commit
b014dbe64c
@ -23,8 +23,8 @@ Create Date: 2014-09-25 12:41:28.585333
|
||||
revision = '2ac2217dcbd9'
|
||||
down_revision = '464e951dc3b8'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2015-03-17 17:50:15.229896
|
||||
revision = '385e33fef139'
|
||||
down_revision = '2ac2217dcbd9'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2014-08-05 17:41:34.470183
|
||||
revision = '464e951dc3b8'
|
||||
down_revision = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -16,7 +16,7 @@
|
||||
import ast
|
||||
import re
|
||||
|
||||
import pep8
|
||||
from hacking import core
|
||||
import six
|
||||
|
||||
|
||||
@ -100,6 +100,7 @@ class BaseASTChecker(ast.NodeVisitor):
|
||||
return False
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def no_translate_logs(logical_line, filename):
|
||||
"""Check for 'LOG.*(_('
|
||||
|
||||
@ -126,6 +127,9 @@ class CheckLoggingFormatArgs(BaseASTChecker):
|
||||
|
||||
"""
|
||||
|
||||
name = "check_logging_format_args"
|
||||
version = "1.0"
|
||||
|
||||
CHECK_DESC = 'C310 Log method arguments should not be a tuple.'
|
||||
LOG_METHODS = [
|
||||
'debug', 'info',
|
||||
@ -181,6 +185,7 @@ class CheckLoggingFormatArgs(BaseASTChecker):
|
||||
return super(CheckLoggingFormatArgs, self).generic_visit(node)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def check_explicit_underscore_import(logical_line, filename):
|
||||
"""Check for explicit import of the _ function
|
||||
|
||||
@ -212,6 +217,9 @@ class CheckForStrUnicodeExc(BaseASTChecker):
|
||||
catch it.
|
||||
"""
|
||||
|
||||
name = "check_for_str_unicode_exc"
|
||||
version = "1.0"
|
||||
|
||||
CHECK_DESC = ('C314 str() and unicode() cannot be used on an '
|
||||
'exception. Remove or use six.text_type()')
|
||||
|
||||
@ -257,6 +265,9 @@ class CheckForTransAdd(BaseASTChecker):
|
||||
string to give the translators the most information.
|
||||
"""
|
||||
|
||||
name = "check_for_trans_add"
|
||||
version = "1.0"
|
||||
|
||||
CHECK_DESC = ('C315 Translated messages cannot be concatenated. '
|
||||
'String should be included in translated message.')
|
||||
|
||||
@ -271,12 +282,13 @@ class CheckForTransAdd(BaseASTChecker):
|
||||
super(CheckForTransAdd, self).generic_visit(node)
|
||||
|
||||
|
||||
def check_oslo_namespace_imports(logical_line, physical_line, filename):
|
||||
@core.flake8ext
|
||||
def check_oslo_namespace_imports(logical_line, noqa):
|
||||
"""'oslo_' should be used instead of 'oslo.'
|
||||
|
||||
C317
|
||||
"""
|
||||
if pep8.noqa(physical_line):
|
||||
if noqa:
|
||||
return
|
||||
if re.match(oslo_namespace_imports, logical_line):
|
||||
msg = ("C317: '%s' must be used instead of '%s'.") % (
|
||||
@ -285,6 +297,7 @@ def check_oslo_namespace_imports(logical_line, physical_line, filename):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def dict_constructor_with_list_copy(logical_line):
|
||||
"""Use a dict comprehension instead of a dict constructor
|
||||
|
||||
@ -297,6 +310,7 @@ def dict_constructor_with_list_copy(logical_line):
|
||||
yield (0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def no_xrange(logical_line):
|
||||
"""Ensure to not use xrange()
|
||||
|
||||
@ -306,6 +320,7 @@ def no_xrange(logical_line):
|
||||
yield(0, "C319: Do not use xrange().")
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def validate_assertTrue(logical_line):
|
||||
"""Use assertTrue instead of assertEqual
|
||||
|
||||
@ -317,6 +332,7 @@ def validate_assertTrue(logical_line):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def validate_assertIsNone(logical_line):
|
||||
"""Use assertIsNone instead of assertEqual
|
||||
|
||||
@ -328,6 +344,7 @@ def validate_assertIsNone(logical_line):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
@core.flake8ext
|
||||
def no_log_warn_check(logical_line):
|
||||
"""Disallow 'LOG.warn'
|
||||
|
||||
@ -336,17 +353,3 @@ def no_log_warn_check(logical_line):
|
||||
msg = ("C320: LOG.warn is deprecated, please use LOG.warning!")
|
||||
if re.match(no_log_warn, logical_line):
|
||||
yield(0, msg)
|
||||
|
||||
|
||||
def factory(register):
|
||||
register(check_explicit_underscore_import)
|
||||
register(no_translate_logs)
|
||||
register(CheckForStrUnicodeExc)
|
||||
register(CheckLoggingFormatArgs)
|
||||
register(CheckForTransAdd)
|
||||
register(check_oslo_namespace_imports)
|
||||
register(dict_constructor_with_list_copy)
|
||||
register(no_xrange)
|
||||
register(validate_assertTrue)
|
||||
register(validate_assertIsNone)
|
||||
register(no_log_warn_check)
|
||||
|
@ -390,13 +390,13 @@ class Orchestrator(cotyledon.Service):
|
||||
|
||||
lock_name, lock = get_lock(self.coord, tenant_id)
|
||||
LOG.debug(
|
||||
'[Worker: {w}] Trying to acquire lock "{l}" ...'.format(
|
||||
w=self._worker_id, l=lock_name)
|
||||
'[Worker: {w}] Trying to acquire lock "{lck}" ...'.format(
|
||||
w=self._worker_id, lck=lock_name)
|
||||
)
|
||||
if lock.acquire(blocking=False):
|
||||
LOG.debug(
|
||||
'[Worker: {w}] Acquired lock "{l}" ...'.format(
|
||||
w=self._worker_id, l=lock_name)
|
||||
'[Worker: {w}] Acquired lock "{lck}" ...'.format(
|
||||
w=self._worker_id, lck=lock_name)
|
||||
)
|
||||
state = self._check_state(tenant_id)
|
||||
if state:
|
||||
|
@ -23,7 +23,7 @@ Create Date: 2016-05-24 18:37:25.305430
|
||||
revision = '10d2738b67df'
|
||||
down_revision = '54cc17accf2c'
|
||||
|
||||
from alembic import op
|
||||
from alembic import op # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2015-03-10 13:06:41.067563
|
||||
revision = '3dd7e13527f3'
|
||||
down_revision = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2016-05-31 12:27:30.821497
|
||||
revision = '4da82e1c11c8'
|
||||
down_revision = 'c88a06b1cfce'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
CONSTRAINT_MAP = {
|
||||
'hashmap_mappings': {
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2015-05-05 14:39:24.562388
|
||||
revision = '4fa888fd7eda'
|
||||
down_revision = '3dd7e13527f3'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2015-05-28 16:44:32.936076
|
||||
revision = '54cc17accf2c'
|
||||
down_revision = '4fa888fd7eda'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def create_table(is_old=False):
|
||||
|
@ -25,8 +25,8 @@ Create Date: 2018-10-29 17:25:37.901136
|
||||
revision = '644faa4491fd'
|
||||
down_revision = '4da82e1c11c8'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
CONSTRAINT_MAP = {
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2016-05-19 18:06:43.315066
|
||||
revision = 'c88a06b1cfce'
|
||||
down_revision = 'f8c799db4aa0'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -22,12 +22,12 @@ Create Date: 2016-05-18 18:08:19.331412
|
||||
# revision identifiers, used by Alembic.
|
||||
revision = 'f8c799db4aa0'
|
||||
down_revision = '10d2738b67df'
|
||||
import copy
|
||||
import copy # noqa: E402
|
||||
|
||||
from alembic import op
|
||||
import six
|
||||
from alembic import op # noqa: E402
|
||||
import six # noqa: E402
|
||||
|
||||
from cloudkitty.rating.hash.db.sqlalchemy.alembic.models import (
|
||||
from cloudkitty.rating.hash.db.sqlalchemy.alembic.models import ( # noqa: E402
|
||||
f8c799db4aa0_fix_unnamed_constraints as models)
|
||||
|
||||
OPS = {
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2015-07-30 12:46:32.998770
|
||||
revision = '4f9efa4601c0'
|
||||
down_revision = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -25,8 +25,8 @@ Create Date: 2019-03-25 13:53:23.398755
|
||||
revision = '75c205f6f1a2'
|
||||
down_revision = '4f9efa4601c0'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2014-10-10 11:28:08.645122
|
||||
revision = '17fd1b237aa3'
|
||||
down_revision = None
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2016-09-05 18:37:26.714065
|
||||
revision = '307430ab38bc'
|
||||
down_revision = '792b438b663'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -23,8 +23,8 @@ Create Date: 2014-12-02 13:12:11.328534
|
||||
revision = '792b438b663'
|
||||
down_revision = '17fd1b237aa3'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -25,8 +25,8 @@ Create Date: 2017-04-01 09:33:41.434750
|
||||
revision = 'c703a1bad612'
|
||||
down_revision = '307430ab38bc'
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from alembic import op # noqa: E402
|
||||
import sqlalchemy as sa # noqa: E402
|
||||
|
||||
|
||||
def upgrade():
|
||||
|
@ -18,7 +18,7 @@ from cloudkitty.tests.gabbi.fixtures import * # noqa
|
||||
from cloudkitty.rating.hash.db import api as hashmap_db
|
||||
|
||||
|
||||
class HashMapConfigFixture(ConfigFixture):
|
||||
class HashMapConfigFixture(ConfigFixture): # noqa: F405
|
||||
def start_fixture(self):
|
||||
super(HashMapConfigFixture, self).start_fixture()
|
||||
self.conn = hashmap_db.get_instance()
|
||||
|
@ -18,7 +18,7 @@ from cloudkitty.tests.gabbi.fixtures import * # noqa
|
||||
from cloudkitty.rating.pyscripts.db import api as pyscripts_db
|
||||
|
||||
|
||||
class PyScriptsConfigFixture(ConfigFixture):
|
||||
class PyScriptsConfigFixture(ConfigFixture): # noqa: F405
|
||||
def start_fixture(self):
|
||||
super(PyScriptsConfigFixture, self).start_fixture()
|
||||
self.conn = pyscripts_db.get_instance()
|
||||
|
@ -40,8 +40,9 @@ class FakeElasticsearchClient(client.ElasticsearchClient):
|
||||
|
||||
@staticmethod
|
||||
def __filter_func(begin, end, filters, mtypes, doc):
|
||||
type_filter = lambda doc: doc['type'] in mtypes if mtypes else True
|
||||
time_filter = lambda doc: (
|
||||
type_filter = lambda doc: ( # noqa: E731
|
||||
doc['type'] in mtypes if mtypes else True)
|
||||
time_filter = lambda doc: ( # noqa: E731
|
||||
(doc['start'] >= begin if begin else True)
|
||||
and (doc['start'] < end if end else True))
|
||||
|
||||
@ -77,7 +78,7 @@ class FakeElasticsearchClient(client.ElasticsearchClient):
|
||||
}]
|
||||
|
||||
output = []
|
||||
key_func = lambda d: tuple(
|
||||
key_func = lambda d: tuple( # noqa: E731
|
||||
d['type'] if g == 'type' else d['groupby'][g] for g in groupby)
|
||||
docs.sort(key=key_func)
|
||||
|
||||
|
@ -17,7 +17,7 @@ import textwrap
|
||||
from unittest import mock
|
||||
|
||||
import ddt
|
||||
import pep8
|
||||
import pycodestyle
|
||||
|
||||
from cloudkitty.hacking import checks
|
||||
from cloudkitty import tests
|
||||
@ -103,14 +103,14 @@ class HackingTestCase(tests.TestCase):
|
||||
|
||||
# We are patching pep8 so that only the check under test is actually
|
||||
# installed.
|
||||
@mock.patch('pep8._checks',
|
||||
@mock.patch('pycodestyle._checks',
|
||||
{'physical_line': {}, 'logical_line': {}, 'tree': {}})
|
||||
def _run_check(self, code, checker, filename=None):
|
||||
pep8.register_check(checker)
|
||||
pycodestyle.register_check(checker)
|
||||
|
||||
lines = textwrap.dedent(code).strip().splitlines(True)
|
||||
|
||||
checker = pep8.Checker(filename=filename, lines=lines)
|
||||
checker = pycodestyle.Checker(filename=filename, lines=lines)
|
||||
checker.check_all()
|
||||
checker.report._deferred_print.sort()
|
||||
return checker.report._deferred_print
|
||||
|
@ -93,8 +93,7 @@ VOLUME_RESOURCE = {
|
||||
'size': '1',
|
||||
"project_id": "f1873b13951542268bf7eed7cf971e52",
|
||||
"resource_id": "08017fbc-b13a-4d8d-b002-4eb4eff54cd4",
|
||||
"source": "openstack",
|
||||
"user_id": "None"}
|
||||
"source": "openstack"}
|
||||
|
||||
NETWORK_BW_IN = {
|
||||
"type": "network.bw.in",
|
||||
@ -398,9 +397,9 @@ class VolumeGenerator(BaseGenerator):
|
||||
def init_mapper(self):
|
||||
self.volumes = {
|
||||
'2bed6a3d-468a-459b-802b-44930016c0a3': {
|
||||
'size': '10'},
|
||||
'size': '10'},
|
||||
'4fd33321-6a5f-4351-94ca-db398cd708e9': {
|
||||
'size': '20'}}
|
||||
'size': '20'}}
|
||||
|
||||
def generate_name(self, *args):
|
||||
basename = 'volume{}'
|
||||
|
@ -3,7 +3,7 @@
|
||||
# process, which may cause wedges in the gate later.
|
||||
|
||||
# hacking should be first
|
||||
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
|
||||
hacking>=3.0,<3.1.0 # Apache-2.0
|
||||
|
||||
coverage>=3.6,!=4.4 # Apache-2.0
|
||||
kombu>=4.0.0,!=4.0.2 # BSD
|
||||
|
16
tox.ini
16
tox.ini
@ -74,7 +74,21 @@ ignore-path = .venv,.git,.tox,.tmp,*cloudkitty/locale*,*lib/python*,cloudkitty.e
|
||||
|
||||
[hacking]
|
||||
import_exceptions = cloudkitty.i18n
|
||||
local-check-factory = cloudkitty.hacking.checks.factory
|
||||
|
||||
[flake8:local-plugins]
|
||||
extension =
|
||||
C310 = checks:CheckLoggingFormatArgs
|
||||
C311 = checks:validate_assertIsNone
|
||||
C312 = checks:validate_assertTrue
|
||||
C313 = checks:no_translate_logs
|
||||
C314 = checks:CheckForStrUnicodeExc
|
||||
C315 = checks:CheckForTransAdd
|
||||
C317 = checks:check_oslo_namespace_imports
|
||||
C318 = checks:dict_constructor_with_list_copy
|
||||
C319 = checks:no_xrange
|
||||
C320 = checks:no_log_warn_check
|
||||
C321 = checks:check_explicit_underscore_import
|
||||
paths = ./cloudkitty/hacking
|
||||
|
||||
[testenv:releasenotes]
|
||||
commands = sphinx-build -a -E -W -d releasenotes/build/doctrees --keep-going -b html releasenotes/source releasenotes/build/html
|
||||
|
Loading…
Reference in New Issue
Block a user