Skip to content
Open
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
18 changes: 9 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build wheel
name: Build wheels

on:
release:
Expand Down Expand Up @@ -97,16 +97,16 @@ jobs:
git config user.name "Marcelo Duarte"
git config user.email marcelotduarte@users.noreply.github.com
SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct)
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 }}"
VERSION=$(uv version --short)
if (echo "$VERSION" | grep -q "\.dev"); then
uv version --no-sync --bump dev=$SOURCE_DATE_EPOCH
else
OPTIONAL=""
uv version --no-sync --bump patch --bump dev=$SOURCE_DATE_EPOCH
fi
VERSION_NEW=$VERSION_BASE$OPTIONAL-dev.$SOURCE_DATE_EPOCH
uvx bump-my-version bump --no-tag build --new-version=$VERSION_NEW 2>/dev/null
git log -1
NEW_VERSION=$(uv version --short)
git checkout -b build-$NEW_VERSION
git commit -m "Bump version: ${VERSION} → ${NEW_VERSION} [ci skip]" -a
git log -2

- name: Build sdist and wheels
run: ./ci/build-wheel.sh "${{ matrix.tag }}"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ jobs:
pattern: python-msilib-wheel-${{ matrix.os }}*
path: wheelhouse

- name: Install dependencies to test
- name: Install dependencies
run: |
uv pip install --extra tests --upgrade -r pyproject.toml
uv pip install -r pyproject.toml --upgrade --group tests
uv pip install python-msilib -f wheelhouse \
--no-build --no-deps --no-index --prerelease=allow --reinstall

Expand Down
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,13 @@ repos:
files: ^(
src/msilib/include/pythoncapi_compat.h|
src/msilib/include/.*.h|src/msilib/.*.c)$

- repo: local
hooks:
- id: requirements
name: requirements
language: system
entry: python ci/requirements.py
files: ^(pyproject.toml|requirements.txt|requirements-dev.txt|
tests/requirements.txt
)$
16 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,24 @@ cov: wheel

.PHONY: release
release:
bump-my-version show-bump 2>/dev/null
uv version
@echo "Run:"
@echo " bump-my-version bump <option>"
@echo " uv version <new-version>"
@echo "--or--"
@echo " bump-my-version bump patch --new-version=X.XX.X"
@echo " uv version --bump <major|minor|patch>"
@echo "--then--"
@echo " git push origin `git branch --show-current`"
@echo " git push origin `git branch --show-current` --tags"

.PHONY: release-dev
release-dev:
if (grep "current_version" pyproject.toml | grep -q "\-dev"); then\
bump-my-version bump --allow-dirty --no-tag build;\
git checkout -B release main
if (uv version --short | grep -q "\.dev"); then\
uv version --bump dev;\
else\
bump-my-version bump --allow-dirty --no-tag minor;\
uv version --bump patch --bump dev=0;\
fi
git commit -m "Bump dev version: `uv version --short` [ci skip]" -a
git push origin `git branch --show-current`
git push origin `git branch --show-current` --tags
git log -1
65 changes: 19 additions & 46 deletions ci/build-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ _CI_DIR=$(dirname "${BASH_SOURCE[0]}")
CI_DIR=$(cd "$_CI_DIR" && pwd)

# Python information (platform and version)
INSTALL_DIR="$HOME/bin"
INSTALL_TOOLS="1"
if [ -n "$UV_PYTHON" ]; then
if ! which uv &>/dev/null; then
# Install/update uv
"$CI_DIR/install-tools.sh"
"$CI_DIR/install-tools.sh" --dev
INSTALL_TOOLS="0"
fi
PYTHON=$(uv python find "$UV_PYTHON")
Expand Down Expand Up @@ -78,54 +79,30 @@ while [ -n "$1" ]; do
done

# Install/update uv and dev tools
INSTALL_DEV="0"
if [ "$IS_CONDA" == "1" ] || [ "$IS_MINGW" == "1" ]; then
if ! [ -e "$HOME/bin/bump-my-version" ]; then
INSTALL_DEV="1"
fi
else
if [[ $PY_PLATFORM == linux* ]]; then
if ! [ -e "$HOME/bin/bump-my-version" ] || \
! [ -e "$HOME/bin/cibuildwheel" ]; then
INSTALL_DEV="1"
fi
else
if ! which bump-my-version &>/dev/null || \
! which cibuildwheel &>/dev/null || \
! which pyproject-build &>/dev/null; then
INSTALL_DEV="1"
fi
fi
fi

if [ "$INSTALL_TOOLS" == "1" ] || [ "$INSTALL_DEV" == "1" ]; then
if [ "$INSTALL_DEV" == "1" ]; then
"$CI_DIR/install-tools.sh" --dev
else
"$CI_DIR/install-tools.sh"
fi
if [ "$INSTALL_TOOLS" == "1" ]; then
"$CI_DIR/install-tools.sh" --dev
fi

