Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to use uv.lock instead of test-requirements.txt #3188

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
15 changes: 7 additions & 8 deletions .github/workflows/autodeps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ jobs:

- name: Bump dependencies
run: |
python -m pip install -U pip pre-commit
python -m pip install -r test-requirements.txt
uv pip compile --universal --python-version=3.9 --upgrade test-requirements.in -o test-requirements.txt
python -m pip install -U uv
uv lock --upgrade
uv tool install pre-commit
uv pip compile --universal --python-version=3.11 --upgrade docs-requirements.in -o docs-requirements.txt
pre-commit autoupdate --jobs 0
uv run pre-commit autoupdate --jobs 0

- name: Install new requirements
run: python -m pip install -r test-requirements.txt
run: uv sync

# apply newer versions' formatting
- name: Black
run: black src/trio
- name: Pre-commit updates
run: uv run pre-commit run -a

- name: uv
run: |
uv pip compile --universal --python-version=3.9 test-requirements.in -o test-requirements.txt
uv pip compile --universal --python-version=3.11 docs-requirements.in -o docs-requirements.txt

- name: Commit changes and create automerge PR
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/check-newsfragment.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: Check newsfragment

permissions: {}

on:
pull_request:
types: [labeled, unlabeled, opened, synchronize]
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: CI

permissions: {}

on:
push:
branches-ignore:
Expand Down Expand Up @@ -59,10 +61,10 @@ jobs:
VERSION: ${{ steps.dist-version.outputs.version }}

- name: Install build
run: python -Im pip install build
run: python -Im pip install uv

- name: Build dists
run: python -Im build
run: python -Im uv build
- name: Verify that the artifacts with expected names got created
run: >-
ls -1
Expand Down Expand Up @@ -111,7 +113,7 @@ jobs:
Smoke-test: install test requirements from the Git repo
run: >-
python -Im
pip install -c test-requirements.txt -r test-requirements.txt
uv sync --locked --extra base_tests --extra tests
shell: bash -eEuo pipefail {0}
working-directory: git-src

Expand All @@ -120,7 +122,7 @@ jobs:
env:
PYTHONPATH: src/
run: >-
pytest --collect-only -qq .
python -Im pytest --collect-only -qq .
| sort
| tee collected-tests
shell: bash -eEuo pipefail {0}
Expand All @@ -131,7 +133,7 @@ jobs:
env:
PYTHONPATH: src/
run: >-
pytest --collect-only -qq .
python -Im pytest --collect-only -qq .
| sort
| tee collected-tests
shell: bash -eEuo pipefail {0}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ on:
tags:
- v*

permissions: {}

