Skip to content

Commit 45f5adb

Browse files
Test frozen package version (#1055)
Add bash script to test package version in a frozen application version and a separate CI job to run it. Closes #1044. Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
1 parent 893bb43 commit 45f5adb

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,22 @@ jobs:
1212
uses: ./.github/workflows/coverage.yml
1313
docs:
1414
uses: ./.github/workflows/docs.yml
15+
frozen-version:
16+
runs-on: ubuntu-24.04
17+
steps:
18+
- uses: actions/checkout@v6
19+
with:
20+
fetch-depth: 0
21+
- uses: actions/setup-python@v6
22+
with:
23+
python-version: "3.x"
24+
- name: Run frozen version test
25+
run: bash mpmath/tests/test_version_frozen.sh
1526
tests:
1627
needs:
1728
- linter
1829
- coverage
30+
- frozen-version
1931
runs-on: ubuntu-24.04
2032
strategy:
2133
fail-fast: false
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
#
3+
# Test that the version number is provided correctly in a frozen (bundled)
4+
# executable (see #1044).
5+
6+
set -e
7+
8+
# Get the directory of the current repository
9+
MPMATH_DIR="$(realpath "$(dirname "$0")/../../")"
10+
echo "Repo mpmath directory: $MPMATH_DIR"
11+
12+
echo "Install requirements..."
13+
python3 -m pip install build pyinstaller
14+
15+
echo "Building the source distribution from the local repo..."
16+
python3 -m build --sdist
17+
18+
# Find and install the generated tarball
19+
TARBALL=$(ls -t dist/*.tar.gz | head -1)
20+
echo "Generated tarball: $TARBALL"
21+
22+
echo "Installing mpmath from tarball..."
23+
pip install dist/"$(basename $TARBALL)"
24+
25+
TEMP_DIR=$(mktemp -d)
26+
echo "Created temporary directory: $TEMP_DIR"
27+
cd "$TEMP_DIR"
28+
29+
# Create version_script.py that prints the package version
30+
cat << EOF > version_script.py
31+
import mpmath
32+
print(mpmath.__version__)
33+
EOF
34+
35+
# Save local version for later comparison
36+
DIRECT_VERSION="$(python3 -m mpmath --version)"
37+
38+
echo "Building version_script with PyInstaller..."
39+
pyinstaller --onefile --clean version_script.py
40+
41+
echo "Run frozen executable and extract the version from the output..."
42+
FROZEN_VERSION="$(./dist/version_script 2>&1)"
43+
44+
if [ "$DIRECT_VERSION" == "$FROZEN_VERSION" ]; then
45+
echo "Test passed: Version matches in frozen (bundled) executable."
46+
else
47+
echo "Test failed: Version mismatch."
48+
echo "Direct version: $DIRECT_VERSION"
49+
echo "Frozen version: $FROZEN_VERSION"
50+
exit 1
51+
fi

0 commit comments

Comments
 (0)