diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 08567f6..ff9c81d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -18,7 +18,10 @@ jobs: with: python-version: '3.12' - - name: Install Hatch - run: pip install --upgrade hatch + - name: Install uv + uses: astral-sh/setup-uv@v5 - - run: hatch run mkdocs gh-deploy --force + - name: Sync dependencies + run: uv sync --extra dev + + - run: uv run mkdocs gh-deploy --force diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37cc1ef..a86f8f3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,16 +60,15 @@ jobs: git tag "v${VERSION}" git push origin "v${VERSION}" - - name: Install Hatch - run: pip install hatch + - name: Install uv + uses: astral-sh/setup-uv@v5 - name: Publish on PyPi env: - HATCH_INDEX_USER: __token__ - HATCH_INDEX_AUTH: ${{ secrets.PYPI_API_TOKEN }} + UV_PUBLISH_TOKEN: ${{ secrets.PYPI_API_TOKEN }} run: | - hatch build - hatch publish -y + uv build + uv publish - name: Create GitHub Release uses: ncipollo/release-action@v1 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 02b7b21..49b402e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -44,22 +44,18 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install Hatch - run: pip install --upgrade hatch + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Sync dependencies + run: uv sync --extra dev - if: matrix.python-version == '3.13' name: Lint - run: hatch run lint:all + run: uv run ruff format --check && uv run ruff check . && uv run mypy --install-types --non-interactive src/banks && uv run pylint src/banks - name: Run tests - run: hatch run cov -m"not e2e" - - - if: matrix.python-version == '3.13' - name: End-to-end - env: - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} - run: hatch run test -m"e2e" + run: uv run pytest --cov --cov-report=xml -m"not e2e" tests - if: matrix.python-version == '3.13' name: Report Coveralls @@ -82,11 +78,14 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install Hatch - run: pip install --upgrade hatch + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Sync dependencies + run: uv sync --extra dev - name: Run tests - run: hatch run test -m"not e2e" + run: uv run pytest -m"not e2e" tests windows: name: Python ${{ matrix.python-version }} on Windows @@ -105,8 +104,11 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Install Hatch - run: pip install --upgrade hatch + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: Sync dependencies + run: uv sync --extra dev - name: Run tests - run: hatch run test -m"not e2e" + run: uv run pytest -m"not e2e" tests diff --git a/AGENTS.md b/AGENTS.md index dd94b8d..65a6b8a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -10,36 +10,39 @@ Banks is a Python prompt programming language and templating system for LLM appl ```bash # Most common commands -hatch run test # Run unit tests -hatch run lint:all # Run all linting checks -hatch run lint:fmt # Auto-format code -hatch run test tests/test_foo.py # Run specific test file +uv run pytest tests # Run unit tests +uv run ruff format --check && uv run ruff check . && uv run mypy --install-types --non-interactive src/banks && uv run pylint src/banks # Run all linting checks +uv run ruff format # Auto-format code +uv run pytest tests/test_foo.py # Run specific test file ``` ## Development Commands +### Setup +- Install dev dependencies: `uv sync --extra dev` + ### Testing -- Run tests: `hatch run test` -- Run tests with coverage: `hatch run test-cov` -- Generate coverage report: `hatch run cov` -- Run specific test file: `hatch run test tests/test_foo.py` -- Run e2e tests: `hatch run test tests/e2e/` (requires API keys) +- Run tests: `uv run pytest tests` +- Run tests with coverage: `uv run pytest --cov --cov-report=xml tests` +- Generate coverage report: `uv run pytest --cov --cov-report=xml tests && uv run coverage combine && uv run coverage report -m` +- Run specific test file: `uv run pytest tests/test_foo.py` +- Run e2e tests: `uv run pytest tests/e2e/` (requires API keys) ### Linting and Type Checking -- Format code: `hatch run lint:fmt` -- Auto-fix lint issues: `hatch run lint:fix` -- Check formatting: `hatch run lint:check` -- Run type checking: `hatch run lint:typing` -- Run pylint: `hatch run lint:lint` -- Run all lint checks: `hatch run lint:all` +- Format code: `uv run ruff format` +- Auto-fix lint issues: `uv run ruff check --fix` +- Check formatting: `uv run ruff format --check && uv run ruff check .` +- Run type checking: `uv run mypy --install-types --non-interactive src/banks` +- Run pylint: `uv run pylint src/banks` +- Run all lint checks: `uv run ruff format --check && uv run ruff check . && uv run mypy --install-types --non-interactive src/banks && uv run pylint src/banks` ### Documentation -- Build docs: `hatch run docs build` -- Serve docs locally: `hatch run docs serve` (available at http://127.0.0.1:8000/) +- Build docs: `uv run mkdocs build` +- Serve docs locally: `uv run mkdocs serve` (available at http://127.0.0.1:8000/) ### Environment Management -- All commands use Hatch environments with automatic dependency management -- Uses `uv` as the installer for faster dependency resolution +- Uses `uv` for dependency management and running tools +- Install all dev dependencies: `uv sync --extra dev` - Python 3.9+ supported (tested on 3.10-3.14) ## Architecture Overview @@ -157,9 +160,9 @@ hatch run test tests/test_foo.py # Run specific test file ### Running Specific Tests ```bash -hatch run test tests/test_image.py # Single file -hatch run test tests/test_image.py::test_name # Single test -hatch run test -k "image" # Tests matching pattern +uv run pytest tests/test_image.py # Single file +uv run pytest tests/test_image.py::test_name # Single test +uv run pytest -k "image" # Tests matching pattern ``` ## Code Style diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index f0ce80a..263a427 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,35 +11,32 @@ be very happy about: - Refer this project in your project's readme - Mention the project at local meetups and tell your friends/colleagues -## Install Hatch +## Setup -Assuming you already have Python installed and it's at least on version 3.10, the first step is to install -[Hatch](https://hatch.pypa.io/1.9/). We'll use Hatch to manage the virtual environments that are needed to build the -project, the documentation and to run the tests. Depending on your operating system, there are different ways to -install Hatch: +Assuming you already have Python installed (version 3.10 or later), the recommended way to work on this project is +with [uv](https://docs.astral.sh/uv/). Install `uv` following the +[official instructions](https://docs.astral.sh/uv/getting-started/installation/), then install all development +dependencies with: -- `brew install hatch` on Mac -- The [GUI installer](https://hatch.pypa.io/1.9/install/#gui-installer_1) on Windows -- Or just `pip install hatch` - -The [official documentation for Hatch](https://hatch.pypa.io/1.9/install/) contains a thorough description of all the -available installation methods. +```sh +$ uv sync --extra dev +``` ## Run the tests -With Hatch installed, from the root of the repository running the tests is as simple as: +With `uv` installed, from the root of the repository running the tests is as simple as: ```sh -$ hatch run test +$ uv run pytest tests ``` -This command will activate the proper virtual environment, sync the required dependencies and invoke +This command will use the virtual environment managed by `uv`, sync the required dependencies and invoke [pytest](https://docs.pytest.org/en/stable/index.html). To see a recap of the test coverage and specifically which are the lines that are currently not tested, you can run: ```sh -$ hatch run cov +$ uv run pytest --cov --cov-report=xml tests && uv run coverage combine && uv run coverage report -m ``` ## Lint the code @@ -51,7 +48,13 @@ and used consistently across the codebase. To perform a comprehensive lint check just run: ```sh -$ hatch run lint:all +$ uv run ruff format --check && uv run ruff check . && uv run mypy --install-types --non-interactive src/banks && uv run pylint src/banks +``` + +To auto-format the code: + +```sh +$ uv run ruff format ``` > [!IMPORTANT] @@ -64,7 +67,7 @@ Any contribution to the documentation is very welcome, whether it's a fix for a new recipe in the cookbook. To preview the documentation locally, you can run: ```sh -$ hatch run docs serve +$ uv run mkdocs serve ``` and open the browser at the URL `http://127.0.0.1:8000/`. The documentation is built with diff --git a/README.md b/README.md index 5219a8a..f215c04 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ [![test](https://github.com/masci/banks/actions/workflows/test.yml/badge.svg)](https://github.com/masci/banks/actions/workflows/test.yml) [![docs](https://github.com/masci/banks/actions/workflows/docs.yml/badge.svg)](https://github.com/masci/banks/actions/workflows/docs.yml) -[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch) [![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) [![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/) [![License - MIT](https://img.shields.io/badge/license-MIT-9400d3.svg)](https://spdx.org/licenses/) diff --git a/pyproject.toml b/pyproject.toml index a6739c3..d8e04f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,18 +35,7 @@ dependencies = [ [project.optional-dependencies] all = ["litellm", "redis"] - -[project.urls] -Documentation = "https://github.com/masci/banks#readme" -Issues = "https://github.com/masci/banks/issues" -Source = "https://github.com/masci/banks" - -[tool.hatch.version] -path = "src/banks/__about__.py" - -[tool.hatch.envs.default] -installer = "uv" -dependencies = [ +dev = [ "coverage[toml]>=6.5", "pytest", "pytest-cov", @@ -54,32 +43,21 @@ dependencies = [ "mkdocs-material", "mkdocstrings[python]", "simplemma", - "eval-type-backport;python_version<'3.10'", + "redis", "litellm", + "mypy>=1.0.0", + "ruff>=0.0.243", + "pylint", ] -[tool.hatch.envs.default.scripts] -test = "pytest {args:tests}" -test-cov = "pytest --cov --cov-report=xml {args:tests}" -cov-report = ["- coverage combine", "coverage report -m"] -cov = ["test-cov", "cov-report"] -docs = "mkdocs {args:build}" - -[[tool.hatch.envs.all.matrix]] -python = ["3.10", "3.11", "3.12", "3.13", "3.14"] - -[tool.hatch.envs.lint] -detached = false # Normally the linting env can be detached, but mypy doesn't install all the stubs we need -dependencies = ["mypy>=1.0.0", "ruff>=0.0.243", "pylint", "redis", "litellm"] - -[tool.hatch.envs.lint.scripts] -check = ["ruff format --check {args}", "ruff check {args:.}"] -lint = "pylint {args:src/banks}" -typing = "mypy --install-types --non-interactive {args:src/banks}" -all = ["check", "typing", "lint"] -fmt = "ruff format {args}" -fix = "ruff check --fix {args}" +[project.urls] +Documentation = "https://github.com/masci/banks#readme" +Issues = "https://github.com/masci/banks/issues" +Source = "https://github.com/masci/banks" + +[tool.hatch.version] +path = "src/banks/__about__.py" [tool.hatch.build.targets.wheel] only-include = ["src/banks", "src/templates"]