Revision f6cbcc06
b/Makefile.am | ||
---|---|---|
24 | 24 |
CHECK_MAN = $(top_srcdir)/autotools/check-man |
25 | 25 |
CHECK_VERSION = $(top_srcdir)/autotools/check-version |
26 | 26 |
CHECK_NEWS = $(top_srcdir)/autotools/check-news |
27 |
CHECK_IMPORTS = $(top_srcdir)/autotools/check-imports |
|
27 | 28 |
DOCPP = $(top_srcdir)/autotools/docpp |
28 | 29 |
REPLACE_VARS_SED = autotools/replace_vars.sed |
29 | 30 |
CONVERT_CONSTANTS = $(top_srcdir)/autotools/convert-constants |
... | ... | |
540 | 541 |
pylintrc \ |
541 | 542 |
autotools/build-bash-completion \ |
542 | 543 |
autotools/check-python-code \ |
544 |
autotools/check-imports \ |
|
543 | 545 |
autotools/check-man \ |
544 | 546 |
autotools/check-news \ |
545 | 547 |
autotools/check-tar \ |
... | ... | |
752 | 754 |
|
753 | 755 |
check_python_code = \ |
754 | 756 |
$(BUILD_BASH_COMPLETION) \ |
757 |
$(CHECK_IMPORTS) \ |
|
755 | 758 |
$(DOCPP) \ |
756 | 759 |
$(all_python_code) |
757 | 760 |
|
... | ... | |
762 | 765 |
$(dist_tools_PYTHON) \ |
763 | 766 |
$(pkglib_python_scripts) \ |
764 | 767 |
$(BUILD_BASH_COMPLETION) \ |
768 |
$(CHECK_IMPORTS) \ |
|
765 | 769 |
$(DOCPP) \ |
766 | 770 |
$(PYTHON_BOOTSTRAP) |
767 | 771 |
|
772 |
standalone_python_modules = \ |
|
773 |
lib/rapi/client.py \ |
|
774 |
tools/ganeti-listrunner |
|
775 |
|
|
768 | 776 |
test/daemon-util_unittest.bash: daemons/daemon-util |
769 | 777 |
|
770 | 778 |
test/ganeti-cleaner_unittest.bash: daemons/ganeti-cleaner |
... | ... | |
1048 | 1056 |
if test -n "$$error"; then exit 1; else exit 0; fi; \ |
1049 | 1057 |
} |
1050 | 1058 |
|
1051 |
check-local: check-dirs |
|
1059 |
.PHONY: check-local |
|
1060 |
check-local: check-dirs $(BUILT_SOURCES) |
|
1052 | 1061 |
$(CHECK_PYTHON_CODE) $(check_python_code) |
1053 | 1062 |
$(CHECK_VERSION) $(VERSION) $(top_srcdir)/NEWS |
1054 | 1063 |
$(CHECK_NEWS) < $(top_srcdir)/NEWS |
1064 |
PYTHONPATH=. $(RUN_IN_TEMPDIR) $(CURDIR)/$(CHECK_IMPORTS) $(CURDIR) $(standalone_python_modules) |
|
1055 | 1065 |
expver=$(VERSION_MAJOR).$(VERSION_MINOR); \ |
1056 | 1066 |
if test "`head -n 1 $(top_srcdir)/README`" != "Ganeti $$expver"; then \ |
1057 | 1067 |
echo "Incorrect version in README, expected $$expver"; \ |
b/autotools/check-imports | ||
---|---|---|
1 |
#!/usr/bin/python |
|
2 |
# |
|
3 |
|
|
4 |
# Copyright (C) 2011 Google Inc. |
|
5 |
# |
|
6 |
# This program is free software; you can redistribute it and/or modify |
|
7 |
# it under the terms of the GNU General Public License as published by |
|
8 |
# the Free Software Foundation; either version 2 of the License, or |
|
9 |
# (at your option) any later version. |
|
10 |
# |
|
11 |
# This program is distributed in the hope that it will be useful, but |
|
12 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 |
# General Public License for more details. |
|
15 |
# |
|
16 |
# You should have received a copy of the GNU General Public License |
|
17 |
# along with this program; if not, write to the Free Software |
|
18 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
19 |
# 02110-1301, USA. |
|
20 |
|
|
21 |
|
|
22 |
"""Script to check module imports. |
|
23 |
|
|
24 |
""" |
|
25 |
|
|
26 |
# pylint: disable=C0103 |
|
27 |
# C0103: Invalid name |
|
28 |
|
|
29 |
import sys |
|
30 |
|
|
31 |
# All modules imported after this line are removed from the global list before |
|
32 |
# importing a module to be checked |
|
33 |
_STANDARD_MODULES = sys.modules.keys() |
|
34 |
|
|
35 |
import os.path |
|
36 |
|
|
37 |
from ganeti import build |
|
38 |
|
|
39 |
|
|
40 |
def main(): |
|
41 |
args = sys.argv[1:] |
|
42 |
|
|
43 |
# Get references to functions used later on |
|
44 |
load_module = build.LoadModule |
|
45 |
abspath = os.path.abspath |
|
46 |
commonprefix = os.path.commonprefix |
|
47 |
normpath = os.path.normpath |
|
48 |
|
|
49 |
script_path = abspath(__file__) |
|
50 |
srcdir = normpath(abspath(args.pop(0))) |
|
51 |
|
|
52 |
assert "ganeti" in sys.modules |
|
53 |
|
|
54 |
for filename in args: |
|
55 |
# Reset global state |
|
56 |
for name in sys.modules.keys(): |
|
57 |
if name not in _STANDARD_MODULES: |
|
58 |
sys.modules.pop(name, None) |
|
59 |
|
|
60 |
assert "ganeti" not in sys.modules |
|
61 |
|
|
62 |
# Load module (this might import other modules) |
|
63 |
module = load_module(filename) |
|
64 |
|
|
65 |
result = [] |
|
66 |
|
|
67 |
for (name, checkmod) in sorted(sys.modules.items()): |
|
68 |
if checkmod is None or checkmod == module: |
|
69 |
continue |
|
70 |
|
|
71 |
try: |
|
72 |
checkmodpath = getattr(checkmod, "__file__") |
|
73 |
except AttributeError: |
|
74 |
# Built-in module |
|
75 |
pass |
|
76 |
else: |
|
77 |
abscheckmodpath = os.path.abspath(checkmodpath) |
|
78 |
|
|
79 |
if abscheckmodpath == script_path: |
|
80 |
# Ignore check script |
|
81 |
continue |
|
82 |
|
|
83 |
if commonprefix([abscheckmodpath, srcdir]) == srcdir: |
|
84 |
result.append(name) |
|
85 |
|
|
86 |
if result: |
|
87 |
raise Exception("Module '%s' has illegal imports: %s" % |
|
88 |
(filename, ", ".join(result))) |
|
89 |
|
|
90 |
|
|
91 |
if __name__ == "__main__": |
|
92 |
main() |
b/autotools/run-in-tempdir | ||
---|---|---|
10 | 10 |
|
11 | 11 |
cp -r autotools daemons scripts lib tools test $tmpdir |
12 | 12 |
mv $tmpdir/lib $tmpdir/ganeti |
13 |
ln -T -s $tmpdir/ganeti $tmpdir/lib |
|
13 | 14 |
mkdir -p $tmpdir/htools |
14 | 15 |
if [ -e htools/test ]; then |
15 | 16 |
cp -p htools/test $tmpdir/htools/ |
Also available in: Unified diff