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