chore: use dependency-groups (#2064)

* chore: use dependency-groups

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* ci: use dep groups in other CIs

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Apply suggestions from code review

* chore: read dep groups in noxfile

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>

* Apply suggestions from code review

Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com>

* Add dev environment instructions

---------

Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
Co-authored-by: Matthieu Darbois <mayeut@users.noreply.github.com>
Co-authored-by: Joe Rickerby <joerick@mac.com>
This commit is contained in:
Henry Schreiner
2024-11-19 19:30:06 +01:00
committed by GitHub
co-authored by Matthieu Darbois Joe Rickerby
parent aac31ae2fb
commit 8f21eb17be
10 changed files with 74 additions and 45 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ fi
$PYTHON --version $PYTHON --version
$PYTHON -m venv venv $PYTHON -m venv venv
venv/bin/python -m pip install -U pip venv/bin/python -m pip install -U pip dependency-groups
venv/bin/python -m pip install -e ".[dev]" venv/bin/python -m dependency_groups test | xargs venv/bin/python -m pip install -e.
venv/bin/python -m pip freeze venv/bin/python -m pip freeze
venv/bin/python --version venv/bin/python --version
+2 -1
View File
@@ -2,7 +2,8 @@ only_if: changesInclude('.cirrus.yml') || ($CIRRUS_BRANCH == "main" && !changesI
run_tests: &RUN_TESTS run_tests: &RUN_TESTS
install_cibuildwheel_script: 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: run_cibuildwheel_tests_script:
- python ./bin/run_tests.py - python ./bin/run_tests.py
+13 -11
View File
@@ -67,11 +67,11 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: | run: |
uv pip install --system ".[test]" uv sync --no-dev --group test
- name: Generate a sample project - name: Generate a sample project
run: | 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) - name: Run a sample build (GitHub Action)
uses: ./ uses: ./
@@ -124,7 +124,7 @@ jobs:
- name: Test cibuildwheel - name: Test cibuildwheel
run: | run: |
python ./bin/run_tests.py --run-podman uv run bin/run_tests.py --run-podman
emulated-archs: emulated-archs:
name: Get qemu emulated architectures name: Get qemu emulated architectures
@@ -137,12 +137,13 @@ jobs:
- uses: actions/setup-python@v5 - uses: actions/setup-python@v5
with: with:
python-version: "3.x" python-version: "3.x"
- uses: astral-sh/setup-uv@v3
- name: Install dependencies - name: Install dependencies
run: python -m pip install ".[test]" run: uv sync --no-dev --group test
- name: Get qemu emulated architectures - name: Get qemu emulated architectures
id: archs id: archs
run: | 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 "${OUTPUT}"
echo "archs=${OUTPUT}" >> "$GITHUB_OUTPUT" echo "archs=${OUTPUT}" >> "$GITHUB_OUTPUT"
@@ -159,14 +160,15 @@ jobs:
- uses: actions/setup-python@v5 - uses: actions/setup-python@v5
with: with:
python-version: "3.x" python-version: "3.x"
- uses: astral-sh/setup-uv@v3
- name: Install dependencies - name: Install dependencies
run: python -m pip install ".[test,uv]" run: uv sync --no-dev --group test
- name: Set up QEMU - name: Set up QEMU
uses: docker/setup-qemu-action@v3 uses: docker/setup-qemu-action@v3
- name: Run the emulation tests - 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: test-pyodide:
name: Test cibuildwheel building pyodide wheels name: Test cibuildwheel building pyodide wheels
@@ -179,14 +181,14 @@ jobs:
name: Install Python 3.12 name: Install Python 3.12
with: with:
python-version: '3.12' python-version: '3.12'
- uses: astral-sh/setup-uv@v3
- name: Install dependencies - name: Install dependencies
run: | run: uv sync --no-dev --group test
python -m pip install ".[test]"
- name: Generate a sample project - name: Generate a sample project
run: | 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) - name: Run a sample build (GitHub Action)
uses: ./ uses: ./
@@ -198,6 +200,6 @@ jobs:
- name: Run tests with 'CIBW_PLATFORM' set to 'pyodide' - name: Run tests with 'CIBW_PLATFORM' set to 'pyodide'
run: | run: |
python ./bin/run_tests.py uv run ./bin/run_tests.py
env: env:
CIBW_PLATFORM: pyodide CIBW_PLATFORM: pyodide
+1 -3
View File
@@ -10,6 +10,4 @@ build:
- asdf plugin add uv - asdf plugin add uv
- asdf install uv latest - asdf install uv latest
- asdf global uv latest - asdf global uv latest
- uv venv - NO_COLOR=1 uv run --no-dev --group docs mkdocs build --strict --site-dir $READTHEDOCS_OUTPUT/html
- uv pip install -e.[docs]
- NO_COLOR=1 .venv/bin/mkdocs build --strict --site-dir $READTHEDOCS_OUTPUT/html
+2 -2
View File
@@ -57,8 +57,8 @@ jobs:
install: install:
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all; fi - 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 -U pip dependency-groups
- $PYTHON -m pip install -e ".[test]" pytest-custom-exit-code - $PYTHON -m dependency_groups test | xargs $PYTHON -m pip install -e.
script: | script: |
# travis_wait disable the output while waiting # travis_wait disable the output while waiting
+6 -3
View File
@@ -14,7 +14,8 @@ jobs:
versionSpec: '3.8' versionSpec: '3.8'
- bash: | - bash: |
docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all 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 python ./bin/run_tests.py
- job: macos_38 - job: macos_38
@@ -24,7 +25,8 @@ jobs:
inputs: inputs:
versionSpec: '3.8' versionSpec: '3.8'
- bash: | - 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 python ./bin/run_tests.py --num-processes 2
- job: windows_38 - job: windows_38
@@ -35,5 +37,6 @@ jobs:
inputs: inputs:
versionSpec: '3.8' versionSpec: '3.8'
- bash: | - 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 python ./bin/run_tests.py
+22 -5
View File
@@ -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. - 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 ```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -e .[dev]
# run the unit tests # run the unit tests
pytest unit_test pytest unit_test
# run the whole integration test suite # 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 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 ## Maintainer notes
### Testing sample configs ### Testing sample configs
+7 -3
View File
@@ -21,12 +21,16 @@ def install_and_run(session: nox.Session, script: str, *args: str, **kwargs: Any
return session.run("python", script, *args, **kwargs) 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 @nox.session
def tests(session: nox.Session) -> None: def tests(session: nox.Session) -> None:
""" """
Run the unit and regular tests. Run the unit and regular tests.
""" """
session.install("-e.[test]") session.install("-e.", *dep_group("test"))
if session.posargs: if session.posargs:
session.run("pytest", *session.posargs) session.run("pytest", *session.posargs)
else: else:
@@ -123,7 +127,7 @@ def update_pins(session: nox.Session) -> None:
""" """
Update the python, docker and virtualenv pins version inplace. 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_pythons.py", "--force")
session.run("python", "bin/update_docker.py") session.run("python", "bin/update_docker.py")
session.run("python", "bin/update_virtualenv.py", "--force") 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 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) session.run("mkdocs", "serve" if session.interactive else "build", "--strict", *session.posargs)
+19 -14
View File
@@ -52,6 +52,20 @@ dependencies = [
] ]
[project.optional-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 = [ bin = [
"click", "click",
"packaging>=21.0", "packaging>=21.0",
@@ -61,9 +75,6 @@ bin = [
"requests", "requests",
"rich>=9.6", "rich>=9.6",
] ]
dev = [
"cibuildwheel[test,bin]",
]
docs = [ docs = [
"jinja2>=3.1.2", "jinja2>=3.1.2",
"mkdocs-include-markdown-plugin==6.2.2", "mkdocs-include-markdown-plugin==6.2.2",
@@ -81,18 +92,12 @@ test = [
"tomli_w", "tomli_w",
"validate-pyproject", "validate-pyproject",
] ]
uv = ["uv"] dev = [
{include-group = "bin"},
{include-group = "docs"},
{include-group = "test"},
]
[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"
[tool.pytest.ini_options] [tool.pytest.ini_options]
minversion = "6.0" minversion = "6.0"
-1
View File
@@ -1 +0,0 @@
-e .[dev,docs]