Trees | Index | Help |
|
---|
Package logilab :: Package common :: Module modutils |
|
Python modules manipulation utility functions. :version: $Revision: 1.50 $ :author: Logilab :copyright: 2003-2005 LOGILAB S.A. (Paris, FRANCE) :contact: http://www.logilab.fr/ -- mailto:python-projects@logilab.org :type PY_SOURCE_EXTS: tuple(str) :var PY_SOURCE_EXTS: list of possible python source file extension :type STD_LIB_DIR: str :var STD_LIB_DIR: directory where standard modules are located :type BUILTIN_MODULES: dict :var BUILTIN_MODULES: dictionary with builtin module names has key
Exceptions | |
---|---|
NoSourceFile |
exception raised when we are not able to get a python... |
Function Summary | |
---|---|
given a mod path (ie splited module / package name), return the corresponding file, giving priority to source file over precompiled file if it exists :type modpath: list or tuple :param modpath: splitted module's name (i.e name of a module or package splitted on '.') :type path: list or None :param path: optional list of path where the module or package should be searched (use sys.path if nothing or None is given) :type context_file: str or None :param context_file: context file to consider, necessary if the identifier has been introduced using a relative import unresolvable in the actual context (i.e. | |
given a package directory return a list of all available python... | |
given a dotted name return the module part of the name : >>> get_module_part('logilab.common.modutils.get_module_part') 'logilab.common.modutils' :type dotted_name: str :param dotted_name: full name of the identifier we are interested in :type context_file: str or None :param context_file: context file to consider, necessary if the identifier has been introduced using a relative import unresolvable in the actual context (i.e. | |
given a package directory return a list of all available python... | |
given a python module's file name return the matching source file... | |
rtype: bool... | |
return true if the given module name is relative to the given... | |
try to guess if a module is a standard python module (by default,... | |
load a python module from it's splitted name... | |
load a Python module from it's name... | |
load a python module from it's splitted name... | |
given a file path return the corresponding splitted module's name... | |
given a mod path (ie splited module / package name), return the... | |
if the given directory has a valid __init__ file, return its path,... | |
return true if the given filename should be considered as a python file... | |
get a module type / file path... |
Variable Summary | |
---|---|
str |
__revision__ = '$Id: modutils.py,v 1.50 2005/11/22 13:13...
|
dict |
BUILTIN_MODULES = {'zipimport': 1, 'thread': 1, '_codecs...
|
Function Details |
---|
file_from_modpath(modpath, path=None, context_file=None)given a mod path (ie splited module / package name), return the corresponding file, giving priority to source file over precompiled file if it exists :type modpath: list or tuple :param modpath: splitted module's name (i.e name of a module or package splitted on '.') :type path: list or None :param path: optional list of path where the module or package should be searched (use sys.path if nothing or None is given) :type context_file: str or None :param context_file: context file to consider, necessary if the identifier has been introduced using a relative import unresolvable in the actual context (i.e. modutils) :raise ImportError: if there is no such module in the directory :rtype: str or None :return: the path to the module's file or None if it's an integrated builtin module such as 'sys' |
get_module_files(src_directory, blacklist=('CVS', '.svn', 'debian'))given a package directory return a list of all available python module's files in the package and its subpackages :type src_directory: str :param src_directory: path of the directory corresponding to the package :type blacklist: list(str) or tuple(str) :param blacklist: optional list of files or directory to ignore, default to 'CVS', '.svn' and 'debian' :rtype: list :return: the list of all available python module's files in the package and its subpackages |
get_module_part(dotted_name, context_file=None)given a dotted name return the module part of the name : >>> get_module_part('logilab.common.modutils.get_module_part') 'logilab.common.modutils' :type dotted_name: str :param dotted_name: full name of the identifier we are interested in :type context_file: str or None :param context_file: context file to consider, necessary if the identifier has been introduced using a relative import unresolvable in the actual context (i.e. modutils) :raise ImportError: if there is no such module in the directory :rtype: str or None :return: the module part of the name or None if we have not been able at all to import the given name XXX: deprecated, since it doesn't handle package precedence over module (see #10066) |
get_modules(package, src_directory, blacklist=('CVS', '.svn', 'debian'))given a package directory return a list of all available python modules in the package and its subpackages :type package: str :param package: the python name for the package :type src_directory: str :param src_directory: path of the directory corresponding to the package :type blacklist: list or tuple :param blacklist: optional list of files or directory to ignore, default to 'CVS', '.svn' and 'debian' :rtype: list :return: the list of all available python modules in the package and its subpackages |
get_source_file(filename, include_no_ext=False)given a python module's file name return the matching source file name (the filename will be returned identically if it's a already an absolute path to a python source file...) :type filename: str :param filename: python module's file name :raise NoSourceFile: if no source file exists on the file system :rtype: str :return: the absolute path of the source file if it exists |
is_python_source(filename)rtype: bool return: True if the filename is a python source file |
is_relative(modname, from_file)return true if the given module name is relative to the given file name :type modname: str :param modname: name of the module we are interested in :type from_file: str :param from_file: path of the module from which modname has been imported :rtype: bool :return: true if the module has been imported relativly to `from_file` |
is_standard_module(modname, std_path=('/usr/lib/python2.3',))try to guess if a module is a standard python module (by default, see `std_path` parameter's description) :type modname: str :param modname: name of the module we are interested in :type std_path: list(str) or tuple(str) :param std_path: list of path considered has standard :rtype: bool :return: true if the module: - is located on the path listed in one of the directory in `std_path` - is a built-in module |
load_module_from_modpath(parts, path=None, use_sys=1, _prefix=None)load a python module from it's splitted name :type parts: list(str) or tuple(str) :param parts: python name of a module or package splitted on '.' :type path: list or None :param path: optional list of path where the module or package should be searched (use sys.path if nothing or None is given) :type use_sys: bool :param use_sys: boolean indicating whether the sys.modules dictionary should be used or not :param _prefix: used internally, should not be specified :raise ImportError: if the module or package is not found :rtype: module :return: the loaded module |
load_module_from_name(dotted_name, path=None, use_sys=1)load a Python module from it's name :type dotted_name: str :param dotted_name: python name of a module or package :type path: list or None :param path: optional list of path where the module or package should be searched (use sys.path if nothing or None is given) :type use_sys: bool :param use_sys: boolean indicating whether the sys.modules dictionary should be used or not :raise ImportError: if the module or package is not found :rtype: module :return: the loaded module |
load_module_from_parts(parts, path=None, use_sys=1, _prefix=None)load a python module from it's splitted name :type parts: list(str) or tuple(str) :param parts: python name of a module or package splitted on '.' :type path: list or None :param path: optional list of path where the module or package should be searched (use sys.path if nothing or None is given) :type use_sys: bool :param use_sys: boolean indicating whether the sys.modules dictionary should be used or not :param _prefix: used internally, should not be specified :raise ImportError: if the module or package is not found :rtype: module :return: the loaded module |
modpath_from_file(filename)given a file path return the corresponding splitted module's name (i.e name of a module or package splitted on '.') :type filename: str :param filename: file's path for which we want the module's name :raise ImportError: if the corresponding module's name has not been found :rtype: list(str) :return: the corresponding splitted module's name |
_file_from_modpath(modpath, path=None, context=None)given a mod path (ie splited module / package name), return the corresponding file this function is used internally, see `file_from_modpath`'s documentation for more information |
_has_init(directory)if the given directory has a valid __init__ file, return its path, else return None |
_is_python_file(filename)return true if the given filename should be considered as a python file .pyc and .pyo are ignored |
_module_file(modpath, path=None)get a module type / file path :type modpath: list or tuple :param modpath: splitted module's name (i.e name of a module or package splitted on '.') :type path: list or None :param path: optional list of path where the module or package should be searched (use sys.path if nothing or None is given) :rtype: tuple(int, str) :return: the module type flag and the file path for a module |
Variable Details |
---|
__revision__
|
BUILTIN_MODULES
|
Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Fri Jan 6 10:52:59 2006 | http://epydoc.sf.net |