Skip to content
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
30 changes: 14 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,44 @@ SHELL=/bin/bash
PATH := $(shell python -c "import sysconfig; print(sysconfig.get_path('scripts'))"):$(PATH)

PY_PLATFORM := $(shell python -c "import sysconfig; print(sysconfig.get_platform())")
PRE_COMMIT_OPTIONS := --show-diff-on-failure --color=always --all-files --hook-stage=manual
PRE_COMMIT_OPTIONS := --show-diff-on-failure --color=always --all-files --hook-stage=manual --no-progress

COV_TMPDIR := $(shell mktemp -d)

.PHONY: all
all: install

.PHONY: pre-commit
pre-commit: install
@(pre-commit run $(PRE_COMMIT_OPTIONS) || true) | more
@pre-commit gc
.PHONY: prek
prek: install
@(prek run $(PRE_COMMIT_OPTIONS) || true) | more
@prek cache gc -q

.PHONY: clean
clean:
clean: uninstall
@rm -f .coverage* || true
@rm -rf build dist wheelhouse
@prek cache clean -q

.PHONY: install
install:
./ci/install-tools.sh --dev
if ! [ -f .git/hooks/pre-commit ]; then\
pre-commit install --install-hooks --overwrite -t pre-commit;\
prek install --install-hooks --overwrite -t pre-commit;\
fi

.PHONY: uninstall
uninstall:
@if [ -f .git/hooks/pre-commit ]; then\
pre-commit clean;\
pre-commit uninstall;\
rm -f .git/hooks/pre-commit;\
fi
@prek uninstall -q
@rm -f .git/hooks/pre-commit

.PHONY: upgrade
upgrade: uninstall clean install
pre-commit autoupdate
$(MAKE) pre-commit
upgrade: install
prek auto-update
$(MAKE) prek

.PHONY: wheel
wheel:
./ci/build-wheel.sh
./ci/build-wheel.sh --install