# a lot of code taken from https://github.com/pypa/cibuildwheel/blob/main/examples/github-deploy.yml
jobs:
build:
Expand Down
16 changes: 4 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.9.2
hooks:
- id: ruff
types: [file]
Expand All @@ -43,7 +43,7 @@ repos:
hooks:
- id: sphinx-lint
- repo: https://github.com/woodruffw/zizmor-pre-commit
rev: v1.1.1
rev: v1.2.2
hooks:
- id: zizmor
- repo: local
Expand All @@ -56,18 +56,10 @@ repos:
additional_dependencies: ["astor", "attrs", "black", "ruff"]
files: ^src\/trio\/_core\/(_run|(_i(o_(common|epoll|kqueue|windows)|nstrumentation)))\.py$
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.5.18
rev: 0.5.21
hooks:
# Compile requirements
- id: pip-compile
name: uv pip-compile test-requirements.in
args: [
"--universal",
"--python-version=3.9",
"test-requirements.in",
"-o",
"test-requirements.txt"]
files: ^test-requirements\.(in|txt)$
- id: uv-lock
- id: pip-compile
name: uv pip-compile docs-requirements.in
args: [
Expand Down
2 changes: 2 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ fi

# Check pip compile is consistent
echo "::group::Pip Compile - Tests & Docs"
pre-commit run uv-lock --all-files \
|| EXIT_STATUS=$?
pre-commit run pip-compile --all-files \
|| EXIT_STATUS=$?
echo "::endgroup::"
Expand Down
44 changes: 32 additions & 12 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,35 +37,55 @@ python -c "import sys, struct, ssl; print('python:', sys.version); print('versio
echo "::endgroup::"

echo "::group::Install dependencies"
python -m pip install -U pip uv -c test-requirements.txt
python -m pip install -U pip tomli
python -m pip --version
UV_VERSION=$(python -c 'import tomli; from pathlib import Path; print({p["name"]:p for p in tomli.loads(Path("uv.lock").read_text())["package"]}["uv"]["version"])')
python -m pip install uv==$UV_VERSION
python -m uv --version

python -m uv pip install build

python -m build
wheel_package=$(ls dist/*.whl)
python -m uv pip install "trio @ $wheel_package" -c test-requirements.txt
UV_VENV_SEED="pip"
python -m uv venv --seed --allow-existing

# Determine platform and activate virtual environment accordingly
case "$OSTYPE" in
linux-gnu*|linux-musl*|darwin*)
source .venv/bin/activate
;;
cygwin*|msys*)
source .venv/Scripts/activate
;;
*)
echo "::error:: Unknown OS. Please add an activation method for '$OSTYPE'."
exit 1
;;
esac

# Install uv in virtual environment
python -m pip install uv==$UV_VERSION

if [ "$CHECK_FORMATTING" = "1" ]; then
python -m uv pip install -r test-requirements.txt exceptiongroup
python -m uv sync --locked --extra base_tests --extra tests
echo "::endgroup::"
source check.sh
else
# Actual tests
# expands to 0 != 1 if NO_TEST_REQUIREMENTS is not set, if set the `-0` has no effect
# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02
if [ "${NO_TEST_REQUIREMENTS-0}" == 1 ]; then
python -m uv pip install pytest coverage -c test-requirements.txt
python -m uv sync --locked --extra base_tests
# python -m uv pip install pytest coverage -c test-requirements.txt
flags="--skip-optional-imports"
else
python -m uv pip install -r test-requirements.txt
python -m uv sync --locked --extra base_tests --extra tests
flags=""
fi

# So we can run the test for our apport/excepthook interaction working
if [ -e /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release; then
sudo apt install -q python3-apport
# If linux runner on Github Actions (not on local machines)
if [[ "${RUNNER_OS:-}" == "Linux" ]]; then
# So we can run the test for our apport/excepthook interaction working
if [ -e /etc/lsb-release ] && grep -q Ubuntu /etc/lsb-release; then
sudo apt install -q python3-apport
fi
fi

# If we're testing with a LSP installed, then it might break network
Expand Down
36 changes: 36 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,41 @@ Changelog = "https://trio.readthedocs.io/en/latest/history.html"
[project.entry-points.hypothesis]
trio = "trio._core._run:_hypothesis_plugin_setup"

[project.optional-dependencies]
base_tests = [
"pytest>=5.0", # for faulthandler in core
"coverage>=7.2.5",
"uv>=0.5.21",
]
tests = [
"async_generator>=1.9",
"pyright",
"pyOpenSSL>=22.0.0", # for the ssl + DTLS tests
"trustme", # for the ssl + DTLS tests
"pylint", # for pylint finding all symbols tests
'jedi; implementation_name == "cpython"', # for jedi code completion tests
"cryptography>=41.0.0", # cryptography<41 segfaults on pypy3.10
# https://github.com/python-trio/trio/pull/654#issuecomment-420518745
"mypy-extensions",
"typing-extensions",
"types-cffi",
"types-pyOpenSSL",
"exceptiongroup>=1.2.1", # 1.2.1 fixes types
# annotations in doc files
"types-docutils",
"sphinx",
# Tools
'black>=24.10.0; implementation_name == "cpython"',
"mypy", # Would use mypy[faster-cache], but orjson has build issues on pypy
'orjson; implementation_name == "cpython"',
"codespell>=2.3.0",
"ruff>=0.8.0",
"astor", # code generation
"uv>=0.2.24",
"codespell",
"pre-commit",
]

[tool.setuptools]
# This means, just install *everything* you see under trio/, even if it
# doesn't look like a source file, so long as it appears in MANIFEST.in:
Expand Down Expand Up @@ -153,6 +188,7 @@ extend-ignore = [
"PERF203", # try-except-in-loop (not always possible to refactor)
"PT012", # multiple statements in pytest.raises block
"SIM117", # multiple-with-statements (messes up lots of context-based stuff and looks bad)
"PT031", # pytest-warns-with-multiple-statements (tests need large blocks in a lot of cases)

# conflicts with formatter (ruff recommends these be disabled)
"COM812",
Expand Down
5 changes: 4 additions & 1 deletion src/trio/_tests/test_deprecate.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,10 @@ def test_warning_class() -> None:
warn_deprecated("foo", "bar", issue=None, instead=None)

# essentially the same as the above check
with pytest.warns(DeprecationWarning):
with pytest.warns(
DeprecationWarning,
match="^foo is deprecated since Trio bar with no replacement$",
):
warn_deprecated("foo", "bar", issue=None, instead=None)

with pytest.warns(TrioDeprecationWarning):
Expand Down
39 changes: 0 additions & 39 deletions test-requirements.in

This file was deleted.

Loading
Loading