Merge "HACKING fixes, sqlalchemy fix."
This commit is contained in:
commit
689fd02c06
10
HACKING.rst
10
HACKING.rst
@ -28,12 +28,18 @@ General
|
|||||||
|
|
||||||
Imports
|
Imports
|
||||||
-------
|
-------
|
||||||
- Do not import objects, only modules
|
- Do not import objects, only modules (*)
|
||||||
- Do not import more than one module per line
|
- Do not import more than one module per line (*)
|
||||||
- Do not make relative imports
|
- Do not make relative imports
|
||||||
- Order your imports by the full module path
|
- Order your imports by the full module path
|
||||||
- Organize your imports according to the following template
|
- Organize your imports according to the following template
|
||||||
|
|
||||||
|
(*) exceptions are:
|
||||||
|
|
||||||
|
- imports from ``migrate`` package
|
||||||
|
- imports from ``sqlalchemy`` package
|
||||||
|
- imports from ``nova.db.sqlalchemy.session`` module
|
||||||
|
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
# vim: tabstop=4 shiftwidth=4 softtabstop=4
|
||||||
|
@ -36,6 +36,13 @@ import pep8
|
|||||||
#N5xx dictionaries/lists
|
#N5xx dictionaries/lists
|
||||||
#N6xx Calling methods
|
#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):
|
def nova_todo_format(physical_line):
|
||||||
"""
|
"""
|
||||||
@ -77,13 +84,13 @@ def nova_one_import_per_line(logical_line):
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
BAD: from nova.rpc.common import RemoteError, LOG
|
BAD: from nova.rpc.common import RemoteError, LOG
|
||||||
BAD: from sqlalchemy import MetaData, Table
|
|
||||||
N301
|
N301
|
||||||
"""
|
"""
|
||||||
pos = logical_line.find(',')
|
pos = logical_line.find(',')
|
||||||
if (pos > -1 and (logical_line.startswith("import ") or
|
parts = logical_line.split()
|
||||||
(logical_line.startswith("from ") and
|
if pos > -1 and (parts[0] == "import" or
|
||||||
logical_line.split()[2] == "import"))):
|
parts[0] == "from" and parts[2] == "import") and \
|
||||||
|
not is_import_exception(parts[1]):
|
||||||
return pos, "NOVA N301: one import per line"
|
return pos, "NOVA N301: one import per line"
|
||||||
|
|
||||||
|
|
||||||
@ -104,6 +111,8 @@ def nova_import_module_only(logical_line):
|
|||||||
try:
|
try:
|
||||||
valid = True
|
valid = True
|
||||||
if parent:
|
if parent:
|
||||||
|
if is_import_exception(parent):
|
||||||
|
return
|
||||||
parent_mod = __import__(parent, globals(), locals(), [mod], -1)
|
parent_mod = __import__(parent, globals(), locals(), [mod], -1)
|
||||||
valid = inspect.ismodule(getattr(parent_mod, mod))
|
valid = inspect.ismodule(getattr(parent_mod, mod))
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user