From 8f21eb17be321024854494f69d8b45610e791c65 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Tue, 19 Nov 2024 13:30:06 -0500 Subject: [PATCH] chore: use dependency-groups (#2064) * chore: use dependency-groups Signed-off-by: Henry Schreiner * ci: use dep groups in other CIs Signed-off-by: Henry Schreiner * Apply suggestions from code review * chore: read dep groups in noxfile Signed-off-by: Henry Schreiner * Apply suggestions from code review Co-authored-by: Matthieu Darbois * Add dev environment instructions --------- Signed-off-by: Henry Schreiner Co-authored-by: Matthieu Darbois Co-authored-by: Joe Rickerby --- .circleci/prepare.sh | 4 ++-- .cirrus.yml | 3 ++- .github/workflows/test.yml | 24 +++++++++++++----------- .readthedocs.yml | 4 +--- .travis.yml | 4 ++-- azure-pipelines.yml | 9 ++++++--- docs/contributing.md | 27 ++++++++++++++++++++++----- noxfile.py | 10 +++++++--- pyproject.toml | 33 +++++++++++++++++++-------------- requirements-dev.txt | 1 - 10 files changed, 74 insertions(+), 45 deletions(-) delete mode 100644 requirements-dev.txt diff --git a/.circleci/prepare.sh b/.circleci/prepare.sh index 272ddae4d..86ab4cbea 100644 --- a/.circleci/prepare.sh +++ b/.circleci/prepare.sh @@ -10,7 +10,7 @@ fi $PYTHON --version $PYTHON -m venv venv -venv/bin/python -m pip install -U pip -venv/bin/python -m pip install -e ".[dev]" +venv/bin/python -m pip install -U pip dependency-groups +venv/bin/python -m dependency_groups test | xargs venv/bin/python -m pip install -e. venv/bin/python -m pip freeze venv/bin/python --version diff --git a/.cirrus.yml b/.cirrus.yml index 9b01cccf3..6faa9bf56 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -2,7 +2,8 @@ only_if: changesInclude('.cirrus.yml') || ($CIRRUS_BRANCH == "main" && !changesI run_tests: &RUN_TESTS install_cibuildwheel_script: - - python -m pip install -e ".[dev]" pytest-custom-exit-code + - python -m pip install dependency-groups + - python -m dependency_groups test | xargs python -m pip install -e. run_cibuildwheel_tests_script: - python ./bin/run_tests.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 629367433..3757be634 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -67,11 +67,11 @@ jobs: - name: Install dependencies run: | - uv pip install --system ".[test]" + uv sync --no-dev --group test - name: Generate a sample project run: | - python -m test.test_projects test.test_0_basic.basic_project sample_proj + uv run -m test.test_projects test.test_0_basic.basic_project sample_proj - name: Run a sample build (GitHub Action) uses: ./ @@ -124,7 +124,7 @@ jobs: - name: Test cibuildwheel run: | - python ./bin/run_tests.py --run-podman + uv run bin/run_tests.py --run-podman emulated-archs: name: Get qemu emulated architectures @@ -137,12 +137,13 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.x" + - uses: astral-sh/setup-uv@v3 - name: Install dependencies - run: python -m pip install ".[test]" + run: uv sync --no-dev --group test - name: Get qemu emulated architectures id: archs run: | - OUTPUT=$(python -c "from json import dumps; from test.utils import EMULATED_ARCHS; print(dumps(EMULATED_ARCHS))") + OUTPUT=$(uv run python -c "from json import dumps; from test.utils import EMULATED_ARCHS; print(dumps(EMULATED_ARCHS))") echo "${OUTPUT}" echo "archs=${OUTPUT}" >> "$GITHUB_OUTPUT" @@ -159,14 +160,15 @@ jobs: - uses: actions/setup-python@v5 with: python-version: "3.x" + - uses: astral-sh/setup-uv@v3 - name: Install dependencies - run: python -m pip install ".[test,uv]" + run: uv sync --no-dev --group test - name: Set up QEMU uses: docker/setup-qemu-action@v3 - name: Run the emulation tests - run: pytest --run-emulation ${{ matrix.arch }} test/test_emulation.py + run: uv run pytest --run-emulation ${{ matrix.arch }} test/test_emulation.py test-pyodide: name: Test cibuildwheel building pyodide wheels @@ -179,14 +181,14 @@ jobs: name: Install Python 3.12 with: python-version: '3.12' + - uses: astral-sh/setup-uv@v3 - name: Install dependencies - run: | - python -m pip install ".[test]" + run: uv sync --no-dev --group test - name: Generate a sample project run: | - python -m test.test_projects test.test_0_basic.basic_project sample_proj + uv run -m test.test_projects test.test_0_basic.basic_project sample_proj - name: Run a sample build (GitHub Action) uses: ./ @@ -198,6 +200,6 @@ jobs: - name: Run tests with 'CIBW_PLATFORM' set to 'pyodide' run: | - python ./bin/run_tests.py + uv run ./bin/run_tests.py env: CIBW_PLATFORM: pyodide diff --git a/.readthedocs.yml b/.readthedocs.yml index 30a381ecc..60724f36e 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -10,6 +10,4 @@ build: - asdf plugin add uv - asdf install uv latest - asdf global uv latest - - uv venv - - uv pip install -e.[docs] - - NO_COLOR=1 .venv/bin/mkdocs build --strict --site-dir $READTHEDOCS_OUTPUT/html + - NO_COLOR=1 uv run --no-dev --group docs mkdocs build --strict --site-dir $READTHEDOCS_OUTPUT/html diff --git a/.travis.yml b/.travis.yml index 709127e61..b610edf00 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,8 +57,8 @@ jobs: install: - if [ "${TRAVIS_OS_NAME}" == "linux" ]; then docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all; fi -- $PYTHON -m pip install -U pip -- $PYTHON -m pip install -e ".[test]" pytest-custom-exit-code +- $PYTHON -m pip install -U pip dependency-groups +- $PYTHON -m dependency_groups test | xargs $PYTHON -m pip install -e. script: | # travis_wait disable the output while waiting diff --git a/azure-pipelines.yml b/azure-pipelines.yml index f6f066f04..fa720d84a 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -14,7 +14,8 @@ jobs: versionSpec: '3.8' - bash: | docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all - python -m pip install -e ".[dev]" + python -m pip install dependency-groups + python -m dependency_groups test | xargs python -m pip install -e. python ./bin/run_tests.py - job: macos_38 @@ -24,7 +25,8 @@ jobs: inputs: versionSpec: '3.8' - bash: | - python -m pip install -e ".[dev]" + python -m pip install dependency-groups + python -m dependency_groups test | xargs python -m pip install -e. python ./bin/run_tests.py --num-processes 2 - job: windows_38 @@ -35,5 +37,6 @@ jobs: inputs: versionSpec: '3.8' - bash: | - python -m pip install -e ".[dev]" + python -m pip install dependency-groups + python -m dependency_groups test | xargs python -m pip install -e. python ./bin/run_tests.py diff --git a/docs/contributing.md b/docs/contributing.md index 235de69ce..237708999 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -82,14 +82,11 @@ A few notes- - Running the macOS integration tests requires _system installs_ of Python from python.org for all the versions that are tested. We won't attempt to install these when running locally, but you can do so manually using the URL in the error message that is printed when the install is not found. -#### Making a venv +#### Running pytest directly -More advanced users might prefer to invoke pytest directly- +More advanced users might prefer to invoke pytest directly. Set up a [dev environment](#setting-up-a-dev-environment), then, ```bash -python3 -m venv .venv -source .venv/bin/activate -pip install -e .[dev] # run the unit tests pytest unit_test # run the whole integration test suite @@ -120,6 +117,26 @@ nox -s update_constraints # update all constraints files in cibuildwheel/resourc nox -s update_pins # update tools, python interpreters & docker images used by cibuildwheel ``` +### Setting up a dev environment + +A dev environment isn't required for any of the `nox` tasks above. However, a dev environment is still useful, to be able to point an editor at, and a few other jobs. + +cibuildwheel uses dependency groups. Set up a dev environment with UV by doing + +```bash +uv sync +``` + +Or, if you're not using `uv`, you can do: + +```bash +python3 -m venv .venv +source .venv/bin/activate +pipx run dependency-groups dev | xargs pip install -e. +``` + +Your virtualenv is at `.venv`. + ## Maintainer notes ### Testing sample configs diff --git a/noxfile.py b/noxfile.py index 0c2057b6d..83e235131 100644 --- a/noxfile.py +++ b/noxfile.py @@ -21,12 +21,16 @@ def install_and_run(session: nox.Session, script: str, *args: str, **kwargs: Any return session.run("python", script, *args, **kwargs) +def dep_group(group: str) -> list[str]: + return nox.project.load_toml("pyproject.toml")["dependency-groups"][group] # type: ignore[no-any-return] + + @nox.session def tests(session: nox.Session) -> None: """ Run the unit and regular tests. """ - session.install("-e.[test]") + session.install("-e.", *dep_group("test")) if session.posargs: session.run("pytest", *session.posargs) else: @@ -123,7 +127,7 @@ def update_pins(session: nox.Session) -> None: """ Update the python, docker and virtualenv pins version inplace. """ - session.install("-e.[bin]") + session.install("-e.", *dep_group("bin")) session.run("python", "bin/update_pythons.py", "--force") session.run("python", "bin/update_docker.py") session.run("python", "bin/update_virtualenv.py", "--force") @@ -166,7 +170,7 @@ def docs(session: nox.Session) -> None: """ Build the docs. Will serve unless --non-interactive """ - session.install("-e.[docs]") + session.install("-e.", *dep_group("docs")) session.run("mkdocs", "serve" if session.interactive else "build", "--strict", *session.posargs) diff --git a/pyproject.toml b/pyproject.toml index f31708d30..13647b0cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,6 +52,20 @@ dependencies = [ ] [project.optional-dependencies] +uv = ["uv"] + +[project.scripts] +cibuildwheel = "cibuildwheel.__main__:main" + +[project.entry-points."validate_pyproject.tool_schema"] +cibuildwheel = "cibuildwheel.schema:get_schema" + +[project.urls] +Changelog = "https://github.com/pypa/cibuildwheel#changelog" +Documentation = "https://cibuildwheel.pypa.io" +Homepage = "https://github.com/pypa/cibuildwheel" + +[dependency-groups] bin = [ "click", "packaging>=21.0", @@ -61,9 +75,6 @@ bin = [ "requests", "rich>=9.6", ] -dev = [ - "cibuildwheel[test,bin]", -] docs = [ "jinja2>=3.1.2", "mkdocs-include-markdown-plugin==6.2.2", @@ -81,18 +92,12 @@ test = [ "tomli_w", "validate-pyproject", ] -uv = ["uv"] - -[project.scripts] -cibuildwheel = "cibuildwheel.__main__:main" - -[project.entry-points."validate_pyproject.tool_schema"] -cibuildwheel = "cibuildwheel.schema:get_schema" +dev = [ + {include-group = "bin"}, + {include-group = "docs"}, + {include-group = "test"}, +] -[project.urls] -Changelog = "https://github.com/pypa/cibuildwheel#changelog" -Documentation = "https://cibuildwheel.pypa.io" -Homepage = "https://github.com/pypa/cibuildwheel" [tool.pytest.ini_options] minversion = "6.0" diff --git a/requirements-dev.txt b/requirements-dev.txt deleted file mode 100644 index 18dc383fb..000000000 --- a/requirements-dev.txt +++ /dev/null @@ -1 +0,0 @@ --e .[dev,docs]