Method summary
- __init__(self, user_path_list = None)
- add_function(self, code, function, module_dir = None)
- add_function_persistent(self, code, function)
- build_search_order(self)
- clear_module_directory(self)
- configure_path(self, cat, code)
- fast_cache(self, code, function)
- get_catalog_files(self)
- get_cataloged_functions(self, code)
- get_environ_path(self)
- get_existing_files(self)
- get_functions(self, code, module_dir = None)
- get_functions_fast(self, code)
- get_module_directory(self)
- get_writable_dir(self)
- get_writable_file(self, existing_only = 0)
- path_key(self, code)
- repair_catalog(self, catalog_path, code)
- set_module_directory(self, module_dir)
- unconfigure_path(self)
- unique_module_name(self, code, module_dir = None)
Methods
- __init__(self, user_path_list = None)
Create a catalog for storing/searching for compiled functions.
user_path_list contains directories that should be searched first for function catalogs. They will come before the path entries in the PYTHONCOMPILED environment varilable.
- add_function(self, code, function, module_dir = None)
Adds a function to the catalog.
The function is added to the cache as well as the first writable file catalog found in the search path. If no code entry exists in the cache, the on disk catalogs are loaded into the cache and function is added to the beginning of the function list.
The path specified by module_dir will replace the 'MODULE' place holder in the catalog search path. See build_search_order() for more info on the search path.
- add_function_persistent(self, code, function)
Store the code->function relationship to disk.
Two pieces of information are needed for loading functions from disk -- the function pickle (which conveniently stores the module name, etc.) and the path to its module's directory. The latter is needed so that the function can be loaded no matter what the user's Python path is.
- build_search_order(self)
Returns a list of paths that are searched for catalogs.
Values specified in the catalog constructor are searched first, then values found in the PYTHONCOMPILED environment variable. The directory returned by default_dir() is always returned at the end of the list.
There is a 'magic' path name called 'MODULE' that is replaced by the directory defined by set_module_directory(). If the module directory hasn't been set, 'MODULE' is ignored.
- clear_module_directory(self)
Reset 'MODULE' path to None so that it is ignored in searches.
- configure_path(self, cat, code)
Add the python path for the given code to the sys.path
unconfigure_path() should be called as soon as possible after imports associated with code are finished so that sys.path is restored to normal.
- fast_cache(self, code, function)
Move function to the front of the cache entry for code
If future calls to the function have the same type signature, this will speed up access significantly because the first function call is correct.
- Note: The cache added to the inline_tools module is significantly
- faster than always calling get_functions, so this isn't as necessary as it used to be. Still, it's probably worth doing.
- get_catalog_files(self)
Returns catalog file list in correct search order.
Some of the catalog files may not currently exists. However, all will be valid locations for a catalog to be created (if you have write permission).
- get_cataloged_functions(self, code)
Load all functions associated with code from catalog search path.
Sometimes there can be trouble loading a function listed in a catalog file because the actual module that holds the function has been moved or deleted. When this happens, that catalog file is "repaired", meaning the entire entry for this function is removed from the file. This only affects the catalog file that has problems -- not the others in the search path.
The "repair" behavior may not be needed, but I'll keep it for now.
- get_environ_path(self)
Return list of paths from 'PYTHONCOMPILED' environment variable.
On Unix the path in PYTHONCOMPILED is a ':' separated list of directories. On Windows, a ';' separated list is used.
- get_existing_files(self)
Returns all existing catalog file list in correct search order.
- get_functions(self, code, module_dir = None)
Return the list of functions associated with this code fragment.
The cache is first searched for the function. If an entry in the cache is not found, then catalog files on disk are searched for the entry. This is slooooow, but only happens once per code object. All the functions found in catalog files on a cache miss are loaded into the cache to speed up future calls. The search order is as follows:
- user specified path (from catalog initialization)
- directories from the PYTHONCOMPILED environment variable
- The temporary directory on your platform.
The path specified by module_dir will replace the 'MODULE' place holder in the catalog search path. See build_search_order() for more info on the search path.
- get_functions_fast(self, code)
Return list of functions for code from the cache.
Return an empty list if the code entry is not found.
- get_module_directory(self)
Return the path used to replace the 'MODULE' in searches.
- get_writable_dir(self)
Return the parent directory of first writable catalog file.
The returned directory has write access.
- get_writable_file(self, existing_only = 0)
Return the name of the first writable catalog file.
Its parent directory must also be writable. This is so that compiled modules can be written to the same directory.
- path_key(self, code)
Return key for path information for functions associated with code.
- repair_catalog(self, catalog_path, code)
Remove entry for code from catalog_path
Occasionally catalog entries could get corrupted. An example would be when a module that had functions in the catalog was deleted or moved on the disk. The best current repair method is just to trash the entire catalog entry for this piece of code. This may loose function entries that are valid, but thats life.
catalog_path must be writable for repair. If it isn't, the function exists with a warning.
- set_module_directory(self, module_dir)
Set the path that will replace 'MODULE' in catalog searches.
You should call clear_module_directory() when your finished working with it.
- unconfigure_path(self)
Restores sys.path to normal after calls to configure_path()
Remove the previously added paths from sys.path
- unique_module_name(self, code, module_dir = None)
Return full path to unique file name that in writable location.
The directory for the file is the first writable directory in the catalog search path. The unique file name is derived from the code fragment. If, module_dir is specified, it is used to replace 'MODULE' in the search path.
