Trivial library that will import the whole module tree
Project description
recursive_import
Trivial library that will import the whole module tree.
Main use case for this library is importing everything in given package. Simplest exaple are decorators that register stuff for CI, a bit like annotation scanning in Java.
Requires python 3.5+, because of
typing
. Besides that, there are no dependencies.
System-independent. Tested on CPython 3.9-3.12 (to simplify CI), but its really trivial.
The whole API is best documented by docstrings:
def package_root(pkg: ModuleType) -> str:
"""
Find out where is the root directory holding code for specified package or module.
:param pkg: package to be located.
:raise ValueError: if the argument is a module and not a package
:return: absolute path to the directory holding the `__init__` file of the package
"""
(...)
def current_project_root() -> str:
"""
Find out where is the root directory holding code for currently running app.
By "currently running app" we mean the module that is present as `__main__`.
:return: absolute path to the directory holding the module that is `__main__`
"""
(...)
def import_package_recursively(root_package: str) -> None:
"""
Will import the package specified by name and all its subpackages and submodules recursively.
Order is: each subpackage or submodule of the package, then recurse in that same order.
:param root_package: name of the package to be scanned. If that's already a subpackage, its parent packages
will get imported by default (because that's how python works)
"""
(...)
Reading the test suite is gonna be useful too, in case of uncertainty.
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
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file recursive_import-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: recursive_import-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fff19508675bda5afbec884bcccf54ad267f9948d4f9874c272ac8348c76843 |
|
MD5 | f8308ec59d2277a641f9dbb0b6051f71 |
|
BLAKE2b-256 | 44d6ea30fa4cee12ee1f39b1dfe7e14c4199aa6306b559d6070cbda2f3a0bf03 |