From ab09d3eb5f57d7c56fd4fcd6f1a3256c3bae1575 Mon Sep 17 00:00:00 2001 From: Brant Knudson Date: Thu, 8 Jan 2015 17:29:47 -0600 Subject: [PATCH] Switch from oslo.utils to oslo_utils oslo_utils moved out of the oslo namespace. bp drop-namespace-packages Change-Id: I72e67dc1f649ba137dd06f5ab7133858c6abd67d --- keystoneclient/access.py | 2 +- keystoneclient/contrib/revoke/model.py | 2 +- keystoneclient/fixture/discovery.py | 2 +- keystoneclient/fixture/v2.py | 2 +- keystoneclient/fixture/v3.py | 2 +- keystoneclient/hacking/__init__.py | 0 keystoneclient/hacking/checks.py | 38 +++++++++++++++ keystoneclient/middleware/auth_token.py | 2 +- keystoneclient/session.py | 2 +- keystoneclient/shell.py | 2 +- .../tests/auth/test_identity_common.py | 2 +- keystoneclient/tests/client_fixtures.py | 26 +++++++++- .../tests/test_auth_token_middleware.py | 2 +- keystoneclient/tests/test_hacking_checks.py | 47 +++++++++++++++++++ keystoneclient/tests/test_keyring.py | 2 +- keystoneclient/tests/v2_0/test_access.py | 2 +- keystoneclient/tests/v2_0/test_auth.py | 2 +- keystoneclient/tests/v3/test_access.py | 2 +- keystoneclient/tests/v3/test_oauth1.py | 2 +- keystoneclient/tests/v3/test_trusts.py | 2 +- keystoneclient/utils.py | 2 +- keystoneclient/v2_0/shell.py | 2 +- keystoneclient/v3/contrib/trusts.py | 2 +- tox.ini | 1 + 24 files changed, 130 insertions(+), 20 deletions(-) create mode 100644 keystoneclient/hacking/__init__.py create mode 100644 keystoneclient/hacking/checks.py create mode 100644 keystoneclient/tests/test_hacking_checks.py diff --git a/keystoneclient/access.py b/keystoneclient/access.py index 8d85c688c..8217de81b 100644 --- a/keystoneclient/access.py +++ b/keystoneclient/access.py @@ -17,7 +17,7 @@ import datetime -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient.i18n import _ from keystoneclient import service_catalog diff --git a/keystoneclient/contrib/revoke/model.py b/keystoneclient/contrib/revoke/model.py index c3f386491..bb62840c2 100644 --- a/keystoneclient/contrib/revoke/model.py +++ b/keystoneclient/contrib/revoke/model.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo.utils import timeutils +from oslo_utils import timeutils # The set of attributes common between the RevokeEvent # and the dictionaries created from the token Data. diff --git a/keystoneclient/fixture/discovery.py b/keystoneclient/fixture/discovery.py index 1bc58a698..eae0bcdc3 100644 --- a/keystoneclient/fixture/discovery.py +++ b/keystoneclient/fixture/discovery.py @@ -12,7 +12,7 @@ import datetime -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient import utils diff --git a/keystoneclient/fixture/v2.py b/keystoneclient/fixture/v2.py index 3a107f400..cd4207b5f 100644 --- a/keystoneclient/fixture/v2.py +++ b/keystoneclient/fixture/v2.py @@ -13,7 +13,7 @@ import datetime import uuid -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient.fixture import exception diff --git a/keystoneclient/fixture/v3.py b/keystoneclient/fixture/v3.py index 4f0d581ce..b4cd0df4b 100644 --- a/keystoneclient/fixture/v3.py +++ b/keystoneclient/fixture/v3.py @@ -13,7 +13,7 @@ import datetime import uuid -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient.fixture import exception diff --git a/keystoneclient/hacking/__init__.py b/keystoneclient/hacking/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/keystoneclient/hacking/checks.py b/keystoneclient/hacking/checks.py new file mode 100644 index 000000000..8481f80c7 --- /dev/null +++ b/keystoneclient/hacking/checks.py @@ -0,0 +1,38 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +"""python-keystoneclient's pep8 extensions. + +In order to make the review process faster and easier for core devs we are +adding some python-keystoneclient specific pep8 checks. This will catch common +errors so that core devs don't have to. + +""" + + +import re + + +def check_oslo_namespace_imports(logical_line, blank_before, filename): + oslo_namespace_imports = re.compile( + r"(((from)|(import))\s+oslo\.utils)|" + "(from\s+oslo\s+import\s+utils)") + + if re.match(oslo_namespace_imports, logical_line): + msg = ("K333: '%s' must be used instead of '%s'.") % ( + logical_line.replace('oslo.', 'oslo_'), + logical_line) + yield(0, msg) + + +def factory(register): + register(check_oslo_namespace_imports) diff --git a/keystoneclient/middleware/auth_token.py b/keystoneclient/middleware/auth_token.py index 43a7ea5c9..29b819b3e 100644 --- a/keystoneclient/middleware/auth_token.py +++ b/keystoneclient/middleware/auth_token.py @@ -159,7 +159,7 @@ import time import netaddr from oslo.config import cfg from oslo.serialization import jsonutils -from oslo.utils import timeutils +from oslo_utils import timeutils import requests import six from six.moves import urllib diff --git a/keystoneclient/session.py b/keystoneclient/session.py index 0c3edbba1..3ac6d600e 100644 --- a/keystoneclient/session.py +++ b/keystoneclient/session.py @@ -19,7 +19,7 @@ import time from oslo.config import cfg from oslo.serialization import jsonutils -from oslo.utils import importutils +from oslo_utils import importutils import requests import six from six.moves import urllib diff --git a/keystoneclient/shell.py b/keystoneclient/shell.py index be7330ce0..7fcaf382a 100644 --- a/keystoneclient/shell.py +++ b/keystoneclient/shell.py @@ -30,7 +30,7 @@ import logging import os import sys -from oslo.utils import encodeutils +from oslo_utils import encodeutils import six import keystoneclient diff --git a/keystoneclient/tests/auth/test_identity_common.py b/keystoneclient/tests/auth/test_identity_common.py index a7d9be6b8..1669fad53 100644 --- a/keystoneclient/tests/auth/test_identity_common.py +++ b/keystoneclient/tests/auth/test_identity_common.py @@ -14,7 +14,7 @@ import abc import datetime import uuid -from oslo.utils import timeutils +from oslo_utils import timeutils import six from keystoneclient import access diff --git a/keystoneclient/tests/client_fixtures.py b/keystoneclient/tests/client_fixtures.py index cadae114d..66b04d947 100644 --- a/keystoneclient/tests/client_fixtures.py +++ b/keystoneclient/tests/client_fixtures.py @@ -16,7 +16,7 @@ import os import fixtures from oslo.serialization import jsonutils -from oslo.utils import timeutils +from oslo_utils import timeutils import six import testresources @@ -535,3 +535,27 @@ class Examples(fixtures.Fixture): EXAMPLES_RESOURCE = testresources.FixtureResource(Examples()) + + +class HackingCode(fixtures.Fixture): + """A fixture to house the various code examples for the keystoneclient + hacking style checks. + """ + + oslo_namespace_imports = { + 'code': """ + import oslo.utils + import oslo_utils + import oslo.utils.encodeutils + import oslo_utils.encodeutils + from oslo import utils + from oslo.utils import encodeutils + from oslo_utils import encodeutils + """, + 'expected_errors': [ + (1, 0, 'K333'), + (3, 0, 'K333'), + (5, 0, 'K333'), + (6, 0, 'K333'), + ], + } diff --git a/keystoneclient/tests/test_auth_token_middleware.py b/keystoneclient/tests/test_auth_token_middleware.py index d36fc48a5..388a7ce33 100644 --- a/keystoneclient/tests/test_auth_token_middleware.py +++ b/keystoneclient/tests/test_auth_token_middleware.py @@ -26,7 +26,7 @@ import fixtures import iso8601 import mock from oslo.serialization import jsonutils -from oslo.utils import timeutils +from oslo_utils import timeutils from requests_mock.contrib import fixture as mock_fixture import six from six.moves.urllib import parse as urlparse diff --git a/keystoneclient/tests/test_hacking_checks.py b/keystoneclient/tests/test_hacking_checks.py new file mode 100644 index 000000000..84095f38e --- /dev/null +++ b/keystoneclient/tests/test_hacking_checks.py @@ -0,0 +1,47 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import textwrap + +import mock +import pep8 +import testtools + +from keystoneclient.hacking import checks +from keystoneclient.tests import client_fixtures + + +class TestCheckOsloNamespaceImports(testtools.TestCase): + + # We are patching pep8 so that only the check under test is actually + # installed. + @mock.patch('pep8._checks', + {'physical_line': {}, 'logical_line': {}, 'tree': {}}) + def run_check(self, code): + pep8.register_check(checks.check_oslo_namespace_imports) + + lines = textwrap.dedent(code).strip().splitlines(True) + + checker = pep8.Checker(lines=lines) + checker.check_all() + checker.report._deferred_print.sort() + return checker.report._deferred_print + + def assert_has_errors(self, code, expected_errors=None): + actual_errors = [e[:3] for e in self.run_check(code)] + self.assertEqual(expected_errors or [], actual_errors) + + def test(self): + code_ex = self.useFixture(client_fixtures.HackingCode()) + code = code_ex.oslo_namespace_imports['code'] + errors = code_ex.oslo_namespace_imports['expected_errors'] + self.assert_has_errors(code, expected_errors=errors) diff --git a/keystoneclient/tests/test_keyring.py b/keystoneclient/tests/test_keyring.py index 4bdf73170..117931609 100644 --- a/keystoneclient/tests/test_keyring.py +++ b/keystoneclient/tests/test_keyring.py @@ -13,7 +13,7 @@ import datetime import mock -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient import access from keystoneclient import httpclient diff --git a/keystoneclient/tests/v2_0/test_access.py b/keystoneclient/tests/v2_0/test_access.py index 1cd926a48..b264b3cbf 100644 --- a/keystoneclient/tests/v2_0/test_access.py +++ b/keystoneclient/tests/v2_0/test_access.py @@ -13,7 +13,7 @@ import datetime import uuid -from oslo.utils import timeutils +from oslo_utils import timeutils import testresources from keystoneclient import access diff --git a/keystoneclient/tests/v2_0/test_auth.py b/keystoneclient/tests/v2_0/test_auth.py index fd9ffc307..ddf8f3910 100644 --- a/keystoneclient/tests/v2_0/test_auth.py +++ b/keystoneclient/tests/v2_0/test_auth.py @@ -14,7 +14,7 @@ import copy import datetime from oslo.serialization import jsonutils -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient import exceptions from keystoneclient.tests.v2_0 import utils diff --git a/keystoneclient/tests/v3/test_access.py b/keystoneclient/tests/v3/test_access.py index 0f0b0e2b4..ba9c2b72e 100644 --- a/keystoneclient/tests/v3/test_access.py +++ b/keystoneclient/tests/v3/test_access.py @@ -13,7 +13,7 @@ import datetime import uuid -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient import access from keystoneclient import fixture diff --git a/keystoneclient/tests/v3/test_oauth1.py b/keystoneclient/tests/v3/test_oauth1.py index ff0d83677..6248bd94c 100644 --- a/keystoneclient/tests/v3/test_oauth1.py +++ b/keystoneclient/tests/v3/test_oauth1.py @@ -14,7 +14,7 @@ import uuid import mock -from oslo.utils import timeutils +from oslo_utils import timeutils import six from six.moves.urllib import parse as urlparse from testtools import matchers diff --git a/keystoneclient/tests/v3/test_trusts.py b/keystoneclient/tests/v3/test_trusts.py index 0b8028f85..4452c766f 100644 --- a/keystoneclient/tests/v3/test_trusts.py +++ b/keystoneclient/tests/v3/test_trusts.py @@ -13,7 +13,7 @@ import uuid -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient import exceptions from keystoneclient.tests.v3 import utils diff --git a/keystoneclient/utils.py b/keystoneclient/utils.py index 436b2f61c..7a2739f5b 100644 --- a/keystoneclient/utils.py +++ b/keystoneclient/utils.py @@ -17,7 +17,7 @@ import inspect import logging import sys -from oslo.utils import encodeutils +from oslo_utils import encodeutils import prettytable import six diff --git a/keystoneclient/v2_0/shell.py b/keystoneclient/v2_0/shell.py index 9920555a0..9d7d7ce6d 100755 --- a/keystoneclient/v2_0/shell.py +++ b/keystoneclient/v2_0/shell.py @@ -26,7 +26,7 @@ import argparse import getpass import sys -from oslo.utils import strutils +from oslo_utils import strutils import six from keystoneclient.i18n import _ diff --git a/keystoneclient/v3/contrib/trusts.py b/keystoneclient/v3/contrib/trusts.py index 0fb75ca50..5fe88f8c9 100644 --- a/keystoneclient/v3/contrib/trusts.py +++ b/keystoneclient/v3/contrib/trusts.py @@ -10,7 +10,7 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo.utils import timeutils +from oslo_utils import timeutils from keystoneclient import base from keystoneclient import exceptions diff --git a/tox.ini b/tox.ini index 49586a554..f519456c5 100644 --- a/tox.ini +++ b/tox.ini @@ -46,3 +46,4 @@ commands= [hacking] import_exceptions = keystoneclient.i18n +local-check-factory = keystoneclient.hacking.checks.factory