Some checks failed
CI (tests + ruff) and stable tag / unittest (py3.10) (push) Has been cancelled
CI (tests + ruff) and stable tag / unittest (py3.11) (push) Has been cancelled
CI (tests + ruff) and stable tag / unittest (py3.12) (push) Has been cancelled
CI (tests + ruff) and stable tag / unittest (py3.13) (push) Has been cancelled
CI (tests + ruff) and stable tag / ruff (py3.12) (push) Has been cancelled
CI (tests + ruff) and stable tag / Tag stable (if version commit) (push) Has been cancelled
https://chatgpt.com/share/69468609-0584-800f-a3e0-9d58210fb0e8
62 lines
1.1 KiB
Markdown
62 lines
1.1 KiB
Markdown
# p2pkg
|
|
|
|
A small, purpose-built repository for a very specific migration:
|
|
|
|
- `foo.py` ➜ `foo/__main__.py`
|
|
- Generates `foo/__init__.py` that re-exports the public API from `__main__`
|
|
so existing code like `import foo` or `from foo import some_function` keeps working.
|
|
- Keeps the original module code *as-is* in `__main__.py` (one-off refactor helper).
|
|
|
|
## Install (editable)
|
|
|
|
```bash
|
|
python -m venv .venv
|
|
. .venv/bin/activate
|
|
pip install -e .
|
|
```
|
|
|
|
## Usage
|
|
|
|
```bash
|
|
# Migrate one or more flat modules into packages
|
|
p2pkg roles_list.py another_module.py
|
|
|
|
# Or run directly
|
|
python tools/p2pkg.py roles_list.py
|
|
```
|
|
|
|
### Behavior
|
|
|
|
Given `roles_list.py`:
|
|
|
|
```
|
|
roles_list.py
|
|
```
|
|
|
|
After migration:
|
|
|
|
```
|
|
roles_list/
|
|
├── __init__.py # re-exports public API from __main__
|
|
└── __main__.py # contains the original implementation (moved)
|
|
```
|
|
|
|
- Running `python -m roles_list` executes `roles_list/__main__.py`.
|
|
- Existing imports remain compatible (via re-exports in `__init__.py`).
|
|
|
|
## Development
|
|
|
|
Run tests:
|
|
|
|
```bash
|
|
make test
|
|
```
|
|
|
|
## License
|
|
|
|
MIT License. See `LICENSE`.
|
|
|
|
---
|
|
|
|
Author: Kevin Veen-Birkenbach
|