This release is a pre-release and may not be stable for production use.
PyDyImport
Dynamically import python file to aviod mess when you are using a different directory structure from python suggested.
Usage
Just construct a DynamicImport instance and call DynamicImport.require
from pydyimport import DynamicImport
require = DynamicImport(__file__).require
mod = require("path/to/file.py")
If you only need some of fields in the module, use DynamicImport.require_only, which always return a tuple.
from pydyimport import DynamicImport
require_only = DynamicImport(__file__).require_only
foo, = require_only("path/to/file.py", 'foo') # still return tuple even if only one field described
Spam1, Spam2 = require_only("path/to/file.py", 'Spam1', 'Spam2')
You can inject environment variables to the modules you will import by the use of env_injector option of DynamicImport.
from pydyimport import DynamicImport
def meaningless_env_injector(path: str, code: bytes):
return {
'__meaning__': 'no',
}
importer = DynamicImport(__file__, env_injector=meaningless_env_injector)
importer.require("path/to/file.py")
You can inject require* functions by RequireEnvInjector,
from pydyimport import DynamicImport
from pydyimport.injector import RequireEnvInjector
require = DynamicImport(__file__, env_injector=RequireEnvInjector(next_injector=None))
require('path/to/module.py')
or just set inject_require True.
from pydyimport import DynamicImport
require = DynamicImport(__file__, inject_require=True)
require('path/to/module.py')
If your source contains # inject_require, the require* functions will automatically inject require* functions to the module.
#!/usr/bin/env python
# inject_require
require('path/to/module.py')
Spam1, foo = require_only('path/to/module2.py', 'Spam1', 'foo')
License
GNU GENERAL PUBLIC LICENSE, version 3 or later.
PyDyImport - dynamically importing and avoid mess in python
Copyright (C) 2020 thisLight
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Metadata
Release files for pydyimport 0.0.1a3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydyimport-0.0.1a3.tar.gz | 3.9 kB | Without provenance | Details for pydyimport-0.0.1a3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pydyimport-0.0.1a3-py3-none-any.whl | Python 3 | none | any | Details for pydyimport-0.0.1a3-py3-none-any.whl |
Total release size: 21.1 kB
Release files / pydyimport-0.0.1a3.tar.gz
| Download URL | pydyimport-0.0.1a3.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
890fbbcb4923ceb5430930fe530a197bc6920ef4473aaba7ee4fe631f1aa4e27
|
|
BLAKE2b-256 checksum How to use checksums |
985c4be979778a7ec172771112bda0759b12a9256b4156bd132b14548c2544a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Release files / pydyimport-0.0.1a3-py3-none-any.whl
| Download URL | pydyimport-0.0.1a3-py3-none-any.whl |
|---|---|
| Size | 17.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b37b20cd2689109e5e2716326cc81587f3f7771fc221d63f803c4e928a215528
|
|
BLAKE2b-256 checksum How to use checksums |
51a8e14c7d24a9aaf822195f345a093150e9e68b1655ff0dfe7241398eeafbc0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5
|
Security for pydyimport 0.0.1a3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.