Skip to main content

Trivial library that will import the whole module tree

Project description

recursive_import

CI PyPI version

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


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

recursive_import-1.0.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file recursive_import-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for recursive_import-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fff19508675bda5afbec884bcccf54ad267f9948d4f9874c272ac8348c76843
MD5 f8308ec59d2277a641f9dbb0b6051f71
BLAKE2b-256 44d6ea30fa4cee12ee1f39b1dfe7e14c4199aa6306b559d6070cbda2f3a0bf03

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page