Skip to main content

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

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

packageinit-1.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

packageinit-1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file packageinit-1.0.tar.gz.

File metadata

  • Download URL: packageinit-1.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for packageinit-1.0.tar.gz
Algorithm Hash digest
SHA256 08341acef1f613f8edddbe80385340de44c13f55487d77aac485b8f3879d664f
MD5 bb4caf63440eeedb1641a9b9c534300d
BLAKE2b-256 8c50e0a7dd2ae9388ada1959f904fb5d3943e653cac2d7615c6c3a1b33927d3b

See more details on using hashes here.

File details

Details for the file packageinit-1.0-py3-none-any.whl.

File metadata

  • Download URL: packageinit-1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for packageinit-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3b792ff562f3fb3a80cb17e020a0585c4389afd74740c0306ebef7b690f0ef15
MD5 53a627a9d2b22e6cb3a0e99615b420ab
BLAKE2b-256 71075ff35f8618b5887942ac5419ff45b9efe727f3a032c807b11df5747b9b55

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page