Skip to content

Latest commit

 

History

History
112 lines (90 loc) · 2.98 KB

README.md

File metadata and controls

112 lines (90 loc) · 2.98 KB

Hatch Demo

Steps

  1. Install hatch:
$ pipx install hatch
# or 
$ brew install hatch
  1. Create new project:
$ hatch new "Hatch Demo"
$ cd hatch-demo
  1. Create default environment:
$ hatch env create
  1. Set uv as the default installer by adding this to pyproject.toml:
[tool.hatch.envs.default]
installer = "uv"
  1. 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 editing pyproject.toml. (This seems to be the procedure described in their docs.)
    • Note 2: Add pytest and ruff under the dev environment.
[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.

  1. Add test and lint scripts to dev env:
[tool.hatch.envs.dev.scripts]
test = "pytest"
lint = "ruff check --fix && ruff format"
  1. Create/install the env:
$ hatch env create dev
  1. Add code (demo.py) and tests (test_demo.py).

  2. Check envs:

$ hatch env show
                  Standalone                  
┏━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Name    ┃ Type    ┃ Dependencies ┃ Scripts ┃
┡━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ default │ virtual │ polars       │ run     │
│         │         │ requests     │         │
├─────────┼─────────┼──────────────┼─────────┤
│ dev     │ virtual │ pytest       │ lint    │
│         │         │ ruff         │ run     │
│         │         │              │ test    │
└─────────┴─────────┴──────────────┴─────────┘
  1. Run tests and lint/format code:
$ hatch run dev:test
$ hatch run dev:lint
  1. Add default script to run the app:
[tool.hatch.envs.default.scripts]
run = "python src/hatch_demo/demo.py"
  1. Run the app:
$ hatch run default:run
  1. Add hatch-based GH workflow to check linting and run tests.

Notes

  • Not sure how to install the project so that it can called like python -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
  • Not sure how to call the entrypoint scripts