Skip to content

Commit

Permalink
chore: use dependency-groups (#2064)
Browse files Browse the repository at this point in the history
* chore: use dependency-groups

Signed-off-by: Henry Schreiner <[email protected]>

* ci: use dep groups in other CIs

Signed-off-by: Henry Schreiner <[email protected]>

* Apply suggestions from code review

* chore: read dep groups in noxfile

Signed-off-by: Henry Schreiner <[email protected]>

* Apply suggestions from code review

Co-authored-by: Matthieu Darbois <[email protected]>

* Add dev environment instructions

---------

Signed-off-by: Henry Schreiner <[email protected]>
Co-authored-by: Matthieu Darbois <[email protected]>
Co-authored-by: Joe Rickerby <[email protected]>
3 people authored Nov 19, 2024
1 parent aac31ae commit 8f21eb1
Showing 10 changed files with 74 additions and 45 deletions.
4 changes: 2 additions & 2 deletions .circleci/prepare.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
@@ -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

24 changes: 13 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 22 additions & 5 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -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
10 changes: 7 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -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)


33 changes: 19 additions & 14 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"
1 change: 0 additions & 1 deletion requirements-dev.txt

This file was deleted.

0 comments on commit 8f21eb1

Please sign in to comment.