# Use of dev tools
_bump_my_version () {
_get_version () {
local value
if which bump-my-version &>/dev/null; then
value=$(bump-my-version "$*" 2>/dev/null)
elif [ -e "$HOME/bin/bump-my-version" ]; then
value=$("$HOME/bin/bump-my-version" "$*" 2>/dev/null)
value=$(uv version --short)
$PYTHON -c "print('$value'.replace('\r','').replace('\n',''), end='')"
}

_get_dirty () {
local value
if which git &>/dev/null; then
value=$(git status --short -uno | wc -l)
else
exit 1
value=1
fi
$PYTHON -c "print('$value'.replace('\r','').replace('\n',''), end='')"
}

_build_sdist () {
if [ "$IS_CONDA" == "1" ] || [ "$IS_MINGW" == "1" ]; then
$PYTHON -m build -n -x --sdist -o wheelhouse
elif [ -e "$HOME/bin/pyproject-build" ]; then
"$HOME/bin/pyproject-build" --sdist -o wheelhouse
elif which pyproject-build &>/dev/null; then
$PYTHON -m build --sdist -o wheelhouse
else
uv build -p "$PY_VERSION$PY_ABI_THREAD" --sdist -o wheelhouse
fi
Expand All @@ -146,18 +123,14 @@ _build_wheel () {
if [ "$CI" == "true" ] && [ "$IS_WINDOWS" == "1" ]; then
export UV_LINK_MODE=copy
fi
if [ -e "$HOME/bin/cibuildwheel" ]; then
"$HOME/bin/cibuildwheel" "$args"
else
$PYTHON -m cibuildwheel "$args"
fi
"$INSTALL_DIR/cibuildwheel" "$args"
fi
}

echo "::group::Project version"
NAME=$(grep -m1 "^name = " pyproject.toml | awk -F\" '{print $2}')
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
VERSION=$(_bump_my_version show current_version)
VERSION=$(_get_version)
if [ -z "$VERSION" ]; then
if [ -d src ]; then
FILENAME=src/$NORMALIZED_NAME/__init__.py
Expand Down Expand Up @@ -186,10 +159,10 @@ echo "Version: $VERSION ($NORMALIZED_VERSION)"
echo "::endgroup::"

mkdir -p wheelhouse >/dev/null
DIRTY=$(_bump_my_version show scm_info.dirty)
DIRTY=$(_get_dirty)
FILEMASK="$NORMALIZED_NAME-$NORMALIZED_VERSION"
FILEEXISTS=$(find "wheelhouse/$FILEMASK.tar.gz" 2>/dev/null || echo '')
if [ "$DIRTY" == "True" ] || [ -z "$FILEEXISTS" ]; then
if [ "$DIRTY" != "0" ] || [ -z "$FILEEXISTS" ]; then
echo "::group::Build sdist"
_build_sdist
echo "::endgroup::"
Expand All @@ -198,7 +171,7 @@ echo "::group::Build wheel(s)"
if [ "$BUILD_TAG" == "$BUILD_TAG_DEFAULT" ]; then
FILEMASK="$NORMALIZED_NAME-$NORMALIZED_VERSION-$PYTHON_TAG-$PYTHON_TAG$PY_ABI_THREAD-$PLATFORM_TAG_MASK"
FILEEXISTS=$(find "wheelhouse/$FILEMASK.whl" 2>/dev/null || echo '')
if [ "$DIRTY" == "True" ] || [ -z "$FILEEXISTS" ]; then
if [ "$DIRTY" != "0" ] || [ -z "$FILEEXISTS" ]; then
_build_wheel --only "$BUILD_TAG_DEFAULT"
fi
elif [ -n "$BUILD_TAG" ]; then
Expand Down
86 changes: 60 additions & 26 deletions ci/install-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,9 @@ else
fi

IS_CONDA=$([ -n "$CONDA_EXE" ] && echo "1")
IS_LINUX=$([[ $PY_PLATFORM == linux* ]] && echo "1")
IS_MINGW=$([[ $PY_PLATFORM == mingw* ]] && echo "1")
IS_WINDOWS=$([[ $PY_PLATFORM == win* ]] && echo "1")

# For Linux
PYTHON_FOR_DEV="3.12"

# Usage
if [ -n "$1" ] && [ "$1" == "--help" ]; then
echo "Usage:"
Expand All @@ -43,6 +39,8 @@ done
echo "::group::Install dependencies and build tools"
# Install/update uv and dev tools
if [ "$IS_CONDA" == "1" ]; then
# Conda Python 3.14: python-msilib is not available yet
PY_VERSION=$(python -c "import sysconfig; print(sysconfig.get_python_version(), end='')")
SYS_PLATFORM=$(python -c "import sys; print(sys.platform, end='')")
# Packages to install
pkgs=("uv" "python-build")
Expand All @@ -55,6 +53,9 @@ if [ "$IS_CONDA" == "1" ]; then
name=$(echo "$line" | awk -F '[><=]+' '{ print $1 }')
if [ "$name" == "cx-logging" ]; then name="cx_logging"; fi
if [ "$name" == "lief" ]; then name="py-lief"; fi
if [ "$name" == "python-msilib" ] && [ "$PY_VERSION" == "3.14" ]; then
continue
fi
if ! printf '%s\0' "${pkgs[@]}" | grep -Fxqz -- "$name"; then
pkgs+=("$name")
fi
Expand Down Expand Up @@ -89,6 +90,7 @@ elif [ "$IS_MINGW" == "1" ]; then
if [[ $line != *sys_platform* ]] || \
[[ $line == *sys_platform*==*win32* ]]; then
name=$(echo "$line" | awk -F '[><=]+' '{ print $1 }')
if [ "$name" == "python-msilib" ]; then name="msilib"; fi
if ! printf '%s\0' "${pkgs[@]}" | grep -Fxqz -- "$name"; then
pkgs+=("$MINGW_PACKAGE_PREFIX-python-$name")
fi
Expand Down Expand Up @@ -124,34 +126,66 @@ else
fi
fi

# Dependencies of the project
echo "Install packages"
if [ "$INSTALL_TESTS" == "1" ]; then
# including pytest and dependencies
uv pip install --extra tests --upgrade -r pyproject.toml
# Lief is not available for Python 3.13t and 3.14t
PY_VERSION=$(python -c "import sysconfig; print(sysconfig.get_python_version(), end='')")
PY_ABI_THREAD=$(python -c "import sysconfig; print(sysconfig.get_config_var('abi_thread') or '', end='')")
PY_VER_ABI="$PY_VERSION$PY_ABI_THREAD"
if [ "$IS_WINDOWS" == "1" ] && \
{ [ "$PY_VER_ABI" == "3.13t" ] || [ "$PY_VER_ABI" == "3.14t" ]; }; then
# Packages to install
pkgs=()

# Dependencies of the project
if [ -f requirements.txt ]; then
while read -r line; do
if [[ $line != *sys_platform* ]] || \
[[ $line == *sys_platform*==*win32* ]]; then
name=$(echo "$line" | awk -F '[><=]+' '{ print $1 }')
if [ "$name" == "lief" ]; then continue; fi
if [ "$name" == "tomli" ]; then continue; fi
name_and_version=$(echo "$line" | awk '{ print $1 }')
pkgs+=("$name_and_version")
fi
done < requirements.txt
fi

# pytest and dependencies
if [ "$INSTALL_TESTS" == "1" ] && [ -f tests/requirements.txt ]; then
while read -r line; do
name=$(echo "$line" | awk -F '[><=]+' '{ print $1 }')
pkgs+=("$name")
done < tests/requirements.txt
fi

echo "Install packages"
uv pip install --upgrade "${pkgs[@]}"

else
uv pip install --upgrade -r pyproject.toml
# Dependencies of the project
echo "Install packages"
if [ "$INSTALL_TESTS" == "1" ]; then
# including pytest and dependencies
uv pip install --upgrade -r pyproject.toml --group tests
else
uv pip install --upgrade -r pyproject.toml
fi
fi
fi

# Install dev tools
if [ "$INSTALL_DEV" == "1" ]; then
if [ "$IS_LINUX" == "1" ] || [ "$IS_MINGW" == "1" ] || \
[ "$IS_CONDA" == "1" ]; then
if [ -f requirements-dev.txt ]; then
while read -r line; do
name=$(echo "$line" | awk -F '[><=]+' '{ print $1 }')
filename=$INSTALL_DIR/$name
echo "Create $filename"
echo "#!/bin/bash"> "$filename"
echo "uvx -p $PYTHON_FOR_DEV \"$line\" \$@">> "$filename"
chmod +x "$filename"
done < requirements-dev.txt
fi
else
# macOS and Windows
uv pip install --extra dev --upgrade -r pyproject.toml
uv pip install --upgrade build
if [ -f requirements-dev.txt ]; then
PY_VERSION=$(python -c "import sysconfig; print(sysconfig.get_python_version(), end='')")
PY_ABI_THREAD=$(python -c "import sysconfig; print(sysconfig.get_config_var('abi_thread') or '', end='')")
PY_VER_ABI="$PY_VERSION$PY_ABI_THREAD"
while read -r line; do
name=$(echo "$line" | awk -F '[><=]+' '{ print $1 }')
filename=$INSTALL_DIR/$name
echo "Create $filename"
echo "#!/bin/bash"> "$filename"
echo "uvx -p $PY_VER_ABI \"$line\" \$@">> "$filename"
chmod +x "$filename"
done < requirements-dev.txt
fi
fi
echo "::endgroup::"
Loading
Loading