No project description provided
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for packageinit-1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b792ff562f3fb3a80cb17e020a0585c4389afd74740c0306ebef7b690f0ef15 |
|
MD5 | 53a627a9d2b22e6cb3a0e99615b420ab |
|
BLAKE2b-256 | 71075ff35f8618b5887942ac5419ff45b9efe727f3a032c807b11df5747b9b55 |