|
| 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