A tool for managing dependencies in a modular python project by tracking which dependencies are needed by which sub-modules
Project description
Import Tracker
Import Tracker
is a Python package offering a number of capabilities related to tracking and managing optional dependencies in Python projects. Specifically, this project enables developers to:
-
Enable lazy imports in their Python projects to prevent code from crashing when uninstalled imports are imported, but not utilized. This can be helpful in large projects, especially those which incorporate lots of hierarchical wild imports, as importing the top level package of such projects can often bring a lot of heavy dependencies into
sys.modules
. -
Track the dependencies of their Python projects to identify which subpackages are leveraging which dependencies, and so on.
Integrating Import Tracker into your projects
In order to integrate Import Tracker
into your project, you'll generally need to replace normal imports in your top level package initialization with calls to import_tracker.import_module
. Such imports will then be subject to the aforementioned behaviors, which are dependent on the value of IMPORT_TRACKER_MODE
. The best sample of how to do this can be found in the initialization file for the sample_lib
leveraged by this project for testing.
Running Import Tracker
Once you have integrated Import Tracker
into your project, you can start leveraging it immediately. In general, the functionality of module imports through Import Tracker
are controlled by setting the IMPORT_TRACKER_MODE
environment variable to one of the following values.
LAZY
: When a module is imported, build a lazy module wrapper that will only try to import the module if an attribute of the wrapped module is accessed.BEST_EFFORT
†: When a module is imported, actually do the import, but wrap it with lazy error semantics.PROACTIVE
: When a module is imported, simply import and return it. This is functionally equivalent to invoking importlib.import_module.TRACKING
: Track the dependencies of a module and dump the results to a JSON file.
Depending on your choice of value for IMPORT_TRACKER_MODE
, you may want to simply run your project code (i.e., for the use-case of having lazy imports), or you may want to run the Import Tracker
module directly to dig into your dependencies. To understand how to accomplish the latter, you can run the following command.
python3 -m import_tracker --help
Currently, the easiest way to run Import Tracker
on a project is to ensure that your project is on your PYTHONPATH
and invoke the main entrypoint:
python3 -m import_tracker -n sample_lib
†: Currently, BEST_EFFORT
is the default behavior if IMPORT_TRACKER_MODE
is unset.
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 Distributions
Built Distributions
Hashes for import_tracker-0.0.3-py310-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94a9c21d78fdae3c63046d47abe8877bc1f93a135c734549462c94a56a11203e |
|
MD5 | e84b3e276fbf93e295e32e13a7430a85 |
|
BLAKE2b-256 | 0c9d966e30ebfe2f9e00c234ffab457987c0b0c90cc71a995d5e483907de6148 |
Hashes for import_tracker-0.0.3-py39-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 828f2a8e448964914fec71faccf325298acb89e85c0ff12e287c1e45179d2aa0 |
|
MD5 | 7f6bae7a2ce582fafe0ca61c486ee7e1 |
|
BLAKE2b-256 | 8f01aa4b1000745b82ae495a8761c03060bb800605e39ef2d1df4f3e2d47efbe |
Hashes for import_tracker-0.0.3-py38-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12efde771c76ef26cfb8a5fe2a1d6d8077acdd5b09bea08ca61605c302631683 |
|
MD5 | 0325fc4e0cbe6f74f0791a34cecc6814 |
|
BLAKE2b-256 | e570607774969a8f30669c41e883e1d712574a5555f205dd1709329c64cdb8db |
Hashes for import_tracker-0.0.3-py37-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e18900edb71d167e8ad3c65a9378b69f06876454d39a502508f3c4738c1f6621 |
|
MD5 | 5b412f4d2033a52b86355effb7aaceff |
|
BLAKE2b-256 | 9e1d63c6e9ff4087cb1be411e918aa298c7f3909c828fd5328810932be26afcd |