|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Guide for setting up a local development environment and running tests. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Python 3.12+ |
| 8 | +- [uv](https://docs.astral.sh/uv/) (recommended) or `pip` |
| 9 | + |
| 10 | +## Setup |
| 11 | + |
| 12 | +```bash |
| 13 | +git clone https://github.com/Zipstack/llm-whisperer-python-client.git |
| 14 | +cd llm-whisperer-python-client |
| 15 | + |
| 16 | +# Create a virtual environment and install all dependencies |
| 17 | +uv sync --group dev --group test |
| 18 | + |
| 19 | +# Either prefix commands with `uv run` (used throughout this guide), |
| 20 | +# or activate the venv manually: |
| 21 | +# source .venv/bin/activate # Linux / macOS |
| 22 | +# .venv\Scripts\activate # Windows |
| 23 | +``` |
| 24 | + |
| 25 | +If you prefer pip: |
| 26 | + |
| 27 | +```bash |
| 28 | +python -m venv .venv |
| 29 | +source .venv/bin/activate # On Windows: .venv\Scripts\activate |
| 30 | +pip install -e ".[dev,test]" |
| 31 | +``` |
| 32 | + |
| 33 | +## Environment variables |
| 34 | + |
| 35 | +The project uses [`pytest-dotenv`](https://pypi.org/project/pytest-dotenv/) to auto-load environment variables from a `.env` file in the project root. |
| 36 | + |
| 37 | +```bash |
| 38 | +cp sample.env .env |
| 39 | +``` |
| 40 | + |
| 41 | +Edit `.env` and fill in your API key: |
| 42 | + |
| 43 | +| Variable | Description | Required for | |
| 44 | +|---|---|---| |
| 45 | +| `LLMWHISPERER_BASE_URL_V2` | API base URL (v2) | Integration tests | |
| 46 | +| `LLMWHISPERER_API_KEY` | Your LLMWhisperer API key | Integration tests | |
| 47 | +| `LLMWHISPERER_LOG_LEVEL` | Log level (`DEBUG`, `INFO`, etc.) | Optional | |
| 48 | + |
| 49 | +Unit tests are fully mocked and do **not** require a `.env` file or API key. |
| 50 | + |
| 51 | +## Running tests |
| 52 | + |
| 53 | +### Unit tests (no API key needed) |
| 54 | + |
| 55 | +```bash |
| 56 | +uv run pytest tests/unit/ -v |
| 57 | +``` |
| 58 | + |
| 59 | +### Integration tests (requires valid `.env`) |
| 60 | + |
| 61 | +```bash |
| 62 | +uv run pytest tests/integration/ -v |
| 63 | +``` |
| 64 | + |
| 65 | +### All tests |
| 66 | + |
| 67 | +```bash |
| 68 | +uv run pytest -v |
| 69 | +``` |
| 70 | + |
| 71 | +### Via tox |
| 72 | + |
| 73 | +```bash |
| 74 | +uv run tox |
| 75 | +``` |
| 76 | + |
| 77 | +This runs tests under Python 3.12 using `uv sync --group test` to install dependencies. |
| 78 | + |
| 79 | +### Via poe |
| 80 | + |
| 81 | +```bash |
| 82 | +uv run poe test |
| 83 | +``` |
| 84 | + |
| 85 | +## Linting and formatting |
| 86 | + |
| 87 | +The project uses [ruff](https://docs.astral.sh/ruff/) for linting and formatting (configured in `pyproject.toml`). |
| 88 | + |
| 89 | +```bash |
| 90 | +# Lint |
| 91 | +uv run ruff check src/ tests/ |
| 92 | + |
| 93 | +# Auto-fix lint issues |
| 94 | +uv run ruff check --fix src/ tests/ |
| 95 | + |
| 96 | +# Format |
| 97 | +uv run ruff format src/ tests/ |
| 98 | +``` |
| 99 | + |
| 100 | +## Project structure |
| 101 | + |
| 102 | +``` |
| 103 | +src/unstract/llmwhisperer/ |
| 104 | + __init__.py # Package version |
| 105 | + client_v2.py # Main client (LLMWhispererClientV2) |
| 106 | + utils.py # Utility helpers |
| 107 | +
|
| 108 | +tests/ |
| 109 | + conftest.py # Shared fixtures |
| 110 | + unit/ # Mocked tests (no network calls) |
| 111 | + integration/ # Tests against the live API |
| 112 | + test_data/ # Sample files used by tests |
| 113 | +``` |
0 commit comments