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: use uvx w/ bump-my-version and cibuildwheel #2755

Merged
merged 3 commits into from
Dec 29, 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
7 changes: 2 additions & 5 deletions .github/workflows/build-wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,21 @@ jobs:
with:
platforms: ${{ matrix.arch }}

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

- name: Bump new dev version
if: github.event_name != 'release'
run: |
git config user.name "Marcelo Duarte"
git config user.email marcelotduarte@users.noreply.github.com
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
VERSION=$(bump-my-version show current_version 2>/dev/null)
VERSION=$(uvx bump-my-version show current_version 2>/dev/null)
VERSION_BASE=$(python -c "print('$VERSION'.rsplit('-',1)[0])")
if [ "${{ github.event_name }}" == "pull_request" ]; then
OPTIONAL=".${{ github.event.number }}"
else
OPTIONAL=""
fi
VERSION_NEW=$VERSION_BASE$OPTIONAL-dev.$SOURCE_DATE_EPOCH
bump-my-version bump --no-tag build --new-version=$VERSION_NEW 2>/dev/null
uvx bump-my-version bump --no-tag build --new-version=$VERSION_NEW 2>/dev/null
git log -1

- name: Build sdist and wheels
Expand Down
43 changes: 32 additions & 11 deletions ci/build-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ else
PLATFORM_TAG_MASK=$(echo $PLATFORM_TAG | sed 's/_/*/')
fi

# Usage
if ! [ -z "$1" ] && [ "$1" == "--help" ]; then
echo "Usage:"
echo "$0 [--all|TAG] [--archs=ARCHS]"
Expand Down Expand Up @@ -46,11 +47,34 @@ while ! [ -z "$1" ]; do
shift
done

# Functions and commands
_verlte() {
echo -e $(echo -e "$1\n$2" | sort -V | head -n1)
}

_vergte() {
echo -e $(echo -e "$1\n$2" | sort -V -r | head -n1)
}

_bump_my_version () {
local args=$*
# Use python <= 3.12 (python 3.13t is not supported)
local py_version=$(_verlte $PY_VERSION 3.12)
echo $(uvx -p $py_version bump-my-version $args 2>/dev/null | tr -d '\r\n')
}

_cibuildwheel () {
local args=$*
# Use python >= 3.11
local py_version=$(_vergte $PY_VERSION 3.11)
# Do not export UV_* to avoid conflict with uv in cibuildwheel macOS/Windows
unset UV_SYSTEM_PYTHON
uvx -p $py_version cibuildwheel $args
}

echo "::group::Install dependencies and build tools"
# Do not export UV_PYTHON to avoid conflict with uv in cibuildwheel macOS
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')
UV_RESOLUTION=highest uv pip install -r requirements.txt
VERSION=$(_bump_my_version show current_version)
if [[ $VERSION == *-* ]]; then
VERSION_OK=$($PYTHON -c "print(''.join('$VERSION'.replace('-','.').rsplit('.',1)), end='')")
else
Expand All @@ -65,24 +89,21 @@ 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')
DIRTY=$(_bump_my_version show scm_info.dirty)
FILEMASK=cx_Freeze-$VERSION_OK-$PYTHON_TAG-$PYTHON_TAG-$PLATFORM_TAG_MASK
FILEEXISTS=$(ls wheelhouse/$FILEMASK.whl 2>/dev/null || echo '')
if [ "$DIRTY" != "False" ] || [ -z "$FILEEXISTS" ]; then
if [[ $PY_PLATFORM == win* ]]; then
uv build --no-build-isolation --wheel -o wheelhouse
else
cibuildwheel --only $PYTHON_TAG-$PLATFORM_TAG --prerelease-pythons
_cibuildwheel --only $PYTHON_TAG-$PLATFORM_TAG
fi
fi
elif ! [ -z "$BUILD_TAG" ]; then
CIBW_BUILD="$BUILD_TAG" cibuildwheel $ARCHS
CIBW_BUILD="$BUILD_TAG" _cibuildwheel $ARCHS
else
cibuildwheel $ARCHS
_cibuildwheel $ARCHS
fi
echo "::endgroup::"

Expand Down
Loading