Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build-wheel: improve performance #2747

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 52 additions & 33 deletions .github/workflows/build-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,80 @@ on:
workflow_dispatch:

jobs:
matrix:
name: Generate matrix of builds
runs-on: ubuntu-latest
steps:

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Extra includes
id: includes
run: |
import json, os
include = [
{"os": "ubuntu-latest", "arch": "x86_64", "tag": "cp3*-manylinux_x86_64"},
{"os": "windows-latest", "arch": "x86_64", "tag": "cp3*-win_amd64"},
{"os": "macos-13", "arch": "x86_64", "tag": "cp3{9,10}-macosx_x86_64"},
{"os": "macos-14", "arch": "arm64", "tag": "cp3{11,12,13}-macosx_arm64"},
]
if "${{ github.event_name }}" != "pull_request":
include += [
{"os": "ubuntu-latest", "arch": "x86_64", "tag": "cp3*-musllinux_x86_64"},
{"os": "ubuntu-latest", "arch": "arm64", "tag": "cp3*-manylinux_aarch64"},
{"os": "ubuntu-latest", "arch": "arm64", "tag": "cp3*-musllinux_aarch64"},
{"os": "ubuntu-latest", "arch": "ppc64le", "tag": "cp3*-manylinux_ppc64le"},
{"os": "macos-14", "arch": "universal2", "tag": "cp3{11,12,13}-macosx_universal2"},
]
with open(os.environ["GITHUB_OUTPUT"], "a+") as f:
print("data="+json.dumps({"include": include}), file=f)
print("data="+json.dumps({"include": include}))
shell: python

outputs:
data: ${{ steps.includes.outputs.data }}

build_wheel:
needs:
- matrix
strategy:
fail-fast: false
matrix:
# macos-14 is arm64 (apple silicon), macos-13 is x86_64
os: [ubuntu-latest, windows-latest, macos-13, macos-14]
name: Build [${{ matrix.os }}]
# macos-14 is arm64 (apple silicon), macos-13 is x86_64
matrix: ${{ fromJSON(needs.matrix.outputs.data) }}
name: Build [${{ matrix.os }}-${{ matrix.arch }}](job-${{ strategy.job-index }})
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
env:
UV_SYSTEM_PYTHON: true
steps:

- uses: actions/checkout@v4

- uses: actions/setup-python@v5
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: |
**/requirements.txt
**/requirements-dev.txt
requirements.txt
requirements-dev.txt

- name: Set up QEMU
if: runner.os == 'Linux' && github.event_name != 'pull_request'
if: runner.os == 'Linux' && matrix.arch != 'x86_64'
uses: docker/setup-qemu-action@v3
with:
platforms: arm64,ppc64le
platforms: ${{ matrix.arch }}

- name: Install build tools
run: uv pip install --system -r requirements-dev.txt
run: uv pip install -r requirements-dev.txt

- name: Bump new dev version
if: github.event_name != 'release'
Expand All @@ -61,33 +101,12 @@ jobs:
git log -1

- name: Build sdist and wheels
run: |
if [ "${{ matrix.os }}" == "ubuntu-latest" ]; then
if [ "${{ github.event_name }}" == "pull_request" ]; then
./ci/build-wheel.sh "cp3{9,10,11,12,13}-manylinux*" --archs="x86_64"
else
./ci/build-wheel.sh --all
fi
elif [ "${{ matrix.os }}" == "macos-13" ]; then
./ci/build-wheel.sh "cp3{9,10}-*"
elif [ "${{ matrix.os }}" == "macos-14" ]; then
if [ "${{ github.event_name }}" == "pull_request" ]; then
./ci/build-wheel.sh "cp3{11,12,13}-*" --archs="arm64"
else
./ci/build-wheel.sh "cp3{11,12,13}-*"
fi
else
if [ "${{ github.event_name }}" == "pull_request" ]; then
./ci/build-wheel.sh "cp3{9,10,11,12,13}-*" --archs="AMD64"
else
./ci/build-wheel.sh --all
fi
fi
run: ./ci/build-wheel.sh "${{ matrix.tag }}"

- name: Upload the artifact
uses: actions/upload-artifact@v4
with:
name: cx-freeze-whl-${{ matrix.os }}
name: cx-freeze-whl-${{ matrix.os }}-job-${{ strategy.job-index }}
path: wheelhouse
compression-level: 0 # no compression

Expand Down
47 changes: 28 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ jobs:
defaults:
run:
shell: bash
env:
UV_SYSTEM_PYTHON: true
steps:

- uses: actions/checkout@v4
Expand All @@ -79,13 +81,14 @@ jobs:
with:
enable-cache: true
cache-dependency-glob: |
**/requirements.txt
**/tests/requirements.txt
requirements.txt
tests/requirements.txt

- name: Download the wheel
uses: actions/download-artifact@v4
with:
name: cx-freeze-whl-${{ matrix.os }}
merge-multiple: true
pattern: cx-freeze-whl-${{ matrix.os }}*
path: wheelhouse

- name: Install dependencies (Linux)
Expand All @@ -96,8 +99,8 @@ jobs:

- name: Install dependencies to test
run: |
uv pip install --system -r requirements.txt -r tests/requirements.txt
uv pip install --system cx_Freeze --no-index --no-deps -f wheelhouse --reinstall
uv pip install -r requirements.txt -r tests/requirements.txt
uv pip install cx_Freeze --no-index --no-deps -f wheelhouse --reinstall

