Automatically create init.py files for your whole project
Motivation
Let's say you have this python project structure (And you installed test_repo into your python environment)
test_repo/
├── backend
│ └── server.py
├── frontend
└── util
├── dom_util.py
├── numpy_util.py
├── python_util.py
└── torch_util.py
Now when you want to import a lot of utilities in server.py, you'll have to write
from test_repo.util.dom_util import dom_loader
from test_repo.util.numpy_util import special_gather
from test_repo.util.torch_util import rolling_window
from test_repo.util.python_util import list_rindex
This is cubersome and annoying for anyone using the package externally. Packageinit will automatically create an __init__.py file inside test_repo/util that imports all non-private methods, modules, variables and constants defined in the python files from test_repo/util. Afterwards, you can instead just import all the utilities using
from test_repo.util import dom_loader, special_gather, rolling_window, list_rindex
Installation
pip install packageinit. Optionally install black formatter using pip install black for nicely formatted __init__.py files.
Alternatively, clone this repo and install with pip install -e .
Usage
Individual import mode
packageinit project_folder. This will create __init__.py in each project_folder and each subfolder that contains .py files. Each __init__.py file will import all methods, classes, constants and variables defined in each .py file of its folders via relative import.
Warning: This may overwrite exisiting __init__.py files. It tries to preserve anything not import related in existing __init__.py files, but that only works if they come after the imports.
Warning: For this to work, all imports in your .py files have to be at the top of your files.
Warning: All .py files in your project_folder have to be importable without error for this to work.
Starred mode
packageinit project_folder --starred. This will create __init__.py in each project_folder and each subfolder that contains .py files. Each __init__.py file include from .yourfilename import * for each .py file in it's folder.
Warning: Importing using * may result in cylclic imports depending on the rest of your import structure in the code.
Metadata
Release files for packageinit 1.0
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 |
|---|---|---|---|---|
| packageinit-1.0.tar.gz | 4.2 kB | Without provenance | Details for packageinit-1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| packageinit-1.0-py3-none-any.whl | Python 3 | none | any | Details for packageinit-1.0-py3-none-any.whl |
Total release size: 8.9 kB
Release files / packageinit-1.0.tar.gz
| Download URL | packageinit-1.0.tar.gz |
|---|---|
| Size | 4.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
08341acef1f613f8edddbe80385340de44c13f55487d77aac485b8f3879d664f
|
|
BLAKE2b-256 checksum How to use checksums |
8c50e0a7dd2ae9388ada1959f904fb5d3943e653cac2d7615c6c3a1b33927d3b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Release files / packageinit-1.0-py3-none-any.whl
| Download URL | packageinit-1.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3b792ff562f3fb3a80cb17e020a0585c4389afd74740c0306ebef7b690f0ef15
|
|
BLAKE2b-256 checksum How to use checksums |
71075ff35f8618b5887942ac5419ff45b9efe727f3a032c807b11df5747b9b55
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/4.0.2 CPython/3.11.7
|
Security for packageinit 1.0
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.