Skip to content

Commit

Permalink
Remove unnecessary oslo namespace import checks
Browse files Browse the repository at this point in the history
Latest oslo libraries do not support the old oslo
namespace based imports, so the import check in our hacking
rules are redundant as CI jobs will fail for sure if someone
tries to use oslo namespace based imports.

Change-Id: I49c74ade374582f53a3678a1bc7df194c24e892e
  • Loading branch information
dims committed Jul 23, 2015
1 parent 8a7665b commit 83d6548
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 56 deletions.
1 change: 0 additions & 1 deletion HACKING.rst
Expand Up @@ -41,7 +41,6 @@ Nova Specific Commandments
- [N329] Validate that LOG.exception messages use _LE.
- [N330] Validate that LOG.warning and LOG.warn messages use _LW.
- [N332] Check that the api_version decorator is the first decorator on a method
- [N333] Check for oslo library imports use the non-namespaced packages
- [N334] Change assertTrue/False(A in/not in B, message) to the more specific
assertIn/NotIn(A, B, message)
- [N335] Check for usage of deprecated assertRaisesRegexp
Expand Down
34 changes: 0 additions & 34 deletions nova/hacking/checks.py
Expand Up @@ -97,21 +97,6 @@
decorator_re = re.compile(r"@.*")
http_not_implemented_re = re.compile(r"raise .*HTTPNotImplemented\(")

# TODO(dims): When other oslo libraries switch over non-namespace'd
# imports, we need to add them to the regexp below.
oslo_namespace_imports = re.compile(r"from[\s]*oslo[.]"
r"(concurrency|config|context|db|i18n|"
r"log|messaging|middleware|rootwrap|"
r"serialization|utils|vmware)")
oslo_namespace_imports_2 = re.compile(r"from[\s]*oslo[\s]*import[\s]*"
r"(concurrency|config|context|db|i18n|"
r"log|messaging|middleware|rootwrap|"
r"serialization|utils|vmware)")
oslo_namespace_imports_3 = re.compile(r"import[\s]*oslo\."
r"(concurrency|config|context|db|i18n|"
r"log|messaging|middleware|rootwrap|"
r"serialization|utils|vmware)")


class BaseASTChecker(ast.NodeVisitor):
"""Provides a simple framework for writing AST-based checks.
Expand Down Expand Up @@ -475,24 +460,6 @@ def visit_BinOp(self, node):
super(CheckForTransAdd, self).generic_visit(node)


def check_oslo_namespace_imports(logical_line, blank_before, filename):
if re.match(oslo_namespace_imports, logical_line):
msg = ("N333: '%s' must be used instead of '%s'.") % (
logical_line.replace('oslo.', 'oslo_'),
logical_line)
yield(0, msg)
match = re.match(oslo_namespace_imports_2, logical_line)
if match:
msg = ("N333: 'module %s should not be imported "
"from oslo namespace.") % match.group(1)
yield(0, msg)
match = re.match(oslo_namespace_imports_3, logical_line)
if match:
msg = ("N333: 'module %s should not be imported "
"from oslo namespace.") % match.group(1)
yield(0, msg)


def assert_true_or_false_with_in(logical_line):
"""Check for assertTrue/False(A in B), assertTrue/False(A not in B),
assertTrue/False(A in B, message) or assertTrue/False(A not in B, message)
Expand Down Expand Up @@ -574,7 +541,6 @@ def factory(register):
register(check_api_version_decorator)
register(CheckForStrUnicodeExc)
register(CheckForTransAdd)
register(check_oslo_namespace_imports)
register(assert_true_or_false_with_in)
register(dict_constructor_with_list_copy)
register(assert_equal_in)
Expand Down
21 changes: 0 additions & 21 deletions nova/tests/unit/test_hacking.py
Expand Up @@ -431,27 +431,6 @@ def my_method():
self._assert_has_errors(code, checks.check_api_version_decorator,
expected_errors=[(2, 0, "N332")])

def test_oslo_namespace_imports_check(self):
code = """
from oslo.concurrency import processutils
"""
self._assert_has_errors(code, checks.check_oslo_namespace_imports,
expected_errors=[(1, 0, "N333")])

def test_oslo_namespace_imports_check_2(self):
code = """
from oslo import i18n
"""
self._assert_has_errors(code, checks.check_oslo_namespace_imports,
expected_errors=[(1, 0, "N333")])

def test_oslo_namespace_imports_check_3(self):
code = """
import oslo.messaging
"""
self._assert_has_errors(code, checks.check_oslo_namespace_imports,
expected_errors=[(1, 0, "N333")])

def test_oslo_assert_raises_regexp(self):
code = """
self.assertRaisesRegexp(ValueError,
Expand Down

0 comments on commit 83d6548

Please sign in to comment.