Module 1: Set up the project
Goal
By the end of this module you have a Python project that:
- installs a
dupcheckcommand, - runs tests with one command,
- can make the same synthetic NACHA file every time.
The concept
uv runs everything. uv manages Python, the virtual environment and the
dependencies. You never call python or pip directly. You type uv run ...
and uv makes sure the right environment is used.
The src/ layout. The code lives in src/echo_check/, not in the project
root. This means tests can only import the package once it is properly
installed. If packaging breaks, the tests catch it right away.
Entry points. One line in pyproject.toml turns a Python function into a
command:
[project.scripts]
dupcheck = "echo_check.cli:main"
When uv installs the project, it creates a dupcheck command that calls
main() in echo_check/cli.py.
Synthetic data with a seed. The generator makes fake NACHA files with
duplicates planted on purpose. It also writes an answer key that lists where
each duplicate is. The same seed always gives the same file, so data/sample.ach
(seed 42) is a fixed test case.
Code walkthrough
pyproject.tomllists the dependencies, thedupcheckentry point and the build backend (uv_build). The build backend is what makes the package installable.src/echo_check/__init__.pymarks the folder as a package and holds the version number.src/echo_check/cli.pyhas a stubmain(). For now it only prints a message.tests/test_smoke.pychecks that the package imports and that thedupcheckcommand runs.tests/test_generator.pyruns the generator with seed 42 in a temporary folder and compares the result to the committed sample byte for byte..gitignoreignores everything underdata/except the two sample files, so generated data never ends up in Git by accident.
Try it:
uv sync
uv run pytest
uv run dupcheck
uv run python generator/generate_nacha.py --out data/sample --seed 42
Exercise
Generate a bigger file with a different seed:
uv run python generator/generate_nacha.py --out data/big --seed 7 --batches 20 --entries 50
Open data/big.answers.json and find one near_amount duplicate. Look up both
lines in data/big.ach. How far apart are the two amounts?
Then run git status. Why doesn't data/big.ach show up?
What can go wrong
dupcheckis not found. The project isn't installed. Runuv sync, and check that[build-system]is inpyproject.toml.- A warning says
VIRTUAL_ENVdoesn't match. Your terminal has a different project's environment active. uv ignores it and uses this project's.venv, so you can ignore the warning, or rundeactivatefirst. - The generator test fails. Someone changed the generator, so seed 42 no
longer gives the committed sample. If the change was on purpose, regenerate
data/sample.*and commit it together with the change. - pytest says "no tests ran" (exit code 5). pytest treats zero tests as a failure. That's why this module starts with smoke tests.