CLI journal project (6/6): package, pyproject, and shipping

Finish pyproject.toml, the journal-stats script entry, the README, tests, and a trial upload to TestPyPI. Twelve exercises before you ship the CLI.

Illustration : carton rempli de cubes de code bien rangés refermé sur un bureau de développeur, image de l'empaquetage d'un projet

AI-generated illustration

Some links on this page are affiliate links. The button opens Amazon so you can check today’s price.

Finish pyproject.toml: a [project] table with name = "journal-stats" (change the name if it is already taken on PyPI), version, requires-python, dependencies, and [project.scripts] so journal-stats = "journal_stats.cli:main". Use a src/journal_stats/ tree for the src layout.

python -m build produces a wheel and an sdist; twine upload dist/* sends them to TestPyPI for a trial. The README documents installation, an example journal-stats analyze a.log b.log, the --async / --no-async options, and --json for machine-readable output.

The packaging lesson is pyproject.toml. Project hub: advanced Python journal CLI.

Exercises (12)

Exercise 1 — A [project.scripts] table for journal-stats. Easy

Show the solution
[project.scripts]
journal-stats = "journal_stats.cli:main"

Exercise 2 — packages = { find = {} } under [tool.setuptools] with where = ["src"]. Intermediate

Show the solution
[tool.setuptools.packages.find]
where = ["src"]

Exercise 3 — pip install -e . then journal-stats --help. Easy

Show the solution
.venv\Scripts\activate ; pip install -e . ; journal-stats --help

Exercise 4 — [project.optional-dependencies]: a dev extra with mypy, pytest, and ruff. Intermediate

Show the solution
[project.optional-dependencies]
dev = ["mypy>=1.8", "pytest>=8", "ruff>=0.3"]

Exercise 5 — python -m build needs the build package. Easy

Show the solution
pip install build

Exercise 6 — twine check dist/* — what it does. Intermediate

Show the solution
Checks the README long description and the metadata.

Exercise 7 — [project.urls] for Home and Repository. Easy

Show the solution
[project.urls]
Homepage = "https://example.org"
Repository = "https://github.com/..."

Exercise 8 — Do not publish secrets from .pypirc — where do you store them? Hard

Show the solution
~/.pypirc outside the repo; CI secret tokens.

Exercise 9 — uvx or pipx install for an isolated CLI — the advantage. Intermediate

Show the solution
One environment per tool, without polluting the system Python.

Exercise 10 — A CHANGELOG.md — the first 0.1.0 entry. Easy

Show the solution
## 0.1.0
- Multi-file analysis, stats by level, optional JSON output.

Exercise 11 — Compare this project with the planner project — a skill that is new here. Easy

Show the solution
A personal answer — asyncio, strict typing, packaging.

Exercise 12 — Keep going toward open-source contributions — a suggestion. Intermediate

Show the solution
Pick a good first issue on a typed Python project.

Wrap-up

You now have the through-line for a complete log tool: generators, decorators, asyncio plus an executor, typing, and a package. Adapt the line format to your real files.

Amazon

Check today’s price on Amazon

Further reading

Was this page helpful?

Have a question about this guide or need advice? Ask us here

Torn between two models or stuck on a build? Drop us a line and we will get back to you by email.