pyproject.toml describes project and build metadata. A wheel is an installable distribution, and a console entry point maps a command to a Python callable.
Connect metadata, package contents and command execution, then test the built package outside the source tree.
The source code passes its tests, but a fresh installation cannot run quarry. A release has several boundaries: source files become a wheel, the wheel becomes an installation, and an entry point calls a function. We will follow those boundaries and test the artifact a user actually receives.

Check the metadata before a release
Every modern project has one pyproject.toml at its root:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "quarry"
version = "0.5.0"
requires-python = ">=3.11"
dependencies = ["chardet>=5,<6", "rich~=13.7"]
[project.scripts]
quarry = "quarry.cli:main"Three tables, three jobs: [build-system] says which tool builds the
project — pip never builds anything itself, it installs the named backend
into a throwaway environment and asks it for a wheel. [project] is
metadata every tool agrees on, dependencies included — loose ranges, as a
library should have; lesson 2's lock file pins them for Quarry's own
deployment, but the metadata stays honest ranges. [project.scripts]
declares commands. The file is TOML, and it's typed:
That typing bites people who write versions the way they say them out loud:
import tomllib
print(tomllib.loads("version = 1.10")["version"])Preparing this topic’s interactive investigation…
Build quarry-0.5.0-py3-none-any.whl
A wheel is a zip archive: your package folders exactly as they'll sit in
site-packages, plus one <name>-<version>.dist-info folder of metadata.
You build one with the standard front-end — python -m build — which hands
your source tree to the backend and writes two files into dist/: the
sdist (.tar.gz, source plus metadata) and the wheel, ready to
install:
Nothing about a wheel is hidden — it's a zip file, and zipfile can make
one:
A real wheel adds WHEEL (format version and platform tag) and RECORD (a
hash and size per file, so the installer can verify and later remove exactly
what it unpacked). py3-none-any describes a pure-Python, platform-independent wheel tag —
Quarry needs one wheel total; compiled code may require several platform/ABI wheels; stable-ABI builds
can sometimes support several Python versions.
In a src layout, the package lives at src/quarry/, which isn't on
sys.path by accident — ordinary imports from the repository root then require an installation or
an explicitly configured search path, which
during development means an editable install (pip install -e .): the
installed copy points back at src/, so edits show up without reinstalling,
and tests resolve the installed development package. A separate wheel-install
test is still needed to check what actually ships.
Wire quarry.cli:main to the quarry command
[project.scripts] maps a command name to an object reference: a
module imported by its dotted name, then an attribute looked up on it. On
install, pip writes a tiny executable whose entire job is from quarry.cli import main; sys.exit(main()). Two consequences follow from lesson 1:
quarry.cli is imported, so its relative imports work and its own main
guard does not run — the wrapper calls main() itself — and main takes no
arguments and communicates through its return value, which goes straight
to sys.exit:
def main():
rows = ["a", "b"]
total = len(rows)
try:
raise SystemExit(main())
except SystemExit as exc:
print(exc.code)Resolving the reference is a short walk — import, then follow each dotted
attribute with getattr:
The common mistake is writing the reference like a path, with a dot where the colon belongs:
ValueErrorThis entry point would install a quarry command that crashes the moment it starts. Fix the TOML, not the loop.
The same machinery serves plugins: any [project.entry-points."quarry.stages"]
table becomes a group in the wheel's entry_points.txt, and at run time
importlib.metadata.entry_points(group="quarry.stages") lists what every
installed package declared — so a stage from someone else's package can join
Quarry's registry without Quarry importing it by name.
Test the artifact from outside the source tree
Three objects are easy to confuse: the source tree you edit, the wheel you build, and the installed package a user imports. A test against the first does not prove the second contains every module or data file. An editable install can expose source files that were omitted from the built artifact.
A local release rehearsal therefore has a different boundary from an ordinary unit test:
- Build a wheel from the intended source revision.
- Create a fresh environment using a supported Python version.
- Install that wheel, not
-e .. - Move outside the repository, import the package, and run the installed command.
- Exercise a path that needs a packaged data file or submodule, not only
--help.
If importing works but the command is missing, inspect [project.scripts] and the environment's script directory. If the command starts but cannot import a submodule, inspect wheel contents and package discovery. If it imports the wrong source tree, inspect module.__file__. These observations distinguish packaging errors from application errors.
A py3-none-any tag describes Python/ABI/platform compatibility at the wheel-tag level. It does not override Requires-Python, missing external programs, operating-system assumptions, or a dependency's own support range. Likewise, a hand-built teaching wheel is useful for understanding metadata but is not a replacement for a maintained build backend.
Transfer: add a template file that is read only by a report command. Predict why a test run from the repository may pass even if the template is absent from the wheel. Add a fresh-install check that would fail in that case, and explain why formatting or type checking would not catch it.
References: project metadata and src versus flat layouts.
Traps worth knowing
A version number publishes once. You can yank a broken release so
resolvers skip it, but you cannot replace 0.5.0 with different files — so
the release routine is bump, build, install the wheel into a fresh
environment, test it, then upload, and most teams let CI do all of it on a
tag. Pure Python is cheap to ship. Six platforms times four supported
Pythons is 24 wheels per release for compiled code, each built and tested on
its own machine; a py3-none-any wheel is one file for all of them — a real
reason to stay pure Python until measurements say otherwise.
Quick practice
try:
raise SystemExit("disk full")
except SystemExit as exc:
print(exc.code, isinstance(exc.code, str))import tomllib
print(tomllib.loads('deps = ["a", "b"]')["deps"], type(tomllib.loads("n = 3")["n"]).__name__)ValueErrorRun it, read the ValueError, then fix ref so it has a module and an attribute separated by a colon.
🎯 Your turn
Build check_pyproject(text) — the last piece of Quarry's shipment, run
before every release. Parse the text with tomllib and return the problems
in this order (an empty list means ready to build):
"invalid TOML"on its own, if it won't parse;"missing build-system.build-backend";"missing [project]"— and stop there;"missing project.name"or"invalid project.name"(letters, digits,.,_,-, starting and ending with a letter or digit);"project.version must be a string", or"missing project.version"unless"version"is listed inproject.dynamic;"bad entry point: <command>"for each script, in sorted order, whose value isn'tdotted.module:dotted.attr.
check_pyproject('''
[build-system]
build-backend = "hatchling.build"
[project]
name = "quarry"
version = 0.5
[project.scripts]
quarry = "quarry/cli.py:main"
''')
# → ["project.version must be a string", "bad entry point: quarry"]Press ▶ Run and hit ✓ Check. ✅
Practice — level up
0/6 solvedSolve each in its own editor — Run to try, Check to grade. Stuck? Reveal a Hint, or the full Solution + walkthrough.
An entry point names a function as module:attribute, like "quarry.cli:main". Write split_ref(ref) returning [module, attribute], or [] when there isn't exactly one : with something on both sides.
A built wheel's file name is {name}-{version}-{tag}.whl, where the name is lower-cased and every run of -, _ or . becomes a single _ (a dash would be read as the separator). Write wheel_name(name, version, tag). Example: wheel_name("Quarry-Tools", "1.2.0", "py3-none-any") → "quarry_tools-1.2.0-py3-none-any.whl".
Inside every wheel is an entry_points.txt that installers read to create commands and that importlib.metadata.entry_points() reads to find plugins. Write entry_points_txt(text): parse the pyproject.toml text with tomllib and build that file. [project.scripts] becomes group console_scripts, [project.gui-scripts] becomes gui_scripts, and each [project.entry-points.<group>] table becomes that group. Write groups in sorted order, each as a [group] line then one name = ref line per entry in sorted order, with a blank line between groups. No entry points at all gives "".
When pip installs Quarry it writes a tiny quarry program that imports quarry.cli, fetches main, and exits with sys.exit(main()). Write run_script(sources, ref, argv) that does the same: sources maps module names to source text. Build the module named in ref as a real module object (types.ModuleType with its dotted name, not __main__) and run its source in it; walk the attribute path after the colon with getattr; call it with sys.argv temporarily set to ["quarry"] + argv. Turn the outcome into an exit status the way sys.exit does: None → 0, an int → itself, anything else → 1; a SystemExit raised inside counts the same way, using its code. Return {"exit": status}, or {"error": "ModuleNotFoundError"} / {"error": "AttributeError"} if the module or the attribute isn't there. Restore sys.argv afterwards.
Build a real wheel, in memory. files maps paths in a src layout project to their text: src/quarry/__init__.py, tests/test_cli.py, README.md and so on. Write build_wheel(pyproject, files):
- read
nameandversionfrom thepyprojecttext; the distribution name is the name lower-cased with runs of-_.turned into_; - the wheel is
{dist}-{version}-py3-none-any.whl; - include every
.pyfile undersrc/<pkg>/wheresrc/<pkg>/__init__.pyexists, stored without thesrc/prefix; nothing else from the project goes in; - add
{dist}-{version}.dist-info/holdingMETADATA(at leastMetadata-Version,NameandVersionlines),WHEEL,RECORD, andentry_points.txtonly if there are[project.scripts]; - write it all into a
zipfile.ZipFileover anio.BytesIO.
Return {"wheel": <file name>, "files": <sorted names in the zip>, "hashes": {<each package .py path in the wheel>: "sha256=<digest>"}}, where the digest is the file's UTF-8 bytes hashed with SHA-256 and encoded with base64.urlsafe_b64encode, = padding stripped — the form RECORD uses.
Quarry's tests pass on your machine, you publish 0.5.0, and the first user's quarry run dies with ModuleNotFoundError: No module named 'quarry.stages'. The project used a flat layout — quarry/ next to tests/ and pyproject.toml — and the new stages/ folder had no __init__.py. Explain how the tests could pass while the installed package was broken, and how a src/ layout plus testing against an installed copy would have caught it.