Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 5 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 19 additions & 17 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
47 changes: 25 additions & 22 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
37 changes: 20 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
46 changes: 12 additions & 34 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,51 +35,29 @@ 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",
"pytest-asyncio",
"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"]
Expand Down
Loading