Skip to content

Commit 1d7497d

Browse files
Switch to prek (#79)
1 parent abf79cc commit 1d7497d

6 files changed

Lines changed: 64 additions & 56 deletions

File tree

Makefile

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,44 @@ SHELL=/bin/bash
33
PATH := $(shell python -c "import sysconfig; print(sysconfig.get_path('scripts'))"):$(PATH)
44

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

88
COV_TMPDIR := $(shell mktemp -d)
99

1010
.PHONY: all
1111
all: install
1212

13-
.PHONY: pre-commit
14-
pre-commit: install
15-
@(pre-commit run $(PRE_COMMIT_OPTIONS) || true) | more
16-
@pre-commit gc
13+
.PHONY: prek
14+
prek: install
15+
@(prek run $(PRE_COMMIT_OPTIONS) || true) | more
16+
@prek cache gc -q
1717

1818
.PHONY: clean
19-
clean:
19+
clean: uninstall
2020
@rm -f .coverage* || true
2121
@rm -rf build dist wheelhouse
22+
@prek cache clean -q
2223

2324
.PHONY: install
2425
install:
2526
./ci/install-tools.sh --dev
2627
if ! [ -f .git/hooks/pre-commit ]; then\
27-
pre-commit install --install-hooks --overwrite -t pre-commit;\
28+
prek install --install-hooks --overwrite -t pre-commit;\
2829
fi
2930

3031
.PHONY: uninstall
3132
uninstall:
32-
@if [ -f .git/hooks/pre-commit ]; then\
33-
pre-commit clean;\
34-
pre-commit uninstall;\
35-
rm -f .git/hooks/pre-commit;\
36-
fi
33+
@prek uninstall -q
34+
@rm -f .git/hooks/pre-commit
3735

3836
.PHONY: upgrade
39-
upgrade: uninstall clean install
40-
pre-commit autoupdate
41-
$(MAKE) pre-commit
37+
upgrade: install
38+
prek auto-update
39+
$(MAKE) prek
4240

4341
.PHONY: wheel
4442
wheel:
45-
./ci/build-wheel.sh
43+
./ci/build-wheel.sh --install
4644

4745
.PHONY: tests
4846
tests: wheel

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ cx_Freeze's `bdist_msi` command to continue working in Python 3.13+.
1212
[![Python](https://img.shields.io/pypi/pyversions/python-msilib)](https://www.python.org/)
1313
[![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)
1414
[![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)
15+
[![prek](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/j178/prek/master/docs/assets/badge-v0.json)](https://github.com/j178/prek)
1516

1617
## Installation
1718

ci/build-wheel.sh

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ else
4747
PLATFORM_TAG_MASK="win*"
4848
fi
4949
fi
50-
BUILD_TAG_DEFAULT="$PYTHON_TAG$PY_ABI_THREAD-$PLATFORM_TAG"
50+
ZIP_SAFE=$(grep -m1 "^zip-safe = " pyproject.toml | awk '{print $3}')
51+
if [ "$ZIP_SAFE" == "true" ]; then
52+
BUILD_TAG_DEFAULT=py3-none-any
53+
else
54+
BUILD_TAG_DEFAULT="$PYTHON_TAG$PY_ABI_THREAD-$PLATFORM_TAG"
55+
fi
5156

5257
# Usage
5358
if [ -n "$1" ] && [ "$1" == "--help" ]; then
@@ -69,7 +74,11 @@ else
6974
fi
7075
while [ -n "$1" ]; do
7176
if [ "$1" == "--all" ]; then
72-
BUILD_TAG="cp3*-$PLATFORM_TAG"
77+
if [ "$ZIP_SAFE" == "true" ]; then
78+
BUILD_TAG="$BUILD_TAG_DEFAULT"
79+
else
80+
BUILD_TAG="cp3*-$PLATFORM_TAG"
81+
fi
7382
elif [ "$1" == "--install" ]; then
7483
INSTALL="1"
7584
else
@@ -84,12 +93,6 @@ if [ "$INSTALL_TOOLS" == "1" ]; then
8493
fi
8594

8695
# Use of dev tools
87-
_get_version () {
88-
local value
89-
value=$(uv version --short)
90-
$PYTHON -c "print('$value'.replace('\r','').replace('\n',''), end='')"
91-
}
92-
9396
_get_dirty () {
9497
local value
9598
if which git &>/dev/null; then
@@ -112,6 +115,8 @@ _build_wheel () {
112115
local args=$*
113116
if [ "$IS_CONDA" == "1" ] || [ "$IS_MINGW" == "1" ]; then
114117
$PYTHON -m build -n -x --wheel -o wheelhouse
118+
elif [ "$ZIP_SAFE" == "true" ]; then
119+
uv build -p "$PY_VERSION$PY_ABI_THREAD" --wheel -o wheelhouse
115120
elif [[ $PY_PLATFORM == win* ]] && [[ $args == *--only* ]]; then
116121
uv build -p "$PY_VERSION$PY_ABI_THREAD" --wheel -o wheelhouse
117122
elif [[ $PY_PLATFORM == macos* ]] && [[ $args == *--only* ]]; then
@@ -129,25 +134,22 @@ _build_wheel () {
129134

130135
echo "::group::Project version"
131136
NAME=$(grep -m1 "^name = " pyproject.toml | awk -F\" '{print $2}')
137+
VERSION=$(grep -m1 "^version = " pyproject.toml | awk -F\" '{print $2}')
132138
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
133-
VERSION=$(_get_version)
134-
if [ -z "$VERSION" ]; then
135-
if [ -d src ]; then
136-
FILENAME=src/$NORMALIZED_NAME/__init__.py
139+
if [ -d src ]; then
140+
if [ -f "src/$NAME/__init__.py" ]; then
141+
NORMALIZED_NAME=$NAME
137142
else
138-
FILENAME=$NAME/__init__.py
143+
if ! [ -f "src/$NORMALIZED_NAME/__init__.py" ]; then
144+
NAME=$(echo "$NAME" | awk -F- '{print $2}')
145+
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
146+
fi
139147
fi
140-
VERSION=$(grep "__version__ = " "$FILENAME" | awk -F\" '{print $2}')
141-
fi
142-
if [ -z "$VERSION" ]; then
143-
NAME=$(echo "$NAME" | awk -F- '{print $2}')
144-
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
145-
if [ -d src ]; then
146-
FILENAME=src/$NORMALIZED_NAME/__init__.py
147-
else
148-
FILENAME=$NAME/__init__.py
148+
else
149+
if ! [ -f "$NAME/__init__.py" ] && ! [ -f "$NORMALIZED_NAME/__init__.py" ]; then
150+
NAME=$(echo "$NAME" | awk -F- '{print $2}')
151+
NORMALIZED_NAME=$(echo "$NAME" | tr '[:upper:]' '[:lower:]' | tr '-' '_')
149152
fi
150-
VERSION=$(grep "__version__ = " "$FILENAME" | awk -F\" '{print $2}')
151153
fi
152154
if [[ $VERSION == *-* ]]; then
153155
NORMALIZED_VERSION=$($PYTHON -c "print(''.join('$VERSION'.replace('-','.').rsplit('.',1)), end='')")
@@ -169,7 +171,11 @@ if [ "$DIRTY" != "0" ] || [ -z "$FILEEXISTS" ]; then
169171
fi
170172
echo "::group::Build wheel(s)"
171173
if [ "$BUILD_TAG" == "$BUILD_TAG_DEFAULT" ]; then
172-
FILEMASK="$NORMALIZED_NAME-$NORMALIZED_VERSION-$PYTHON_TAG-$PYTHON_TAG$PY_ABI_THREAD-$PLATFORM_TAG_MASK"
174+
if [ "$ZIP_SAFE" == "true" ]; then
175+
FILEMASK="$NORMALIZED_NAME-$NORMALIZED_VERSION-$BUILD_TAG_DEFAULT"
176+
else
177+
FILEMASK="$NORMALIZED_NAME-$NORMALIZED_VERSION-$PYTHON_TAG-$PYTHON_TAG$PY_ABI_THREAD-$PLATFORM_TAG_MASK"
178+
fi
173179
FILEEXISTS=$(find "wheelhouse/$FILEMASK.whl" 2>/dev/null || echo '')
174180
if [ "$DIRTY" != "0" ] || [ -z "$FILEEXISTS" ]; then
175181
_build_wheel --only "$BUILD_TAG_DEFAULT"
@@ -184,11 +190,11 @@ echo "::endgroup::"
184190
if [ "$INSTALL" == "1" ]; then
185191
echo "::group::Install $NORMALIZED_NAME $NORMALIZED_VERSION"
186192
if [[ $PY_PLATFORM == mingw* ]]; then
187-
PIP_COMMAND="pip install --force-reinstall"
193+
PIP_COMMAND="pip install --break-system-packages --force-reinstall"
188194
else
189195
PIP_COMMAND="uv pip install --no-build --prerelease=allow --reinstall"
190196
fi
191197
$PIP_COMMAND "$NORMALIZED_NAME==$NORMALIZED_VERSION" -f wheelhouse \
192-
--no-deps --no-index
198+
--no-deps --no-index
193199
echo "::endgroup::"
194200
fi

ci/install-tools.sh

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mkdir -p "$INSTALL_DIR"
55

66
if which python &>/dev/null; then
77
PY_PLATFORM=$(python -c "import sysconfig; print(sysconfig.get_platform(), end='')")
8+
elif ! [ -n "$MINGW_PACKAGE_PREFIX" ]; then
9+
PY_PLATFORM="mingw"
810
else
911
PY_PLATFORM=""
1012
fi
@@ -44,6 +46,9 @@ if [ "$IS_CONDA" == "1" ]; then
4446
SYS_PLATFORM=$(python -c "import sys; print(sys.platform, end='')")
4547
# Packages to install
4648
pkgs=("uv" "python-build")
49+
if which python &>/dev/null; then
50+
pkgs+=("python=3.13")
51+
fi
4752

4853
# Dependencies of the project
4954
if [ -f requirements.txt ]; then
@@ -71,7 +76,7 @@ if [ "$IS_CONDA" == "1" ]; then
7176
done < tests/requirements.txt
7277
fi
7378

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

8795
# Dependencies of the project
8896
if [ -f requirements.txt ]; then
@@ -113,17 +121,12 @@ else
113121
if [ "$IS_WINDOWS" == "1" ]; then
114122
export UV_LINK_MODE=copy
115123
fi
116-
if ! which uv &>/dev/null; then
117-
echo "error: Please install uv"
118-
exit 1
119-
fi
120-
else
121-
if which uv &>/dev/null; then
122-
uv self -q update
123-
else
124-
curl -LsSf https://astral.sh/uv/install.sh | \
124+
elif which uv &>/dev/null; then
125+
uv self -q update
126+
fi
127+
if ! which uv &>/dev/null; then
128+
curl -LsSf https://astral.sh/uv/install.sh | \
125129
env UV_INSTALL_DIR="$INSTALL_DIR" sh
126-
fi
127130
fi
128131

129132
# Lief is not available for Python 3.13t and 3.14t
@@ -182,7 +185,7 @@ if [ "$INSTALL_DEV" == "1" ]; then
182185
name=$(echo "$line" | awk -F '[><=]+' '{ print $1 }')
183186
filename=$INSTALL_DIR/$name
184187
echo "Create $filename"
185-
echo "#!/bin/bash"> "$filename"
188+
echo "#!/bin/sh"> "$filename"
186189
echo "uvx -p $PY_VER_ABI \"$line\" \$@">> "$filename"
187190
chmod +x "$filename"
188191
done < requirements-dev.txt

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Documentation = "https://docs.python.org/3.12/library/msilib.html"
4747
[dependency-groups]
4848
dev = [
4949
"cibuildwheel==3.3.1",
50-
"pre-commit==4.5.1",
50+
"prek==0.3.2",
5151
]
5252
tests = [
5353
"coverage==7.13.4",

requirements-dev.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
cibuildwheel==3.3.1
2-
pre-commit==4.5.1
2+
prek==0.3.2

0 commit comments

Comments
 (0)