A dynamic module handler, with standalone tools
Project description
ModuleHandler
Installation
.. code:: bash
pip3 install modulehandler
Usage
Considering this folder tree
.. code:: bash
tests_import_handler
├── addons
│ └── m1
│ ├── __init__.py
│ ├── manifest.json
│ └── README.md
├── m2
│ ├── __init__.py
│ └── manifest.json
└── m3.py
.. code:: python
import ModuleHandler
from pathlib import Path
registry = ModuleHandler.ModuleRegistry()
tests_import_handler = Path("tests_import_handler").resolve()
addons = tests_import_handler.joinpath("addons")
m2 = tests_import_handler.joinpath("m2")
m3 = tests_import_handler.joinpath("m3.py")
# Register won't load
registry.register_search_dir(addons)
registry.register_module(m2)
registry.register_module(m3)
# load modules individually
m3 = registry.load("m3") # ignore if already loader with noreload=True
# load all modules
registry.load_all() # ignore if already loader with noreload=True
# access loaded module
m1 = registry["m1"]
m4 = registry.get("m4") # return None
# register + load
m2 = registry.import_module(m2)
# import from search paths if not already loaded
m1 = registry.imports("m1")
# get readme as html
registry.description("m1")
# get module absolute path
registry.path("m1")
Nb:
- This won't change sys search paths nor add modules to sys.modules:
"m1" in sys.modules # False
- loading only replace module in registry but this won't propagate to copy of old module.
Future
- Currently, the configuration filename is not easily editable, same for configuration validation. It may be editable but still with current behaviour kept as default.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
modulehandler-0.3.tar.gz
(3.6 kB
view details)
Built Distribution
File details
Details for the file modulehandler-0.3.tar.gz
.
File metadata
- Download URL: modulehandler-0.3.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bfd88ec9a5486b938eb1d0b0273448a054c09f2f32fa2f88436a552598a418e |
|
MD5 | c44cd7efdf60a98dc22971e437c34929 |
|
BLAKE2b-256 | fd2ef805af1dac031d595d85ef7c3477f3bd759eb8a5299ce42d1f45b895dfa3 |
File details
Details for the file modulehandler-0.3-py3-none-any.whl
.
File metadata
- Download URL: modulehandler-0.3-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc8f5d2189900a5e82cfa355d4cb5c2e40702cb5ba89a2189e5dfe3c93a9180f |
|
MD5 | 6fd95b1f7d55dc8aab9f6e51cd0dcf8b |
|
BLAKE2b-256 | 9bc89490dd0611856532dd543427cda1793ae1c79f5c41d1c5029a17895e82f9 |