Convenience functions related to modules and importing.
Project description
Convenience functions related to modules and importing.
Latest release 20210123: module_attributes: skip values from other modules if we know the module (computed values like tuples have no module and still need to be returned).
Function direct_imports(src_filename, module_name=None)
Crudely parse src_filename
for import
statements.
Return the set of directly imported module names.
If module_name
is not None
,
resolve relative imports against it.
Otherwise, relative import names are returned unresolved.
This is a very simple minded source parse.
Function import_module_from_file(module_name, source_file, sys_path=None)
Import a specific file as a module instance, return the module instance.
Parameters:
module_name
: the name to assign to the modulesource_file
: the source file to loadsys_path
: optional list of paths to set assys.path
for the duration of this import; the default is the current value ofsys.path
Note that this is a "bare" import;
the module instance is not inserted into sys.modules
.
Warning: sys.path
is modified for the duration of this function,
which may affect multithreaded applications.
Function import_module_name(module_name, name, path=None, lock=None)
Import module_name
and return the value of name
within it.
Parameters:
module_name
: the module name to import.name
: the name within the module whose value is returned; ifname
isNone
, return the module itself.path
: an array of paths to use as sys.path during the import.lock
: a lock to hold during the import (recommended).
Function module_attributes(M)
Generator yielding the names and values of attributes from a module which were defined in the module.
Function module_files(M)
Generator yielding .py
pathnames involved in a module.
Function module_names(M)
Return a list of the names of attributes from a module which were defined in the module.
Release Log
Release 20210123: module_attributes: skip values from other modules if we know the module (computed values like tuples have no module and still need to be returned).
Release 20200521:
- New import_module_from_file function to import a Python file as a module instance.
- New direct_imports(src_filename,module_name=None) returning the set of directly imports module names.
Release 20190101: New functions: module_names, module_attributes.
Release 20160918:
- New generator function module_files yielding pathnames.
- import_module_name: accept name=None, just return the module.
- Add empty "install_requires" for DISTINFO completeness.
Release 20150116: Initial PyPI release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cs.py.modules-20210123.tar.gz
.
File metadata
- Download URL: cs.py.modules-20210123.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.9.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d4a31baf8a7ab6756efca0e91dd4e5436a772d18b82559950bb7a17bf59b8fd |
|
MD5 | 354b66d227a229185d4dab7ce030185a |
|
BLAKE2b-256 | 08608ad188630ac73c0c45bcec2f6556cbb4381c7ec12a167d7d21afa37d679d |