Skip to content

Development

Setting Up uv

This project is set up to use uv to manage Python and dependencies. First, be sure you have uv installed.

The package itself imports on Python 3.8 or newer. make install, pytest, ruff, ty, and mkdocs need Python 3.11 or newer. uv python install 3.13 is the version the docs and CI dev job use.

Then fork the MFDI-hub/discry repo (having your own fork will make it easier to contribute) and clone it.

Basic Developer Workflows

The Makefile simply offers shortcuts to uv commands for developer convenience. (For clarity, GitHub Actions don’t use the Makefile and just call uv directly.) Windows does not include GNU make. Install it (WSL or a port such as Chocolatey) or run the uv commands below. They are what the Makefile wraps.

# First, install all dependencies, set up the venv, and install git hooks.
# This runs `uv sync` and `pre-commit install`.
make install

# Run uv sync, lint, and test:
make

# Build wheel (publishable; does not vendor path sources):
make build

# Linting (codespell, ruff, ty, vulture). Local runs may rewrite files.
# CI passes --check so a dirty tree fails the job:
make lint
uv run python devtools/lint.py
uv run python devtools/lint.py --check

# Run tests (parallel + coverage). Order is shuffled; see test-random below.
make test

# Print the randomly seed, then repeat in a stable order:
make test-random

# Run all pre-commit hooks on the whole tree:
make pre-commit

# Preview documentation locally (MkDocs + Material):
make docs

# The API section is not a hand-written page. mkdocs-api-autonav builds one
# page per module from the docstrings on `uv run mkdocs build`.

# Delete all the build artifacts:
make clean

# Upgrade dependencies to compatible versions:
make upgrade

# To run tests by hand:
uv run pytest   # all tests
uv run pytest -n auto --cov --cov-report=term-missing
uv run pytest -s src/module/some_file.py  # one test, showing outputs

# Build and install current dev executables, to let you use your dev copies
# as local tools:
uv tool install --editable .

# Dependency management directly with uv:
# Add a new dependency:
uv add package_name
# Add a development dependency:
uv add --dev package_name
# Update to latest compatible versions (including dependencies on git repos):
uv sync --upgrade
# Update a specific package:
uv lock --upgrade-package package_name
# Update dependencies on a package:
uv add package_name@latest

# Run a shell within the Python environment:
uv venv
source .venv/bin/activate
# On Windows PowerShell:
# .venv\Scripts\Activate.ps1

See uv docs for details.

Running individual tools

All tool configuration lives in pyproject.toml, so each tool can also be driven directly (this is what editors and CI do):

uv run ruff check .            # lint
uv run ruff check --fix .      # lint + autofix
uv run ruff format .           # format (or --check to verify only)
uv run ty check                # type check (paths come from [tool.ty.src])
uv run codespell               # spelling
uv run vulture                 # dead code
uv run pytest                  # tests
uv run pytest -n auto -k name  # parallel, filtered

The Makefile wraps the common combinations (make install, make lint, make test, make docs-build), and devtools/lint.py runs the whole lint chain in one go.

ty is pre-1.0. If a third-party package ships no type information, prefer [tool.ty.analysis] allowed-unresolved-imports over sprinkling # type: ignore. Run uv run ty check --output-format concise to see rule names for [tool.ty.rules].

Sync chosen files

tool-shed is installed with the dev group (PyPI project tools-shed). sync_chosen_files watches selected source paths and writes a single text dump (useful for sharing code with LLMs or archiving a snapshot). The same install provides the rest of the shed: watch_run, skeleton_dump, hash_tree, repo_map, related, quiet_exec, slice, churn, and diff_syms.

Edit scripts/chosen_files.txt to list files or directories (one path per line). Then:

# One-shot dump:
uv run sync_chosen_files --once

# Watch and re-sync on changes:
uv run sync_chosen_files

# Custom paths or output file:
uv run sync_chosen_files --dir src/discry --out outputs/builds/source_dump.txt --once
uv run sync_chosen_files --file-list scripts/chosen_files.txt --ext py,toml --once

Output defaults to outputs/builds/source_dump.txt (gitignored).

Pre-commit and Commitizen

Install hooks once (also done by make install):

uv run pre-commit install
uv run pre-commit install --hook-type commit-msg

Commit hooks run ruff, codespell, and ty. vulture and deptry run on pre-push (make install registers that hook too) and in CI. Commit messages should follow Conventional Commits (required for automated releases). Use Commitizen interactively:

uv run cz commit
# or validate the last message:
uv run cz check --rev-range HEAD~1..HEAD

IDE setup

If you use VS Code or a fork like Cursor or Windsurf, you can install the following extensions:

  • Python
  • ty for type checking and the ty language server. Note that this extension works with non-Microsoft VS Code forks like Cursor.
  • Ruff

.vscode/settings.json sets python.languageServer to None. Navigation and completions then come from the ty extension. Install it, or set the language server back to Pylance and set python.analysis.typeCheckingMode to off so ty remains the type checker.

This repo also includes:

  • VS Code Tasks (.vscode/tasks.json) — Run Task → install / lint / test / docs / …
  • Dev Container (.devcontainer/devcontainer.json) — open in Codespaces or “Reopen in Container” for a ready uv + pre-commit environment

Local CI with act

To run GitHub Actions workflows locally (optional):

# https://nektosact.com/
brew install act   # or see act install docs for your OS
act push           # simulate a push event (runs CI)
act -l             # list jobs

HTTP client (httpie)

Handy for poking at HTTP APIs without adding a project dependency:

uvx httpie GET https://httpbin.org/get
# or install as a user tool:
uv tool install httpie

Logging and progress

rich and funlog are already dev dependencies (used by devtools/lint.py). For application code, add what you actually use:

uv add structlog      # structured logging
uv add tqdm           # progress bars
import structlog
from tqdm import tqdm

log = structlog.get_logger()
log.info("starting", items=10)

for item in tqdm(range(10)):
    ...

Profiling

Profiling tools are an opt-in group, so they never slow a normal setup:

uv run --group profiling py-spy record -o profile.svg -- python -m discry
uv run python -m cProfile -o out.prof -m discry
uv run --group profiling snakeviz out.prof

Property-based tests

uv sync --group property-testing
from hypothesis import given, strategies as st


@given(st.lists(st.integers()))
def test_roundtrip(values: list[int]) -> None:
    assert sorted(sorted(values)) == sorted(values)

Documentation hosting

Local and CI use MkDocs. For hosted docs you can:

  • GitHub Pages — .github/workflows/docs.yml builds and deploys on push to main/master. Enable Pages in repo settings: Settings → Pages → Build and deployment → GitHub Actions.
  • Read the Docs — import the repo on Read the Docs; .readthedocs.yaml is already included.

Project management on GitHub

Optional GitHub features (not code):

Publishing Releases

See publishing.md for instructions on publishing to PyPI (manual releases and semantic-release).

Documentation


This file was built with python-template.