- Install
hatch
:
$ pipx install hatch
# or
$ brew install hatch
- Create new project:
$ hatch new "Hatch Demo"
$ cd hatch-demo
- Create default environment:
$ hatch env create
- Set
uv
as the default installer by adding this topyproject.toml
:
[tool.hatch.envs.default]
installer = "uv"
- Add dependencies (
requests
,polars
,pytest
,ruff
)- Note 1: I didn't see a way to add deps via
hatch
command, so this was manually done by editingpyproject.toml
. (This seems to be the procedure described in their docs.) - Note 2: Add
pytest
andruff
under thedev
environment.
- Note 1: I didn't see a way to add deps via
[tool.hatch.envs.default]
installer = "uv"
dependencies = ["polars", "requests"]
[tool.hatch.envs.dev]
installer = "uv"
dependencies = [
"hatch-demo",
"pytest",
"ruff"
]
Note: You have to reference hatch-demo
in order to get the project deps needed for running tests.
- Add
test
andlint
scripts todev
env:
[tool.hatch.envs.dev.scripts]
test = "pytest"
lint = "ruff check --fix && ruff format"
- Create/install the env:
$ hatch env create dev
-
Add code (
demo.py
) and tests (test_demo.py
). -
Check envs:
$ hatch env show
Standalone
┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Name ┃ Type ┃ Dependencies ┃ Scripts ┃
┡━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ default │ virtual │ polars │ run │
│ │ │ requests │ │
├─────────┼─────────┼──────────────┼─────────┤
│ dev │ virtual │ pytest │ lint │
│ │ │ ruff │ run │
│ │ │ │ test │
└─────────┴─────────┴──────────────┴─────────┘
- Run tests and lint/format code:
$ hatch run dev:test
$ hatch run dev:lint
- Add default script to run the app:
[tool.hatch.envs.default.scripts]
run = "python src/hatch_demo/demo.py"
- Run the app:
$ hatch run default:run
- Add hatch-based GH workflow to check linting and run tests.
Not sure how to install the project so that it can called likepython -m hatch_demo
- You can run it from the
hatch
env like:hatch run dev:python -m hatch_demo
- You can install it from source and call it:
$ uv venv $ uv pip install . $ source .venv/bin/activate $ python -m hatch_demo
- You can run it from the
- Not sure how to call the entrypoint scripts