SitemapMcMillan Enterprises, Inc.Python Pages Sockets HOWTO Distributing Python Programs Download Python Archives Standalone Executables Installer Release 5 Gettin Started with Release 5 Spec Files When Things Go Wrong Analyzing Python Modules An Import Framework Installer Release 4 A Python C++ API Embedding Python Stackless Python MkSQL Import Hooks Java Samples Sponsoring ME Inc. About ME Inc. |
A modulefinder Replacement[This is part of Installer release 5. It can also be downloaded separately.] Module It also uses Instead of an ImportTracker
analyze_one()When a name is imported, there are structural and dynamic effects. The dynamic effects are due to the execution of the top-level code in the module (or modules) that get imported. The structural effects have to do with whether the import is relative or absolute, and whether the name is a dotted name (if there are N dots in the name, then N+1 modules will be imported even without any code running). The Module ClassesThere are The highly astute will notice that there is a hole in code scanningLike The code scanning also keeps track (as well as it can) of the context of an import. It recognizes when imports are found at the top-level, and when they are found inside definitions (deferred imports). Within that, it also tracks whether the import is inside a condition (conditional imports). HooksIn
The first hook ( The second hook ( The callable hook exists for things like dynamic modification of a package's [Download an example hooks package (as a zip or tar.gz file) - Installer 5 already contains these files.] Warnings
Note that by using a hook module, you can silence some particularly tiresome warnings, but not all of them. Cross ReferenceOnce a full analysis (that is, an UsageA simple example follows:
>>> import mf
>>> a = mf.ImportTracker()
>>> a.analyze_r("os")
['os', 'sys', 'posixpath', 'nt', 'stat', 'string', 'strop',
're', 'pcre', 'ntpath', 'dospath', 'macpath', 'win32api',
'UserDict', 'copy', 'types', 'repr', 'tempfile']
>>> a.analyze_one("os")
['os']
>>> a.modules['string'].imports
[('strop', 0, 0), ('strop.*', 0, 0), ('re', 1, 1)]
>>>
The tuples in the
>>> for w in a.modules['string'].warnings: print w
...
W: delayed eval hack detected at line 359
W: delayed eval hack detected at line 389
W: delayed eval hack detected at line 418
>>> for w in a.getwarnings(): print w
...
W: no module named pwd (delayed, conditional import by posixpath)
W: no module named dos (conditional import by os)
W: no module named os2 (conditional import by os)
W: no module named posix (conditional import by os)
W: no module named mac (conditional import by os)
W: no module named MACFS (delayed, conditional import by tempfile)
W: no module named macfs (delayed, conditional import by tempfile)
W: top-level conditional exec statment detected at line 47
- os (C:\Program Files\Python\Lib\os.py)
W: delayed eval hack detected at line 359
- string (C:\Program Files\Python\Lib\string.py)
W: delayed eval hack detected at line 389
- string (C:\Program Files\Python\Lib\string.py)
W: delayed eval hack detected at line 418
- string (C:\Program Files\Python\Lib\string.py)
>>>
(The historically minded will note the antiquity of the Python used to demonstrate this.) |
| copyright 1999-2002 McMillan Enterprises, Inc. |
|