Module import style checking changes

* Implementing the * import detection (it is disabled for now)
* New style relative import testing based on syntax rules
* Old style relative import testing based on module search
* Inspection based solution replaced by PYTHONPATH search
  in order to avoid module compile and initialization steps
  (code execution) in a syntax checking phase.

This solution is faster and safer, but does not able to recognize
modules added dynamically to the module scope.

Change-Id: Ifc871f4fdbcd4a9a736170ceb4475f4f2cbe66bc
This commit is contained in:
Attila Fazekas 2013-02-05 17:51:17 +01:00
parent 0feb5db822
commit 672cd79b9e
3 changed files with 19 additions and 6 deletions

View File

@ -52,6 +52,7 @@ Imports
-------
- Do not import objects, only modules (*)
- Do not import more than one module per line (*)
- Do not use wildcard ``*`` import (*)
- Do not make relative imports
- Do not make new nova.db imports in nova/virt/*
- Order your imports by the full module path
@ -62,6 +63,8 @@ Imports
- imports from ``migrate`` package
- imports from ``sqlalchemy`` package
- imports from ``nova.db.sqlalchemy.session`` module
- imports from ``nova.openstack.common.log.logging`` package
- imports from ``nova.db.sqlalchemy.migration.versioning_api`` package
Example::

View File

@ -93,6 +93,8 @@ export venv_name
export tools_dir
export venv=${venv_path}/${venv_dir}
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
if [ $no_site_packages -eq 1 ]; then
installvenvopts="--no-site-packages"
fi
@ -156,12 +158,11 @@ function run_pep8 {
srcfiles=`find nova -type f -name "*.py" ! -wholename "nova\/openstack*"`
srcfiles+=" `find bin -type f ! -name "nova.conf*" ! -name "*api-paste.ini*" ! -name "*~"`"
srcfiles+=" `find tools -type f -name "*.py"`"
srcfiles+=" `find plugins -type f -name "*.py"`"
srcfiles+=" `find smoketests -type f -name "*.py"`"
srcfiles+=" setup.py"
# Until all these issues get fixed, ignore.
ignore='--ignore=E12,E711,E721,E712,N403,N404'
ignore='--ignore=E12,E711,E721,E712,N403,N404,N303'
# First run the hacking selftest, to make sure it's right
echo "Running hacking.py self test"
@ -171,6 +172,10 @@ function run_pep8 {
echo "Running pep8"
${wrapper} python tools/hacking.py ${ignore} ${srcfiles}
PYTHONPATH=$SCRIPT_ROOT/plugins/xenserver/networking/etc/xensource/scripts ${wrapper} python tools/hacking.py ${ignore} ./plugins/xenserver/networking
PYTHONPATH=$SCRIPT_ROOT/plugins/xenserver/xenapi/etc/xapi.d/plugins ${wrapper} python tools/hacking.py ${ignore} ./plugins/xenserver/xenapi
${wrapper} bash tools/unused_imports.sh
# NOTE(sdague): as of grizzly-2 these are passing however leaving the comment
# in here in case we need to break it out when we get more of our hacking working

13
tox.ini
View File

@ -20,10 +20,15 @@ deps=
pyflakes
commands =
python tools/hacking.py --doctest
python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404 --show-source \
--exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build .
python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404 --show-source \
--filename=nova* bin
python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404,N303 \
--show-source \
--exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,build,./plugins/xenserver/networking/etc/xensource/scripts,./plugins/xenserver/xenapi/etc/xapi.d/plugins .
python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404,N303,N304 \
--show-source \
./plugins/xenserver/networking/etc/xensource/scripts \
./plugins/xenserver/xenapi/etc/xapi.d/plugins
python tools/hacking.py --ignore=E12,E711,E721,E712,N403,N404,N303 \
--show-source --filename=nova* bin
bash tools/unused_imports.sh
[testenv:pylint]