Python Template
This project makes use of several excellent tools from Astral, including uv, ruff, and ty.
Setup
- Once you have installed
uv, install dependencies with
uv sync- Install the pre-commit hooks using
uv run pre-commit autoupdateuv run pre-commit install --install-hooks- VS Code will prompt you to install the recommended extensions, which you should accept. If you mistakenly closed it, you can find them in
.vscode/extensions.json.
Usage
- Format:
uv run ruff format - Typecheck:
uv run ty check - Lint:
uv run ruff check
To run the FastAPI app locally with uv (the project uses uv for task execution), run:
uv run python src/main.pyYou can set the PORT environment variable to change the listening port (defaults to 5000):
PORT=8080 uv run python src/main.pyDeployment (Kennel)
Production runs on Kennel via devenv and secretspec. Pushes to Codeberg main trigger deploys (GitHub mirror pushes do not).
URLs:
- https://api.cmugpt-agent.scottylabs.org (custom domain)
- https://cmugpt-agent-agent-main.scottylabs.net (default Kennel URL)
Validate locally before pushing:
SECRETSPEC_PROVIDER=dotenv://.env devenv build scottylabs.kennel.confignix build .#packages.x86_64-linux.agentSet production secrets (requires cmugpt-agent-admins group and bao login -method=oidc):
secretspec set -P prod OPENROUTER_API_KEYsecretspec set -P prod MCP_SERVER_URLsecretspec set -P prod AGENT_SHARED_SECRETsecretspec check -P prodGuidelines
You should not globally disable rules enforced by ruff or ty. If absolutely necessary, you can ignore them on a line-by-line basis:
For ty, use ignore directives in the following order of precedence, based on what is strictly necessary.
# ty: ignore[<rule>]for ignoring single rules# ty: ignore[rule1, rule2, ...]for ignoring multiple rules# type: ignoreor# type: ignore[<rule>]for ignoring all violations on that line (even if a rule is specified!)- The decorator
@typing.no_type_checkto suppress all violations inside a function
For ruff, follow the same pattern.
# noqa: <rule>for ignoring single rules# noqa: rule1, rule2, ...for ignoring multiple rules# noqafor ignoring all violations on that line# ruff: noqa: <rule>for ignoring a specific rule across an entire file# ruff: noqafor ignoring all violations across an entire file