- name: Generate coverage report
env:
Expand Down Expand Up @@ -127,6 +130,8 @@ jobs:
defaults:
run:
shell: bash
env:
UV_SYSTEM_PYTHON: true
steps:

- uses: actions/checkout@v4
Expand All @@ -140,26 +145,27 @@ jobs:
with:
enable-cache: true
cache-dependency-glob: |
**/requirements.txt
**/tests/requirements.txt
requirements.txt
tests/requirements.txt

- name: Download the wheel
uses: actions/download-artifact@v4
with:
name: cx-freeze-whl-${{ matrix.os }}
merge-multiple: true
pattern: cx-freeze-whl-${{ matrix.os }}*
path: wheelhouse

- name: Install dependencies to test
run: |
uv pip install --system -r requirements.txt -r tests/requirements.txt
uv pip install --system cx_Freeze --no-index --no-deps -f wheelhouse --reinstall
uv pip install -r requirements.txt -r tests/requirements.txt
uv pip install cx_Freeze --no-index --no-deps -f wheelhouse --reinstall

- name: Generate coverage report
run: |
if [ "${{ matrix.extra-requirement }}" == "lief-disabled" ]; then
export CX_FREEZE_BIND=imagehlp
else
uv pip install --system "${{ matrix.extra-requirement }}"
uv pip install "${{ matrix.extra-requirement }}"
fi
MATRIX_ID=${{ matrix.python-version }}.${{ matrix.os }}
SUFFIX=$(echo "${{ matrix.extra-requirement }}" | sed 's/==/-/')
Expand All @@ -169,7 +175,7 @@ jobs:
- name: Upload coverage reports
uses: actions/upload-artifact@v4
with:
name: cov-${{ matrix.python-version }}.${{ matrix.os }}-${{ hashFiles('.coverage.*') }}
name: cov-${{ matrix.python-version }}.${{ matrix.os }}-${{ strategy.job-index }}
path: .coverage.*
include-hidden-files: true

Expand All @@ -184,6 +190,8 @@ jobs:
defaults:
run:
shell: bash
env:
UV_SYSTEM_PYTHON: true
steps:

- uses: actions/checkout@v4
Expand All @@ -197,26 +205,27 @@ jobs:
with:
enable-cache: true
cache-dependency-glob: |
**/requirements.txt
**/tests/requirements.txt
requirements.txt
tests/requirements.txt

- name: Download the wheel
uses: actions/download-artifact@v4
with:
name: cx-freeze-whl-${{ matrix.os }}
merge-multiple: true
pattern: cx-freeze-whl-${{ matrix.os }}*
path: wheelhouse

- name: Install dependencies to test
run: |
uv pip install --system -r requirements.txt -r tests/requirements.txt
uv pip install --system cx_Freeze --no-index --no-deps -f wheelhouse --reinstall
uv pip install -r requirements.txt -r tests/requirements.txt
uv pip install cx_Freeze --no-index --no-deps -f wheelhouse --reinstall

- name: Install dependencies - extra
run: |
if [ "${{ matrix.python-version }}" == "3.10" ]; then
uv pip install --system -i https://pypi.anaconda.org/intel/simple numpy
uv pip install -i https://pypi.anaconda.org/intel/simple numpy
fi
uv pip install --system pandas
uv pip install pandas

- name: Generate coverage report
env:
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repos:


- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
rev: v0.8.4
hooks:
- id: ruff
args: ["--fix", "--unsafe-fixes"]
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ ifeq ($(PY_PLATFORM),win-amd64)
python -m pip install --upgrade uv --disable-pip-version-check;\
fi
else
curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL="$HOME/bin" sh
curl -LsSf https://astral.sh/uv/install.sh | env UV_UNMANAGED_INSTALL="$(HOME)/bin" sh
endif
if ! which pre-commit || ! [ -f .git/hooks/pre-commit ]; then\
UV_RESOLUTION=highest uv pip install --upgrade \
Expand Down
6 changes: 4 additions & 2 deletions ci/build-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ done

echo "::group::Install dependencies and build tools"
# Do not export UV_PYTHON to avoid conflict with uv in cibuildwheel macOS
UV_PYTHON=$($PYTHON -c "import sys; print(sys.executable, end='')")
UV_PYTHON=$UV_PYTHON UV_RESOLUTION=highest \
UV_RESOLUTION=highest \
uv pip install -r requirements.txt -r requirements-dev.txt
VERSION=$(bump-my-version show current_version 2>/dev/null | tr -d '\r\n')
if [[ $VERSION == *-* ]]; then
Expand All @@ -66,6 +65,9 @@ if [[ $PY_PLATFORM == linux* ]]; then
echo "::endgroup::"
fi
echo "::group::Build wheel(s)"
# Do not export UV_* to avoid conflict with uv in cibuildwheel macOS/Windows
unset UV_PYTHON
unset UV_SYSTEM_PYTHON
if [ "$BUILD_TAG" == "--only" ]; then
DIRTY=$(bump-my-version show scm_info.dirty 2>/dev/null | tr -d '\r\n')
FILEMASK=cx_Freeze-$VERSION_OK-$PYTHON_TAG-$PYTHON_TAG-$PLATFORM_TAG_MASK
Expand Down
Loading