|
| 1 | +# Contributor Guidelines |
| 2 | + |
| 3 | +Welcome! This guide helps you set up the project locally for development and contributions. It also explains the coding standards used in the project along with the CI checks |
| 4 | + |
| 5 | +## Local Setup |
| 6 | + |
| 7 | +This project uses **uv** for Python packaging and virtual environments. Python is pinned to **3.12.10** in `pyproject.toml`. |
| 8 | + |
| 9 | + |
| 10 | +### Step 1: Clone the Repository |
| 11 | +Clone the repository and navigate to the project directory. |
| 12 | + |
| 13 | +```bash |
| 14 | +cd RAG-Module |
| 15 | +``` |
| 16 | + |
| 17 | +### Step 2: Install uv |
| 18 | +If uv is not already installed, install it via the official installer. |
| 19 | + |
| 20 | +```bash |
| 21 | +curl -LsSf https://astral.sh/uv/install.sh | sh |
| 22 | +# Restart your terminal or run: source ~/.zshrc |
| 23 | +``` |
| 24 | + |
| 25 | +### Step 3: Install the Required Python Version |
| 26 | +Use uv to install and manage Python 3.12.10. |
| 27 | + |
| 28 | +```bash |
| 29 | +uv python install 3.12.10 |
| 30 | +``` |
| 31 | + |
| 32 | +### Step 4: Recreate the Virtual Environment |
| 33 | +From the project root (where `pyproject.toml` and `uv.lock` are located), recreate the environment from the lockfile. |
| 34 | + |
| 35 | +```bash |
| 36 | +# Create .venv and install dependencies strictly from uv.lock |
| 37 | +uv sync --frozen |
| 38 | +``` |
| 39 | + |
| 40 | +**Notes:** |
| 41 | +- `uv sync` creates a local `.venv/` directory by default and installs dependencies from `uv.lock`. |
| 42 | +- If `--frozen` fails due to a stale lockfile, run `uv sync -p 3.12.10` (without `--frozen`) to resolve and update. |
| 43 | + |
| 44 | +### Step 5: Activate the Environment (Optional) |
| 45 | +Activate the virtual environment to use it directly. |
| 46 | + |
| 47 | +```bash |
| 48 | +source .venv/bin/activate |
| 49 | +python -V # Should output: Python 3.12.10 |
| 50 | +``` |
| 51 | + |
| 52 | +### Step 6: Run the Application |
| 53 | + |
| 54 | +When running the FastAPI APIs locally always run with |
| 55 | + |
| 56 | +```bash |
| 57 | +uv run python app.py |
| 58 | +``` |
| 59 | + |
| 60 | +instead of |
| 61 | + |
| 62 | +```bash |
| 63 | +python3 app.py |
| 64 | +``` |
| 65 | + |
| 66 | +This will make sure that regardless of whether you have activated the .venv environment or not uv will use the right versions when setting up the |
| 67 | + |
| 68 | + |
| 69 | +For more help, check the [uv documentation](https://docs.astral.sh/uv/) |
| 70 | + |
| 71 | +## CI Checks |
| 72 | + |
| 73 | +### Environment Check |
| 74 | + |
| 75 | +- Located in `.github/workflows/uv-env-check.yml` |
| 76 | + |
| 77 | +- This GitHub actions check runs to check whether there are any conflicts between the lockfile and pyproject.toml. If it fails, then there has been some dependency update to the pyproject.toml without updating the lockfile |
| 78 | + |
| 79 | +### Type check for Python |
| 80 | + |
| 81 | +## Installing New Dependencies to the Project (Python) |
| 82 | + |
| 83 | +If you need to add a new Python dependency, **do not run `pip install` directly**. |
| 84 | + |
| 85 | +We use `uv` to manage environments and lockfiles so that installs are reproducible in local development, CI, and containers. |
| 86 | + |
| 87 | +### Follow This Process: |
| 88 | + |
| 89 | +#### 1. Add the Dependency |
| 90 | +Use `uv add` instead of `pip install`. This ensures both `pyproject.toml` and `uv.lock` are updated together. |
| 91 | + |
| 92 | +```bash |
| 93 | +uv add "package-name>=x.y,<x.(y+1)" |
| 94 | +``` |
| 95 | + |
| 96 | +- Use a bounded version range (`>=` + `<`) to avoid uncontrolled upgrades. |
| 97 | + |
| 98 | + |
| 99 | +#### 2. Re-sync Your Environment |
| 100 | +After adding, re-sync to refresh your local `.venv`: |
| 101 | + |
| 102 | +```bash |
| 103 | +uv sync --reinstall |
| 104 | +``` |
| 105 | + |
| 106 | +#### 3. Run Checks Locally |
| 107 | +Make sure type checks, linter, and tests pass: |
| 108 | + |
| 109 | +```bash |
| 110 | +uv run pyright |
| 111 | +uv run ruff check . |
| 112 | +uv run pytest |
| 113 | +``` |
| 114 | + |
| 115 | +#### 4. Commit Both Files |
| 116 | +Always commit both `pyproject.toml` and `uv.lock`. If only one is updated, CI will fail (`uv sync --frozen` check). |
| 117 | + |
| 118 | +```bash |
| 119 | +git add pyproject.toml uv.lock |
| 120 | +git commit -m "added package-name dependency" |
| 121 | +``` |
| 122 | + |
| 123 | +#### 5. Open a PR |
| 124 | +CI will validate that the lockfile and environment are consistent. If you forgot to update the lockfile, the PR will fail with a clear error. |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +### Important Notes |
| 129 | + |
| 130 | +- **Never edit `uv.lock` manually.** It is controlled by `uv`. |
| 131 | +- **Never use `uv pip install` for permanent deps** — it only changes your local venv. Use `uv add` instead. |
| 132 | +- If you remove a dependency, run: |
| 133 | + |
| 134 | +```bash |
| 135 | +uv remove package-name |
| 136 | +uv sync --reinstall |
| 137 | +git add pyproject.toml uv.lock |
| 138 | +git commit -m "removed package-name" |
| 139 | +``` |
| 140 | + |
| 141 | +## Coding Standards |
| 142 | + |
| 143 | +## PR evaluation criteria |
0 commit comments