Skip to content
Merged
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
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
with:
cache-suffix: tests-py${{ matrix.python }}${{ matrix.lowest_direct && '-lowest-direct' || '' }}
- name: Run the unit tests
run: just test --python="$PYTHON" ${LOWEST_DIRECT:+--lowest-direct} ${UPGRADE:+--upgrade}
run: just test
env:
PYTHON: ${{ matrix.python }}
LOWEST_DIRECT: ${{ matrix.lowest_direct && 'true' || '' }}
Expand All @@ -103,7 +103,7 @@ jobs:
include-hidden-files: true
if-no-files-found: error
- name: Run the type checks
run: just typecheck --python="$PYTHON" ${LOWEST_DIRECT:+--lowest-direct}
run: just typecheck
if: ${{ !cancelled() }}
env:
PYTHON: ${{ matrix.python }}
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
run: just pdc up
timeout-minutes: 5
- name: Run the integration tests
run: just integration ${UPGRADE:+--upgrade}
run: just integration
timeout-minutes: 5
env:
UPGRADE: ${{ (github.event_name == 'schedule' || inputs.upgrade) && 'true' || '' }}
Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ A framework-free Python client for the Philanthropy Data Commons (PDC) API. The

## Commands

- `just test [--python VERSION] [--lowest-direct] [--upgrade] [-- ARGS]` runs the unit tests, which mock all HTTP with `responses`. `just integration` takes the same options. Both run against the installed package in an isolated environment, with the versions in `uv.lock` unless `--lowest-direct` or `--upgrade` resolves them fresh. Arguments after `--` go to pytest.
- `just test [ARGS]` runs the unit tests, which mock all HTTP with `responses`, and `just integration [ARGS]` the live suite; arguments go to pytest. Both run against the installed package in an isolated environment, with the Python in `.python-version` and the versions in `uv.lock`. Set `PYTHON=VERSION` for another Python, and `LOWEST_DIRECT=true` or `UPGRADE=true` to resolve versions fresh.
- `just pdc up` starts PDC's CI stack in Docker; `just integration` runs the live suite against it.
- `just typecheck` runs mypy (with the pydantic plugin) over `src` and both test suites, mypy in strict mode over `src`, then pyrefly and ty over `src` and both test suites, and fails at the end if any of them failed. `just typecheck-mypy`, `just typecheck-pyrefly`, and `just typecheck-ty` run one checker each. All take `--python` and `--lowest-direct`, which work as they do for `just test`.
- `just typecheck` runs mypy (with the pydantic plugin) over `src` and both test suites, mypy in strict mode over `src`, then pyrefly and ty over `src` and both test suites, and fails at the end if any of them failed. `just typecheck-mypy`, `just typecheck-pyrefly`, and `just typecheck-ty` run one checker each. All read `PYTHON` and `LOWEST_DIRECT`, which work as they do for `just test`.
- `just zizmor` audits the GitHub Actions workflows; run it after changing anything in `.github/`. It runs offline audits only unless `GH_TOKEN` is set. Arguments go to zizmor.
- Releases go through the Release workflow, which creates the tag; see "Releasing" in `CONTRIBUTING.md`. New changelog entries go under `## Unreleased`.
- Verify with `just check` (lint, type checks, and both suites). The unit tests can't catch a change in PDC's behavior; if the stack isn't available, run `just lint`, `just typecheck`, and `just test` and say that integration verification is pending.
Expand Down
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ just integration # integration tests against that stack
just check # lint, type checks, unit tests, and integration tests
```

`just test` and `just integration` install the package into an isolated environment and run the tests against it, using the Python version in `.python-version` and the versions in `uv.lock`. Both take the same options, and pass arguments after `--` to pytest:
`just test` and `just integration` install the package into an isolated environment and run the tests against it, using the Python version in `.python-version` and the versions in `uv.lock`. Both pass their arguments to pytest, and read the same environment variables:

- `--python VERSION` uses another Python.
- `--lowest-direct` uses the lowest versions of direct dependencies that `pyproject.toml` allows.
- `--upgrade` uses the newest versions released at least a week ago (`exclude-newer` in `pyproject.toml`) and prints how they differ from `uv.lock`, without changing it.
- `PYTHON=VERSION` uses another Python.
- `LOWEST_DIRECT=true` uses the lowest versions of direct dependencies that `pyproject.toml` allows.
- `UPGRADE=true` uses the newest versions released at least a week ago (`exclude-newer` in `pyproject.toml`) and prints how they differ from `uv.lock`, without changing it.

```bash
just test --python 3.12 --lowest-direct -- -k token
PYTHON=3.12 LOWEST_DIRECT=true just test -k token
```

`just typecheck` takes `--python` and `--lowest-direct` too. CI type checks Python 3.12 with the lowest versions and Python 3.14 with `uv.lock`.
`just typecheck` reads `PYTHON` and `LOWEST_DIRECT` too. CI type checks Python 3.12 with the lowest versions and Python 3.14 with `uv.lock`.

`uv.lock` pins the versions used for development and CI. Update it with `uv lock --upgrade`. CI also runs both suites weekly with `--upgrade`, and opens an issue when that run or a push to main fails.
`uv.lock` pins the versions used for development and CI. Update it with `uv lock --upgrade`. CI also runs both suites weekly with `UPGRADE=true`, and opens an issue when that run or a push to main fails.

`just pdc up` downloads PDC's [`compose-ci.yml`](https://github.com/PhilanthropyDataCommons/service/blob/main/compose-ci.yml) and Keycloak realm from the service repo's main branch and starts the stack: the PDC API, Keycloak, Postgres, and S3. `just/patch_realm.py` adds the `kc-admin-api` scope the Keycloak sync needs, which the realm lacks; it warns once the realm defines it, and then should be deleted. CI starts the stack the same way. The integration tests reach Keycloak at `pdc-auth`, so add this line to `/etc/hosts`:

Expand Down
63 changes: 25 additions & 38 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ set minimum-version := '1.55.0'

mod pdc 'just/pdc.just'

python := shell("cat .python-version")
set positional-arguments

python := env("PYTHON", shell("cat .python-version"))
lowest_direct := env("LOWEST_DIRECT", "false")
upgrade := env("UPGRADE", "false")
isolated_run := "uv run --python=" + python + (if lowest_direct == "true" { " --resolution=lowest-direct" } else { "" }) + " --isolated --no-dev"
pytest := isolated_run + (if upgrade == "true" { " --upgrade" } else { "" }) + " --no-editable --group tests --reinstall -- python -I -m pytest"
typecheck_run := isolated_run + " --group tests --group typecheck --"

_default:
@just --list --unsorted
Expand All @@ -23,69 +30,49 @@ format:
# Audit GitHub Actions workflows with zizmor (passes through args)
[group('dev')]
zizmor *args:
uvx --exclude-newer "7 days" zizmor .github/ {{args}}
uvx --exclude-newer "7 days" zizmor .github/ "$@"

# Run all three type checkers, failing at the end if any failed
[group('dev')]
[arg("python", long)]
[arg("lowest_direct", long="lowest-direct", value="true")]
typecheck python=python lowest_direct="false":
typecheck:
#!/usr/bin/env bash
status=0
for checker in mypy pyrefly ty; do
{{just_executable()}} typecheck-$checker --python={{python}} \
{{ if lowest_direct == "true" { "--lowest-direct" } else { "" } }} || status=1
{{just_executable()}} typecheck-$checker || status=1
done
exit $status

# Type check the package and tests with mypy, then the package in strict mode
[group('dev')]
[arg("python", long)]
[arg("lowest_direct", long="lowest-direct", value="true")]
typecheck-mypy python=python lowest_direct="false":
typecheck-mypy:
#!/usr/bin/env bash
status=0
{{just_executable()}} _typecheck {{python}} {{lowest_direct}} mypy || status=1
{{just_executable()}} _typecheck {{python}} {{lowest_direct}} mypy --strict src || status=1
{{typecheck_run}} mypy --python-version={{python}} || status=1
{{typecheck_run}} mypy --python-version={{python}} --strict src || status=1
exit $status

# Type check the package and tests with pyrefly
[group('dev')]
[arg("python", long)]
[arg("lowest_direct", long="lowest-direct", value="true")]
typecheck-pyrefly python=python lowest_direct="false" *args: (_typecheck python lowest_direct "pyrefly check" args)
typecheck-pyrefly *args:
{{typecheck_run}} pyrefly check --python-version={{python}} "$@"

# Type check the package and tests with ty
[group('dev')]
[arg("python", long)]
[arg("lowest_direct", long="lowest-direct", value="true")]
typecheck-ty python=python lowest_direct="false" *args: (_typecheck python lowest_direct "ty check" args)
typecheck-ty *args:
{{typecheck_run}} ty check --python-version={{python}} "$@"

# Run the unit tests against the installed package
[group('test')]
[arg("python", long)]
[arg("lowest_direct", long="lowest-direct", value="true")]
[arg("upgrade", long, value="true")]
test python=python lowest_direct="false" upgrade="false" *args: (_pytest python lowest_direct upgrade args)
test *args: _preview-upgrade
{{pytest}} "$@"

# Run the integration tests against the installed package and a live PDC stack (run `just pdc up` first)
[group('test')]
[arg("python", long)]
[arg("lowest_direct", long="lowest-direct", value="true")]
[arg("upgrade", long, value="true")]
integration python=python lowest_direct="false" upgrade="false" *args: (_pytest python lowest_direct upgrade "integration_tests/ " + args)

_typecheck python lowest_direct tool *args:
uv run --python={{python}} {{ if lowest_direct == "true" { "--resolution=lowest-direct" } else { "" } }} --isolated --no-dev --group tests --group typecheck -- \
{{tool}} --python-version={{python}} {{args}}

_pytest python lowest_direct upgrade *args:
@if [ "{{upgrade}}" = "true" ]; then uv lock --upgrade --dry-run; fi
uv run --python={{python}} \
{{ if lowest_direct == "true" { "--resolution=lowest-direct" } else { "" } }} \
{{ if upgrade == "true" { "--upgrade" } else { "" } }} \
--isolated --no-editable --no-dev --group tests --reinstall -- \
python -I -m pytest {{args}}
integration *args: _preview-upgrade
{{pytest}} integration_tests/ "$@"

_preview-upgrade:
@if [ "{{upgrade}}" = true ]; then uv lock --upgrade --dry-run; fi

# Run lint, type checks, unit tests, and integration tests (run `just pdc up` first)
[group('test')]
Expand Down