Auto-generate missing __init__.py files to fix Python import issues and ensure proper module discovery.
Project description
pyinitgen
Auto-generate missing __init__.py files to fix Python import issues and ensure proper module discovery.
⚡ Quick Start
Prerequisites
- Python 3.8 or higher
Installation
pip install pyinitgen
Run
Navigate to your project root and run:
pyinitgen
Demo
# Preview changes without writing (Safe Mode)
pyinitgen --dry-run
# Run and fix your project structure
pyinitgen
# Output:
# Created src/utils/__init__.py
# ✅ Operation complete. Scanned 43 dirs, created 8 new __init__.py files.
✨ Features
- 📂 Recursive Scan: Intelligently walks your directory tree to find all Python module folders.
- 🛠️ Auto-creates
__init__.py: Generates files only where they are missing. - 🧠 Smart Exclusions: Automatically ignores
node_modules,.git,__pycache__,venv, and other non-Python directories. - ✍️ Custom Content: Inject custom code (e.g., license headers) into every new
__init__.py. - 👀 Dry-Run Mode: Visualize changes before applying them.
- ✅ Check Flag: CI/CD ready—exit with an error if files are missing without modifying disk.
- 🔒 Zero Destructive Actions: Never overwrites existing files.
🛠️ Configuration
Environment Variables
| Name | Description | Default | Required |
|---|---|---|---|
CREATE_DUMP_PALETTE |
Select a fixed color palette index (0-5) for the logo. | None (Procedural) | No |
CLI Arguments
| Flag | Short | Description |
|---|---|---|
--base-dir |
Base directory to scan (default: current directory). | |
--dry-run |
Preview changes without writing to disk. | |
--quiet |
-q |
Suppress all non-error output. |
--verbose |
-v |
Show all scanned directories (debug mode). |
--no-emoji |
Disable emoji in the final output. | |
--init-content |
Custom content to write to new __init__.py files. |
|
--check |
Check for missing __init__.py files and exit with code 1 if found. |
|
--version |
Show the program's version number and exit. |
Configuration Files
You can define permanent exclusions in pyproject.toml or .pyinitgen.toml.
pyproject.toml example:
[tool.pyinitgen]
exclude_dirs = ["legacy_code", "test_data"]
.pyinitgenignore example:
Create a .pyinitgenignore file in your root to list folders to skip (one per line).
assets
legacy
temp_builds
🏗️ Architecture
pyinitgen follows a standard Python CLI structure designed for maintainability and speed.
src/
└── pyinitgen/
├── __init__.py
├── banner.py # 🎨 Renders the procedural ASCII art logo
├── cli.py # 🧠 Core logic: Scan, Detect, Create
├── config.py # ⚙️ Configuration loader (TOML handling)
└── ignores.py # 🚫 Ignore pattern processing
Data Flow:
- CLI Entry: Arguments are parsed.
- Config Load: Global config, local TOML files, and
.pyinitgenignoreare merged. - Walker: Directory tree is traversed, filtering out excluded paths.
- Creator: Missing
__init__.pyfiles are identified and created (or reported in Dry Run).
🐞 Troubleshooting
| Error Message | Possible Cause | Solution |
|---|---|---|
ModuleNotFoundError: No module named 'rich' |
Missing dependency. | Run pip install pyinitgen --upgrade. |
Permission denied: '.../__init__.py' |
File system permissions. | Run with appropriate permissions or check folder ownership. |
| No files created | Directories might be ignored. | Check pyproject.toml or .pyinitgenignore exclusions. Use -v to debug. |
Debug Mode: Use the verbose flag to see exactly what directories are being scanned:
pyinitgen -v --dry-run
🤝 Contributing
We welcome contributions! Please see CONTRIBUTING.md for details on how to set up your development environment, run tests, and submit PRs.
Development Setup
- Clone the repo.
- Install dev dependencies:
pip install -e ".[dev]" - Run tests:
python -m pytest tests/
🗺️ Roadmap
- Custom Exclusions: Support for config files.
- CI/CD Check:
--checkflag for pipelines. - Watch Mode: Auto-generate files as directories are created.
- Interactive Mode: Confirm each file creation.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyinitgen-4.0.1.tar.gz.
File metadata
- Download URL: pyinitgen-4.0.1.tar.gz
- Upload date:
- Size: 15.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43621dcba8bf42908fbeb76ac8c475330611bc3d76a60019b84e937699574d25
|
|
| MD5 |
16534a0e7c74b84ea2b93aaf6e13c89d
|
|
| BLAKE2b-256 |
786bf36294f57b83611305e807cdd5431a05d43172099b3654b31b3fbdb40d7a
|
Provenance
The following attestation bundles were made for pyinitgen-4.0.1.tar.gz:
Publisher:
publish.yml on dhruv13x/pyinitgen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyinitgen-4.0.1.tar.gz -
Subject digest:
43621dcba8bf42908fbeb76ac8c475330611bc3d76a60019b84e937699574d25 - Sigstore transparency entry: 764296532
- Sigstore integration time:
-
Permalink:
dhruv13x/pyinitgen@b8068287655fd33459e4ca5ca900bcb4369ff218 -
Branch / Tag:
refs/tags/v4.0.1 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b8068287655fd33459e4ca5ca900bcb4369ff218 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyinitgen-4.0.1-py3-none-any.whl.
File metadata
- Download URL: pyinitgen-4.0.1-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d5ef7f213181051ac0276d1aef3e10c398e1cb275293187977b7753f2d72007
|
|
| MD5 |
9417c7be6d8719d3405fcea822359074
|
|
| BLAKE2b-256 |
18d70567efbce5cea26101eac21ef04193014ff3a5bc7b45c7b8e8d2bbad3ef1
|
Provenance
The following attestation bundles were made for pyinitgen-4.0.1-py3-none-any.whl:
Publisher:
publish.yml on dhruv13x/pyinitgen
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyinitgen-4.0.1-py3-none-any.whl -
Subject digest:
6d5ef7f213181051ac0276d1aef3e10c398e1cb275293187977b7753f2d72007 - Sigstore transparency entry: 764296540
- Sigstore integration time:
-
Permalink:
dhruv13x/pyinitgen@b8068287655fd33459e4ca5ca900bcb4369ff218 -
Branch / Tag:
refs/tags/v4.0.1 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b8068287655fd33459e4ca5ca900bcb4369ff218 -
Trigger Event:
push
-
Statement type: