blob: 9ae078892d54cb3a5cec70a0fd684cc9d4ca363a [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +00001
2:mod:`modulefinder` --- Find modules used by a script
3=====================================================
4
5.. sectionauthor:: A.M. Kuchling <amk@amk.ca>
6
7
8.. module:: modulefinder
9 :synopsis: Find modules used by a script.
10
11
Georg Brandl116aa622007-08-15 14:28:22 +000012This module provides a :class:`ModuleFinder` class that can be used to determine
13the set of modules imported by a script. ``modulefinder.py`` can also be run as
14a script, giving the filename of a Python script as its argument, after which a
15report of the imported modules will be printed.
16
17
18.. function:: AddPackagePath(pkg_name, path)
19
20 Record that the package named *pkg_name* can be found in the specified *path*.
21
22
23.. function:: ReplacePackage(oldname, newname)
24
25 Allows specifying that the module named *oldname* is in fact the package named
26 *newname*. The most common usage would be to handle how the :mod:`_xmlplus`
27 package replaces the :mod:`xml` package.
28
29
30.. class:: ModuleFinder([path=None, debug=0, excludes=[], replace_paths=[]])
31
32 This class provides :meth:`run_script` and :meth:`report` methods to determine
33 the set of modules imported by a script. *path* can be a list of directories to
34 search for modules; if not specified, ``sys.path`` is used. *debug* sets the
35 debugging level; higher values make the class print debugging messages about
36 what it's doing. *excludes* is a list of module names to exclude from the
37 analysis. *replace_paths* is a list of ``(oldpath, newpath)`` tuples that will
38 be replaced in module paths.
39
40
41.. method:: ModuleFinder.report()
42
43 Print a report to standard output that lists the modules imported by the script
44 and their paths, as well as modules that are missing or seem to be missing.
45
46
47.. method:: ModuleFinder.run_script(pathname)
48
49 Analyze the contents of the *pathname* file, which must contain Python code.
50