.PHONY: tests
tests: wheel
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ cx_Freeze's `bdist_msi` command to continue working in Python 3.13+.
[![Python](https://img.shields.io/pypi/pyversions/python-msilib)](https://www.python.org/)
[![Coverage](https://raw.githubusercontent.com/marcelotduarte/python-msilib/python-coverage-comment-action-data/badge.svg)](https://htmlpreview.github.io/?https://github.com/marcelotduarte/python-msilib/blob/python-coverage-comment-action-data/htmlcov/index.html)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![prek](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json)](https://github.com/j178/prek)

## Installation

Expand Down
58 changes: 32 additions & 26 deletions ci/build-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ else
PLATFORM_TAG_MASK="win*"
fi
fi
BUILD_TAG_DEFAULT="$PYTHON_TAG$PY_ABI_THREAD-$PLATFORM_TAG"
ZIP_SAFE=$(grep -m1 "^zip-safe = " pyproject.toml | awk '{print $3}')
if [ "$ZIP_SAFE" == "true" ]; then
BUILD_TAG_DEFAULT=py3-none-any
else
BUILD_TAG_DEFAULT="$PYTHON_TAG$PY_ABI_THREAD-$PLATFORM_TAG"
fi

# Usage
if [ -n "$1" ] && [ "$1" == "--help" ]; then
Expand All @@ -69,7 +74,11 @@ else
fi
while [ -n "$1" ]; do
if [ "$1" == "--all" ]; then
BUILD_TAG="cp3*-$PLATFORM_TAG"
if [ "$ZIP_SAFE" == "true" ]; then
BUILD_TAG="$BUILD_TAG_DEFAULT"
else
BUILD_TAG="cp3*-$PLATFORM_TAG"
fi
elif [ "$1" == "--install" ]; then
INSTALL="1"
else
Expand All @@ -84,12 +93,6 @@ if [ "$INSTALL_TOOLS" == "1" ]; then
fi

# Use of dev tools
_get_version () {
local value
value=$(uv version --short)
$PYTHON -c "print('$value'.replace('\r','').replace('\n',''), end='')"
}

_get_dirty () {
local value
if which git &>/dev/null; then
Expand All @@ -112,6 +115,8 @@ _build_wheel () {
local args=$*
if [ "$IS_CONDA" == "1" ] || [ "$IS_MINGW" == "1" ]; then
$PYTHON -m build -n -x --wheel -o wheelhouse
elif [ "$ZIP_SAFE" == "true" ]; then
uv build -p "$PY_VERSION$PY_ABI_THREAD" --wheel -o wheelhouse
elif [[ $PY_PLATFORM == win* ]] && [[ $args == *--only* ]]; then
uv build -p "$PY_VERSION$PY_ABI_THREAD" --wheel -o wheelhouse
elif [[ $PY_PLATFORM == macos* ]] && [[ $args == *--only* ]]; then
Expand All @@ -129,25 +134,22 @@ _build_wheel () {

echo "::group::Project version"
NAME=$(grep -m1 "^name = " pyproject.toml | awk -F\" '{print $2}')
VERSION=$(grep -m1 "^version = " pyproject.toml | awk -F\" '{print $2}')
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
VERSION=$(_get_version)
if [ -z "$VERSION" ]; then
if [ -d src ]; then
FILENAME=src/$NORMALIZED_NAME/__init__.py
if [ -d src ]; then
if [ -f "src/$NAME/__init__.py" ]; then
NORMALIZED_NAME=$NAME
else
FILENAME=$NAME/__init__.py
if ! [ -f "src/$NORMALIZED_NAME/__init__.py" ]; then
NAME=$(echo "$NAME" | awk -F- '{print $2}')
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
fi
fi
VERSION=$(grep "__version__ = " "$FILENAME" | awk -F\" '{print $2}')
fi
if [ -z "$VERSION" ]; then
NAME=$(echo "$NAME" | awk -F- '{print $2}')
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
if [ -d src ]; then
FILENAME=src/$NORMALIZED_NAME/__init__.py
else
FILENAME=$NAME/__init__.py
else
if ! [ -f "$NAME/__init__.py" ] && ! [ -f "$NORMALIZED_NAME/__init__.py" ]; then
NAME=$(echo "$NAME" | awk -F- '{print $2}')
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
fi
VERSION=$(grep "__version__ = " "$FILENAME" | awk -F\" '{print $2}')
fi
if [[ $VERSION == *-* ]]; then
NORMALIZED_VERSION=$($PYTHON -c "print(''.join('$VERSION'.replace('-','.').rsplit('.',1)), end='')")
Expand All @@ -169,7 +171,11 @@ if [ "$DIRTY" != "0" ] || [ -z "$FILEEXISTS" ]; then
fi
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"
if [ "$ZIP_SAFE" == "true" ]; then
FILEMASK="$NORMALIZED_NAME-$NORMALIZED_VERSION-$BUILD_TAG_DEFAULT"
else
FILEMASK="$NORMALIZED_NAME-$NORMALIZED_VERSION-$PYTHON_TAG-$PYTHON_TAG$PY_ABI_THREAD-$PLATFORM_TAG_MASK"
fi
FILEEXISTS=$(find "wheelhouse/$FILEMASK.whl" 2>/dev/null || echo '')
if [ "$DIRTY" != "0" ] || [ -z "$FILEEXISTS" ]; then
_build_wheel --only "$BUILD_TAG_DEFAULT"
Expand All @@ -184,11 +190,11 @@ echo "::endgroup::"
if [ "$INSTALL" == "1" ]; then
echo "::group::Install $NORMALIZED_NAME $NORMALIZED_VERSION"
if [[ $PY_PLATFORM == mingw* ]]; then
PIP_COMMAND="pip install --force-reinstall"
PIP_COMMAND="pip install --break-system-packages --force-reinstall"
else
PIP_COMMAND="uv pip install --no-build --prerelease=allow --reinstall"
fi
$PIP_COMMAND "$NORMALIZED_NAME==$NORMALIZED_VERSION" -f wheelhouse \
--no-deps --no-index
--no-deps --no-index
echo "::endgroup::"
fi
27 changes: 15 additions & 12 deletions ci/install-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mkdir -p "$INSTALL_DIR"

if which python &>/dev/null; then
PY_PLATFORM=$(python -c "import sysconfig; print(sysconfig.get_platform(), end='')")
elif ! [ -n "$MINGW_PACKAGE_PREFIX" ]; then
PY_PLATFORM="mingw"
else
PY_PLATFORM=""
fi
Expand Down Expand Up @@ -44,6 +46,9 @@ if [ "$IS_CONDA" == "1" ]; then
SYS_PLATFORM=$(python -c "import sys; print(sys.platform, end='')")
# Packages to install
pkgs=("uv" "python-build")
if which python &>/dev/null; then
pkgs+=("python=3.13")
fi

# Dependencies of the project
if [ -f requirements.txt ]; then
Expand Down Expand Up @@ -71,7 +76,7 @@ if [ "$IS_CONDA" == "1" ]; then
done < tests/requirements.txt
fi

# Install libmamba-solver and use it to speed up packages install
# Install libmamba-solver and use it to speed up packages installation
echo "Update conda to use libmamba-solver"
$CONDA_EXE clean --index-cache --logfiles --quiet --yes
$CONDA_EXE update -n base conda --quiet --yes
Expand All @@ -83,6 +88,9 @@ if [ "$IS_CONDA" == "1" ]; then
elif [ "$IS_MINGW" == "1" ]; then
# Packages to install
pkgs=("$MINGW_PACKAGE_PREFIX-uv" "$MINGW_PACKAGE_PREFIX-python-build")
if which python &>/dev/null; then
pkgs+=("$MINGW_PACKAGE_PREFIX-python")
fi

# Dependencies of the project
if [ -f requirements.txt ]; then
Expand Down Expand Up @@ -113,17 +121,12 @@ else
if [ "$IS_WINDOWS" == "1" ]; then
export UV_LINK_MODE=copy
fi
if ! which uv &>/dev/null; then
echo "error: Please install uv"
exit 1
fi
else
if which uv &>/dev/null; then
uv self -q update
else
curl -LsSf https://astral.sh/uv/install.sh | \
elif which uv &>/dev/null; then
uv self -q update
fi
if ! which uv &>/dev/null; then
curl -LsSf https://astral.sh/uv/install.sh | \
env UV_INSTALL_DIR="$INSTALL_DIR" sh
fi
fi

# Lief is not available for Python 3.13t and 3.14t
Expand Down Expand Up @@ -182,7 +185,7 @@ if [ "$INSTALL_DEV" == "1" ]; then
name=$(echo "$line" | awk -F '[><=]+' '{ print $1 }')
filename=$INSTALL_DIR/$name
echo "Create $filename"
echo "#!/bin/bash"> "$filename"
echo "#!/bin/sh"> "$filename"
echo "uvx -p $PY_VER_ABI \"$line\" \$@">> "$filename"
chmod +x "$filename"
done < requirements-dev.txt
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Documentation = "https://docs.python.org/3.12/library/msilib.html"
[dependency-groups]
dev = [
"cibuildwheel==3.3.1",
"pre-commit==4.5.1",
"prek==0.3.2",
]
tests = [
"coverage==7.13.4",
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
cibuildwheel==3.3.1
pre-commit==4.5.1
prek==0.3.2
Loading