Skip to content

Commit 4bf714f

Browse files
njzjzMathieu Taillefumier
authored andcommitted
ci(build): use uv for cibuildwheel (deepmodeling#3695)
Should save 1 minute per build on average. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced platform-specific constraints for `h5py` when using TensorFlow, ensuring better compatibility and performance. - **Chores** - Updated build configuration to include the `uv` tool for building wheels. - Modified `.gitignore` to exclude the `.uv/` directory. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
1 parent 14fbe18 commit 4bf714f

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

.github/workflows/build_wheel.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,27 @@ jobs:
7474
with:
7575
# https://github.com/pypa/setuptools_scm/issues/480
7676
fetch-depth: 0
77+
- name: Install uv
78+
run: curl -LsSf https://astral.sh/uv/install.sh | sh
79+
if: runner.os != 'Linux'
7780
- uses: docker/setup-qemu-action@v3
7881
name: Setup QEMU
7982
if: matrix.platform_id == 'manylinux_aarch64' && matrix.os == 'ubuntu-latest'
8083
# detect version in advance. See #3168
81-
- uses: actions/setup-python@v5
82-
name: Install Python
83-
with:
84-
python-version: '3.11'
85-
cache: 'pip'
86-
if: matrix.dp_pkg_name == 'deepmd-kit-cu11'
8784
- run: |
88-
python -m pip install setuptools_scm
89-
python -c "from setuptools_scm import get_version;print('SETUPTOOLS_SCM_PRETEND_VERSION='+get_version())" >> $GITHUB_ENV
85+
echo "SETUPTOOLS_SCM_PRETEND_VERSION=$(pipx run uv tool run --from setuptools_scm python -m setuptools_scm)" >> $GITHUB_ENV
9086
rm -rf .git
9187
if: matrix.dp_pkg_name == 'deepmd-kit-cu11'
9288
- name: Build wheels
93-
uses: pypa/cibuildwheel@v2.18
89+
uses: pypa/cibuildwheel@v2.19
9490
env:
9591
CIBW_BUILD_VERBOSITY: 1
9692
CIBW_ARCHS: all
9793
CIBW_BUILD: cp${{ matrix.python }}-${{ matrix.platform_id }}
9894
DP_VARIANT: ${{ matrix.dp_variant }}
9995
CUDA_VERSION: ${{ matrix.cuda_version }}
10096
DP_PKG_NAME: ${{ matrix.dp_pkg_name }}
97+
CIBW_BUILD_FRONTEND: 'build[uv]'
10198
- uses: actions/upload-artifact@v4
10299
with:
103100
name: cibw-cp${{ matrix.python }}-${{ matrix.platform_id }}-cu${{ matrix.cuda_version }}-${{ strategy.job-index }}
@@ -109,14 +106,8 @@ jobs:
109106
- uses: actions/checkout@v4
110107
with:
111108
fetch-depth: 0
112-
- uses: actions/setup-python@v5
113-
name: Install Python
114-
with:
115-
python-version: '3.11'
116-
cache: 'pip'
117-
- run: python -m pip install build
118109
- name: Build sdist
119-
run: python -m build --sdist
110+
run: pipx run uv tool run --with build[uv] --from build python -m build --installer uv --sdist
120111

121112
- uses: actions/upload-artifact@v4
122113
with:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ build_cc_tests
4444
build_c_tests
4545
build_c/
4646
libdeepmd_c/
47+
.uv/

backend/find_tensorflow.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,18 @@ def get_tf_requirement(tf_version: str = "") -> dict:
156156
"tensorflow; platform_machine=='aarch64' or (platform_machine=='arm64' and platform_system == 'Darwin')",
157157
# https://github.com/tensorflow/tensorflow/issues/61830
158158
"tensorflow-cpu!=2.15.*; platform_system=='Windows'",
159+
# TODO: build(wheel): unpin h5py on aarch64
160+
# Revert after https://github.com/h5py/h5py/issues/2408 is fixed;
161+
# or set UV_PREFER_BINARY when https://github.com/astral-sh/uv/issues/1794 is resolved.
162+
# 3.6.0 is the first version to have aarch64 wheels.
163+
"h5py>=3.6.0,<3.11.0; platform_system=='Linux' and platform_machine=='aarch64'",
159164
*extra_requires,
160165
],
161166
"gpu": [
162167
"tensorflow",
163168
"tensorflow-metal; platform_machine=='arm64' and platform_system == 'Darwin'",
169+
# See above.
170+
"h5py>=3.6.0,<3.11.0; platform_system=='Linux' and platform_machine=='aarch64'",
164171
*extra_requires,
165172
],
166173
**extra_select,

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ dependencies = [
4343
'typing_extensions; python_version < "3.8"',
4444
'importlib_metadata>=1.4; python_version < "3.8"',
4545
'h5py',
46+
"h5py>=3.6.0,<3.11.0; platform_system=='Linux' and platform_machine=='aarch64'",
4647
'wcmatch',
4748
'packaging',
4849
'ml_dtypes',
@@ -232,6 +233,12 @@ before-all = [
232233
"""rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux""",
233234
"""{ if [ "$(uname -m)" = "x86_64" ] ; then yum config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo && yum install -y cuda-nvcc-${CUDA_VERSION/./-} cuda-cudart-devel-${CUDA_VERSION/./-}; fi }""",
234235
"yum install -y mpich-devel",
236+
# uv is not available in the old manylinux image
237+
"""{ if [ "$(uname -m)" = "x86_64" ] ; then pipx install uv; fi }""",
238+
]
239+
before-build = [
240+
# old build doesn't support uv
241+
"""{ if [ "$(uname -m)" = "x86_64" ] ; then uv pip install --system -U build; fi }""",
235242
]
236243

237244
[tool.cibuildwheel.windows]

0 commit comments

Comments
 (0)