Skip to content

Commit a3af13a

Browse files
authored
Allow installation of extras in GitHub action (#2630)
1 parent 168717b commit a3af13a

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

action.yml

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ inputs:
1717
description: 'Build a specific wheel only. No need for arch/platform if this is set'
1818
required: false
1919
default: ''
20+
extras:
21+
description: 'Comma-separated list of extras to install'
22+
required: false
23+
default: ''
2024
branding:
2125
icon: package
2226
color: yellow
@@ -42,6 +46,10 @@ runs:
4246
from pathlib import Path
4347
from subprocess import run
4448
49+
EXTRAS = set(e.strip() for e in "${{ inputs.extras }}".split(",") if e.strip())
50+
if sys.platform == "linux":
51+
EXTRAS.discard("uv")
52+
4553
4654
class EnvBuilder(venv.EnvBuilder):
4755
def __init__(self):
@@ -53,7 +61,10 @@ runs:
5361
def post_setup(self, context):
5462
super().post_setup(context)
5563
self.bin_path = Path(context.env_exe).parent
56-
run([sys.executable, "-m", "pip", "--python", context.env_exe, "install", r"${{ github.action_path }}"], check=True)
64+
install_spec = r"${{ github.action_path }}"
65+
if EXTRAS:
66+
install_spec += f"[{','.join(sorted(EXTRAS))}]"
67+
run([sys.executable, "-m", "pip", "--python", context.env_exe, "install", install_spec], check=True)
5768
5869
5970
print("::group::Install cibuildwheel")
@@ -62,30 +73,47 @@ runs:
6273
shutil.rmtree(venv_path)
6374
builder = EnvBuilder()
6475
builder.create(venv_path)
65-
cibw_path = [path for path in builder.bin_path.glob("cibuildwheel*") if path.stem == "cibuildwheel"][0]
76+
exposed_binaries = {"cibuildwheel"}
77+
if "uv" in EXTRAS:
78+
exposed_binaries.add("uv")
79+
clean_bin_path = builder.bin_path.parent / f"{builder.bin_path.name}.clean"
80+
clean_bin_path.mkdir()
81+
for path in list(builder.bin_path.iterdir()):
82+
if path.stem in exposed_binaries:
83+
try:
84+
os.symlink(path, clean_bin_path / path.name)
85+
except OSError:
86+
import shutil
87+
88+
shutil.copy2(path, clean_bin_path / path.name)
89+
full_path = f"{clean_bin_path}{os.pathsep}{os.environ['PATH']}"
6690
with open(os.environ["GITHUB_OUTPUT"], "at") as f:
67-
f.write(f"cibw-path={cibw_path}\n")
91+
f.write(f"updated-path={full_path}\n")
6892
print("::endgroup::")
6993
EOF
7094
shell: bash
7195

7296
# Redirecting stderr to stdout to fix interleaving issue in Actions.
7397
- run: >
74-
"${{ steps.cibw.outputs.cibw-path }}"
98+
cibuildwheel
7599
"${{ inputs.package-dir }}"
76100
${{ inputs.output-dir != '' && format('--output-dir "{0}"', inputs.output-dir) || ''}}
77101
${{ inputs.config-file != '' && format('--config-file "{0}"', inputs.config-file) || ''}}
78102
${{ inputs.only != '' && format('--only "{0}"', inputs.only) || ''}}
79103
2>&1
104+
env:
105+
PATH: "${{ steps.cibw.outputs.updated-path }}"
80106
shell: bash
81107
if: runner.os != 'Windows'
82108
83109
# Windows needs powershell to interact nicely with Meson
84110
- run: >
85-
& "${{ steps.cibw.outputs.cibw-path }}"
111+
cibuildwheel
86112
"${{ inputs.package-dir }}"
87113
${{ inputs.output-dir != '' && format('--output-dir "{0}"', inputs.output-dir) || ''}}
88114
${{ inputs.config-file != '' && format('--config-file "{0}"', inputs.config-file) || ''}}
89115
${{ inputs.only != '' && format('--only "{0}"', inputs.only) || ''}}
116+
env:
117+
PATH: "${{ steps.cibw.outputs.updated-path }}"
90118
shell: pwsh
91119
if: runner.os == 'Windows'

docs/ci-services.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ To build Linux, macOS, and Windows wheels using GitHub Actions, create a `.githu
2323

2424
Use `env:` to pass [build options](options.md) and `with:` to set
2525
`package-dir: .`, `output-dir: wheelhouse` and `config-file: ''`
26-
locations (those values are the defaults).
26+
locations (those values are the defaults). You can also pass a
27+
comma-separated list of extras to install additional packages.
28+
For example, `extras: "uv"` to install UV into the virtual environment.
2729

2830
!!! tab "pipx"
2931
The GitHub Actions runners have pipx installed, so you can easily build in

docs/options.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,16 @@ Default: `build`
470470

471471
Choose which build frontend to use.
472472

473-
You can use "build\[uv\]", which will use an external [uv][] everywhere
473+
You can use "build\[uv\]", which will use an external [UV][] everywhere
474474
possible, both through `--installer=uv` passed to build, as well as when making
475475
all build and test environments. This will generally speed up cibuildwheel.
476-
Make sure you have an external uv on Windows and macOS, either by
477-
pre-installing it, or installing cibuildwheel with the uv extra,
478-
`cibuildwheel[uv]`. uv currently does not support Windows on ARM,
479-
musllinux on s390x, Android, or iOS. Legacy dependencies like
480-
setuptools on Python < 3.12 and pip are not installed if using uv.
476+
Make sure you have an external UV on Windows and macOS, either by
477+
pre-installing it, or installing cibuildwheel with the `uv` extra, which is
478+
possible by manually passing `cibuildwheel[uv]` to installers or by using the
479+
`extras` option in the [cibuildwheel action](ci-services.md#github-actions).
480+
UV currently does not support Android, iOS nor musllinux on s390x. Legacy
481+
dependencies like setuptools on Python < 3.12 and pip are not installed if
482+
using UV.
481483

482484
On Android and Pyodide, only "build" is supported.
483485

0 commit comments

Comments
 (0)