|
| 1 | +# 20260204 Python Repo Practices |
| 2 | + |
| 3 | +- [Setting up a new Python repo](#setting-up-a-new-python-repo) |
| 4 | +- [Examples](#examples) |
| 5 | + - [Basic structure](#basic-structure) |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Setting up a new Python repo |
| 10 | + |
| 11 | + |
| 12 | +0. Create the repository via the Github web UI |
| 13 | + - This allows you to add a README.md, and a .gitignore for Python (super handy!) |
| 14 | + - Add a license if desired (BSD-3-Clause is a good default) |
| 15 | + - Clone the repo to your local machine |
| 16 | + |
| 17 | +1. Install uv on your local machine |
| 18 | + - Follow the instructions at https://docs.astral.sh/uv/#installation |
| 19 | + |
| 20 | +2. Create a `pyproject.toml` file |
| 21 | + - Define some basic dependencies in it |
| 22 | + |
| 23 | +3. Run `uv sync` to create the `uv.lock` file |
| 24 | + |
| 25 | +4. Create your dirs |
| 26 | + |
| 27 | +- `ops/` - for Dockerfiles, CI/CD configs, etc. |
| 28 | +- `test/` - for your unit tests |
| 29 | +- `<your_package_name>/` - for your main package code |
| 30 | + - _make sure it's underscored, not hyphenated_ |
| 31 | + - and matches the name in `pyproject.toml` |
| 32 | + |
| 33 | +5. Add a Dockerfile in `ops/` if desired |
| 34 | + - Copy one of the templates from this repo: https://github.com/astral-sh/uv-docker-example |
| 35 | + |
| 36 | +5. Add a `Makefile` for common tasks |
| 37 | + - e.g., `make build`, `make test`, `make lint`, etc. |
| 38 | + |
| 39 | +6. Make sure there is an `__init__.py` file in |
| 40 | + - the `test/` directory |
| 41 | + - This ensures that the tests can be discovered and run properly |
| 42 | + - the main package directory |
| 43 | + - This ensures that the package is recognized as a module |
| 44 | + |
| 45 | +7. Commit and push your changes to GitHub |
| 46 | + |
| 47 | +## Examples |
| 48 | + |
| 49 | +### Basic structure |
| 50 | + |
| 51 | +An example from one of my projects: |
| 52 | + |
| 53 | +``` |
| 54 | +. |
| 55 | +├── LICENSE |
| 56 | +├── Makefile |
| 57 | +├── README.md |
| 58 | +├── abn_lookup_service |
| 59 | +│ └── lookup.py |
| 60 | +├── ops |
| 61 | +│ ├── Dockerfile |
| 62 | +├── pyproject.toml |
| 63 | +├── test |
| 64 | +│ ├── __init__.py |
| 65 | +│ └── test_lookup.py |
| 66 | +└── uv.lock |
| 67 | +``` |
| 68 | + |
0 commit comments