Metadata-Version: 2.1
Name: recursive-import
Version: 1.0.0
Summary: Trivial library that will import the whole module tree
Author-email: Filip Malczak <filip.malczak@gmail.com>
License: MIT License
        
        Copyright (c) 2024 Filip
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/FilipMalczak/recursive_import
Keywords: import
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.5
Description-Content-Type: text/markdown
License-File: LICENSE

# recursive_import

[![CI](https://github.com/FilipMalczak/recursive_import/actions/workflows/ci.yml/badge.svg)](https://github.com/FilipMalczak/recursive-import/actions/workflows/ci.yml)
[![PyPI version](https://badge.fury.io/py/recursive-import.svg)](https://badge.fury.io/py/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:

```python
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](./test/test_recursive_import_from_root.py) is gonna be useful too, in case of uncertainty.
