From d066a50e9a196cc870b298144acec224f7cfbd5b Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Fri, 15 Feb 2013 16:26:40 -0800 Subject: Fix hacking tests on osx There were a few incompatibilities with the hacking tests and OSX. Readlink -f doesn't work so use cd and pwd instead. Importing a module with path separators doesn't work, so recursively import the module. Finally the extra / in the find command was not needed. Add a 'set -e' to run_pep8 to make sure test fails on any error Ignore paste as it doesn't have an __init__ in its top level directory Change-Id: Ifc66da7b872faa08f3be98f8b10486181ba77861 --- tools/hacking.py | 10 +++++++--- tools/run_pep8.sh | 6 ++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/hacking.py b/tools/hacking.py index d5853d591..69a4d7399 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -48,7 +48,8 @@ logging.disable('LOG') IMPORT_EXCEPTIONS = ['sqlalchemy', 'migrate', 'nova.db.sqlalchemy.session', 'nova.openstack.common.log.logging', - 'nova.db.sqlalchemy.migration.versioning_api'] + 'nova.db.sqlalchemy.migration.versioning_api', 'paste'] +# Paste is missing a __init__ in top level directory START_DOCSTRING_TRIPLE = ['u"""', 'r"""', '"""', "u'''", "r'''", "'''"] END_DOCSTRING_TRIPLE = ['"""', "'''"] VERBOSE_MISSING_IMPORT = os.getenv('HACKING_VERBOSE_MISSING_IMPORT', 'False') @@ -187,9 +188,12 @@ def nova_import_rules(logical_line): # pass the doctest, since the relativity depends on the file's locality def is_module_for_sure(mod, search_path=sys.path): - mod_path = mod.replace('.', os.sep) try: - imp.find_module(mod_path, search_path) + while '.' in mod: + pack_name, _sep, mod = mod.partition('.') + f, p, d = imp.find_module(pack_name, search_path) + search_path = [p] + imp.find_module(mod, search_path) except ImportError: return False return True diff --git a/tools/run_pep8.sh b/tools/run_pep8.sh index 4e7212e08..80c20a92d 100755 --- a/tools/run_pep8.sh +++ b/tools/run_pep8.sh @@ -1,4 +1,6 @@ #!/bin/bash + +set -e # This is used by run_tests.sh and tox.ini python tools/hacking.py --doctest @@ -12,7 +14,7 @@ ${PEP8} ${EXCLUDE} . ${PEP8} --filename=nova* bin -SCRIPT_ROOT=$(echo $(dirname $(readlink -f "$0")) | sed s/\\/tools//) +SCRIPT_ROOT=$(echo $(cd "$(dirname $0)"; pwd) | sed s/\\/tools//) SCRIPTS_PATH=${SCRIPT_ROOT}/plugins/xenserver/networking/etc/xensource/scripts PYTHONPATH=${SCRIPTS_PATH} ${PEP8} ./plugins/xenserver/networking @@ -20,6 +22,6 @@ PYTHONPATH=${SCRIPTS_PATH} ${PEP8} ./plugins/xenserver/networking # NOTE(sirp): Also check Dom0 plugins w/o .py extension PLUGINS_PATH=${SCRIPT_ROOT}/plugins/xenserver/xenapi/etc/xapi.d/plugins PYTHONPATH=${PLUGINS_PATH} ${PEP8} ./plugins/xenserver/xenapi \ - `find plugins/xenserver/xenapi/etc/xapi.d/plugins/ -type f -perm +111` + `find plugins/xenserver/xenapi/etc/xapi.d/plugins -type f -perm +111` ! pyflakes nova/ | grep "imported but unused" -- cgit