-
Install uv if you haven't.
-
Setup and activate the Python virtual environment for this project:
uv init
uv run main.py
source .venv/bin/activateYou can exit the virtual environment by running deactivate.
Steps for using this template:
- Replace
todo_pkg_nameacross the project to your package name (based on the project name).
- Only lower case letters, numbers, and
_(not recommended) are allowed in the package name; do NOT use other symbols. - Prefer concise names and acronyms, e.g.,
tecoinstead oftest_completion. - Don't forget to rename the
src/todo_pkg_namedirectory.
-
Replace other
TODOs inpyproject.tomlandREADME.md, this can be done as you go along the project. -
Test out your environment. Follow the Environment Setup instructions, and then...
- Run
python -m todo_pkg_name.example_main --helpand see if the code runs (it should work from anywhere) - Run
pytestto see the tests running (it must be run from the project root/or under/tests)
-
Notes about bundled dependencies:
seutilis a util library. There are some examples to use it inexample_main.py.- In particular,
jsonargparse, which is transitively installed byseutil, helps to parse command line arguments. Use it to read paths to inputs/outputs from command line, and avoid hardcoding them in code.
- In particular,
ruffis code formatter + linter. Run it periodically to improve your code quality.- Format code:
uv run ruff format . - Lint code:
uv run ruff check .(use--fixto auto-fix safe issues) - VS Code: install
charliermarsh.ruffplugin; suggestions should show up in the editor
- Format code:
tyis static type checker (currently in beta; rules and diagnostics may evolve).- Type check:
uv run ty check
- Type check:
-
Start developing your code.
- If you need to add new dependencies, add them with
uv add <package_name>; you may need to runuv syncto synchronize the virtual environment if you work on multiple machines. Details see uv documentation. - Follow formatting conventions:
uv run ruff format . - Follow linting rules:
uv run ruff check . - Write type hints and check with
uv run ty check. - Write docstrings and tests.
- Update this README as you work on the project, e.g., update summaries, add usage instructions, etc.
Reference: pengyunie/python-template