diff options
| author | Yuriy Taraday <yorik.sar@gmail.com> | 2012-03-11 19:04:26 +0400 |
|---|---|---|
| committer | Yuriy Taraday <yorik.sar@gmail.com> | 2012-04-09 18:00:40 +0400 |
| commit | f7a6c58d920cc4310132d4e0cb06838202de407b (patch) | |
| tree | 753b24eec5e0b82d9b11aaea2e350230f5550e56 /tools | |
| parent | 21dbbaa3861b277b98ba8642a85b1f4f2722866f (diff) | |
HACKING fixes, sqlalchemy fix.
Add exceptions to hacking.py make sqlalchemy stuff legal and prevent
clutter.
Change-Id: I44b100b4c0c4dfcec81beea7aba2d8598d5a08d0
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/hacking.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/tools/hacking.py b/tools/hacking.py index 7aa756bb5..c3c1d7156 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -36,6 +36,13 @@ import pep8 #N5xx dictionaries/lists #N6xx Calling methods +IMPORT_EXCEPTIONS = ['sqlalchemy', 'migrate', 'nova.db.sqlalchemy.session'] + + +def is_import_exception(mod): + return mod in IMPORT_EXCEPTIONS or \ + any(mod.startswith(m + '.') for m in IMPORT_EXCEPTIONS) + def nova_todo_format(physical_line): """ @@ -77,13 +84,13 @@ def nova_one_import_per_line(logical_line): Examples: BAD: from nova.rpc.common import RemoteError, LOG - BAD: from sqlalchemy import MetaData, Table N301 """ pos = logical_line.find(',') - if (pos > -1 and (logical_line.startswith("import ") or - (logical_line.startswith("from ") and - logical_line.split()[2] == "import"))): + parts = logical_line.split() + if pos > -1 and (parts[0] == "import" or + parts[0] == "from" and parts[2] == "import") and \ + not is_import_exception(parts[1]): return pos, "NOVA N301: one import per line" @@ -104,6 +111,8 @@ def nova_import_module_only(logical_line): try: valid = True if parent: + if is_import_exception(parent): + return parent_mod = __import__(parent, globals(), locals(), [mod], -1) valid = inspect.ismodule(getattr(parent_mod, mod)) else: |
