Andrew M. Kuchling | 17e33e4 | 2004-08-07 20:13:34 +0000 | [diff] [blame] | 1 | \section{\module{modulefinder} --- |
| 2 | Find modules used by a script} |
| 3 | \sectionauthor{A.M. Kuchling}{amk@amk.ca} |
| 4 | |
| 5 | \declaremodule{standard}{modulefinder} |
| 6 | \modulesynopsis{Find modules used by a script.} |
| 7 | |
Fredrik Lundh | 049fd90 | 2006-01-11 00:14:29 +0000 | [diff] [blame] | 8 | \versionadded{2.3} |
| 9 | |
Andrew M. Kuchling | 17e33e4 | 2004-08-07 20:13:34 +0000 | [diff] [blame] | 10 | This module provides a \class{ModuleFinder} class that can be used to |
| 11 | determine the set of modules imported by a script. |
| 12 | \code{modulefinder.py} can also be run as a script, giving the |
| 13 | filename of a Python script as its argument, after which a report of |
| 14 | the imported modules will be printed. |
| 15 | |
| 16 | \begin{funcdesc}{AddPackagePath}{pkg_name, path} |
| 17 | Record that the package named \var{pkg_name} can be found in the specified \var{path}. |
| 18 | \end{funcdesc} |
| 19 | |
| 20 | \begin{funcdesc}{ReplacePackage}{oldname, newname} |
| 21 | Allows specifying that the module named \var{oldname} is in fact |
| 22 | the package named \var{newname}. The most common usage would be |
| 23 | to handle how the \module{_xmlplus} package replaces the \module{xml} |
| 24 | package. |
| 25 | \end{funcdesc} |
| 26 | |
| 27 | \begin{classdesc}{ModuleFinder}{\optional{path=None, debug=0, excludes=[], replace_paths=[]}} |
| 28 | |
| 29 | This class provides \method{run_script()} and \method{report()} |
| 30 | methods to determine the set of modules imported by a script. |
| 31 | \var{path} can be a list of directories to search for modules; if not |
| 32 | specified, \code{sys.path} is used. |
| 33 | \var{debug} sets the debugging level; higher values make the class print |
| 34 | debugging messages about what it's doing. |
| 35 | \var{excludes} is a list of module names to exclude from the analysis. |
| 36 | \var{replace_paths} is a list of \code{(\var{oldpath}, \var{newpath})} |
| 37 | tuples that will be replaced in module paths. |
| 38 | \end{classdesc} |
| 39 | |
| 40 | \begin{methoddesc}[ModuleFinder]{report}{} |
| 41 | Print a report to standard output that lists the modules imported by the script |
| 42 | and their |
| 43 | paths, as well as modules that are missing or seem to be missing. |
| 44 | \end{methoddesc} |
| 45 | |
| 46 | \begin{methoddesc}[ModuleFinder]{run_script}{pathname} |
| 47 | Analyze the contents of the \var{pathname} file, which must contain |
| 48 | Python code. |
| 49 | \end{methoddesc} |
| 50 | |
| 51 | |