Package a command-line application
In the TaskFlow capstone you ran a program from its source folder. This guide turns those same files into a wheel, installs it in a fresh environment, and checks that a user can run the taskflow command from another directory.
On this page
Identify the three names
Extract the handbook’s example files. Open python_from_zero/09_projects/72_taskflow_capstone/app in a terminal. Use Python 3.12 or newer. Inside pyproject.toml, find these two project sections. The excerpt shows the fields to inspect.
[project]
name = "taskflow-learning"
version = "1.0.0"
[project.scripts]
taskflow = "taskflow.cli:main"taskflow-learning names the distribution that pip installs. taskflow is the importable package directory. The key under [project.scripts] gives the installed command its name. Its value tells the installer to generate a launcher which imports main from taskflow.cli, calls it, and uses its return value as the process exit status.
Build an installation file
From the app directory, create a build environment. These shell commands use macOS or Linux. On Windows use py -m venv .build-env and substitute .build-env\Scripts\python.exe for .build-env/bin/python.
python3 -m venv .build-env
.build-env/bin/python -m pip install build
.build-env/bin/python -m build --wheel --outdir wheelhousebuild reads [build-system], prepares a build environment with the declared backend, and asks it to create a wheel. Look for wheelhouse/taskflow_learning-1.0.0-py3-none-any.whl. Its filename uses an underscore for the distribution name. Keep the wheel so the next step installs exactly what you built.
Verify the installed command
Create a second environment for the user. Install the wheel by filename, then move into a new empty folder. Running there catches a common packaging mistake where imports succeed only because the source files are nearby. Use .user-env\Scripts\taskflow.exe in place of .user-env/bin/taskflow on Windows.
python3 -m venv .user-env
.user-env/bin/python -m pip install wheelhouse/taskflow_learning-1.0.0-py3-none-any.whl
mkdir wheel-check
cd wheel-check
../.user-env/bin/taskflow --data check.json add "Review wheel"
../.user-env/bin/taskflow --data check.json list --jsonThe first command against the new data file prints Added task 1.. The second returns a JSON array containing a task with ID 1, title Review wheel, and done set to false. A successful import alone would leave the installed command and its argument handling unchecked.