API Reference for Enthought Tool Suite 3.0.1
This module contains utility functions for finding the functions contained within package or module and its sub-packages or modules.
# Search a module for all its functions. >>> from search_package2 import find_functions >>> find_functions('atexit') [('atexit', '_run_exitfuncs'), ('atexit', 'register')]
# Search a package and all its sub-packages for functions. >>> funcs = find_functions('xml') >>> for func in funcs[:3]: print func ('xml.dom.domreg', 'registerDOMImplementation') ('xml.dom.domreg', '_good_enough') ('xml.dom.domreg', 'getDOMImplementation')
Globals
logger = logging.getLogger(__name__)
Recursively find all the functions in a package or module.
By default, find_functions searches for functions by "scanning" the code for function definitions. It does this by using Python's AST. This prevents python from loading all of the modules into memory, but it also can miss some functions. Setting import_method=True will actually import the modules in its search and may find functions that are not found using the other method.
Find functions by traversing an abstract syntax tree generated by the compiler module. fixme: expand docstring, possibly provide response about non-existant modules/packages
Find functions using an import statement. Sloppier and consumes more memory than find_functions_ast, but also get submodules of the modules, which the ast method cannot do. For example, giving it 'os', it would also find functions from os.path. It also follows import statements in the files, which may or may not be desirable.
Search a module and all the modules within it for functions.
The function imports the module and searches its __dict__ for functions. It also search any module found within the module for functions.
Return a list of python modules (.py files) in a package.
Return a list of python modules (.py files) in a directory. If an __init__.py file is not present, do not look in the directory.
Given a module, get an absolute path to it.
pkgutil, instead of imp, is used for 2 reasons:
- pkgutil works with dotted names
- pkgutil works with eggs
There are a couple of downsides, the methods we use are not documented and the method was added in python 2.5. For convenience, _pkgutil is used instread, which is copied from Python 2.5 to support Python 2.4.
Return whether the given module name is a module.
Return whether the given module name is a package.
This function will search the standard python path for the module. If it is defined as an __init__.py, we return True. Otherwise False.
Ensure the file path uses the platform's directory separator.
Given a package/module name and the absolute path to a python file, return a path in the form that python can understand (ie one that could be specified in an import statement) package_path can be optionally specified to give the file path to the package. This is automatically determined if not specified, but as determining this is an expensive operation, it is best to calculate this outside the function if one will be looking up many functions in the same module.
Given a and _ast node produced by 'compile' with the _ast.PyCF_ONLY_AST flag, returns a list of CallableObjects s from that node's toplevel functions.
| Local name | Refers to |
|---|---|
| _ast | _ast |
| _pkgutil | enthought.block_canvas.function_tools._pkgutil |
| glob | glob.glob |
| inspect | inspect |
| logging | logging |
| os | os |
© Copyright 2002-2008 Enthought, Inc.