Skip to content

Commit 7fe05fe

Browse files
committed
feat(build): clean up build artifacts and optimize wheel installation process in Linux script
1 parent 5748fd2 commit 7fe05fe

File tree

1 file changed

+49
-20
lines changed

1 file changed

+49
-20
lines changed

scripts/build/build_linux.sh

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ echo "Installing build tools..."
3232
sudo apt-get update -qq
3333
sudo apt-get install -y binutils
3434

35+
# Save the original directory
36+
ORIGINAL_DIR="$(pwd)"
37+
38+
# Clean ALL build artifacts that might confuse PyInstaller
39+
echo "Cleaning build artifacts..."
40+
rm -rf build dist pyprophet.spec *.egg-info
41+
rm -rf .eggs
42+
# Clean any Python cache that might have source references
43+
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
44+
find . -type f -name "*.pyc" -delete 2>/dev/null || true
45+
find . -type f -name "*.pyo" -delete 2>/dev/null || true
46+
3547
# Install/upgrade build dependencies
3648
$PYTHON -m pip install --upgrade pip setuptools wheel cython numpy pyinstaller
3749

@@ -59,9 +71,20 @@ for dep in deps:
5971
continue
6072
PYEOF
6173

62-
# Build and install pyprophet as a wheel (cleanest approach)
63-
echo "Building and installing pyprophet package..."
74+
# Build pyprophet wheel in a completely isolated temp directory
75+
echo "Building pyprophet wheel in isolated directory..."
76+
WHEEL_BUILD_DIR=$(mktemp -d)
77+
cp -r "${ORIGINAL_DIR}"/* "${WHEEL_BUILD_DIR}/" 2>/dev/null || true
78+
cd "${WHEEL_BUILD_DIR}"
79+
6480
$PYTHON -m pip wheel --no-deps --wheel-dir /tmp/pyprophet_wheels .
81+
82+
# Return to original directory and clean up wheel build directory
83+
cd "${ORIGINAL_DIR}"
84+
rm -rf "${WHEEL_BUILD_DIR}"
85+
86+
# Install pyprophet from wheel
87+
echo "Installing pyprophet from wheel..."
6588
$PYTHON -m pip install --force-reinstall --no-deps /tmp/pyprophet_wheels/pyprophet-*.whl
6689

6790
# Verify installation
@@ -72,6 +95,10 @@ $PYTHON -c "import pyprophet; print(f'PyProphet installed at: {pyprophet.__file_
7295
SITE_PACKAGES=$($PYTHON -c "import pyprophet, os; print(os.path.dirname(pyprophet.__file__))")
7396
echo "PyProphet package location: ${SITE_PACKAGES}"
7497

98+
# Verify numpy is installed correctly (not from source)
99+
echo "Verifying numpy installation..."
100+
$PYTHON -c "import numpy; print(f'NumPy installed at: {numpy.__file__}'); import pandas; print('Pandas imports successfully')"
101+
75102
# Collect compiled extension binaries from the installed package
76103
ADD_BINARY_ARGS=()
77104
for so in "${SITE_PACKAGES}"/pyprophet/scoring/_optimized*.so; do
@@ -81,27 +108,29 @@ for so in "${SITE_PACKAGES}"/pyprophet/scoring/_optimized*.so; do
81108
fi
82109
done
83110

84-
# Save the original directory
85-
ORIGINAL_DIR="$(pwd)"
86-
87-
# Clean previous PyInstaller builds in original directory
88-
rm -rf build dist pyprophet.spec
89-
90111
# Create dist directory in original location
91112
mkdir -p "${ORIGINAL_DIR}/dist"
92113

93-
# Change to a temporary directory to avoid picking up source files
94-
# This ensures PyInstaller only sees installed packages
114+
# Change to a temporary directory to avoid picking up ANY source files
95115
BUILD_DIR=$(mktemp -d)
96116
echo "Using temporary build directory: ${BUILD_DIR}"
97117
cd "${BUILD_DIR}"
98118

99-
# Copy only the necessary files
119+
# Copy only the necessary files (NOT the entire source tree)
100120
cp "${ORIGINAL_DIR}/packaging/pyinstaller/run_pyprophet.py" .
101-
cp -r "${ORIGINAL_DIR}/packaging/pyinstaller/hooks" .
121+
mkdir -p hooks
122+
cp "${ORIGINAL_DIR}/packaging/pyinstaller/hooks"/*.py hooks/ 2>/dev/null || true
102123

103-
# Run PyInstaller in onefile mode (single executable)
124+
# Verify we're in a clean directory with no source pollution
125+
echo "Build directory contents:"
126+
ls -la
127+
128+
# Run PyInstaller in onefile mode
104129
echo "Running PyInstaller (onefile mode)..."
130+
echo "Current directory: $(pwd)"
131+
echo "Python sys.path will be:"
132+
$PYTHON -c "import sys; import pprint; pprint.pprint(sys.path)"
133+
105134
$PYTHON -m PyInstaller \
106135
--clean \
107136
--noconfirm \
@@ -125,15 +154,15 @@ $PYTHON -m PyInstaller \
125154
--exclude-module black \
126155
--exclude-module ruff \
127156
--collect-submodules pyprophet \
128-
--collect-all numpy \
129-
--collect-all pandas \
130-
--collect-all scipy \
131-
--collect-all sklearn \
132-
--collect-all pyopenms \
157+
--copy-metadata numpy \
158+
--copy-metadata pandas \
159+
--copy-metadata scipy \
160+
--copy-metadata sklearn \
161+
--copy-metadata scikit-learn \
162+
--copy-metadata pyopenms \
133163
--copy-metadata duckdb \
134164
--copy-metadata duckdb-extensions \
135165
--copy-metadata duckdb-extension-sqlite-scanner \
136-
--copy-metadata pyopenms \
137166
"${ADD_BINARY_ARGS[@]}" \
138167
run_pyprophet.py
139168

@@ -144,7 +173,7 @@ mv dist/pyprophet "${ORIGINAL_DIR}/dist/pyprophet"
144173
# Return to original directory
145174
cd "${ORIGINAL_DIR}"
146175

147-
# Clean up temporary build directory and wheel directory
176+
# Clean up temporary directories
148177
rm -rf "${BUILD_DIR}" /tmp/pyprophet_wheels
149178

150179
# NOTE: UPX compression is NOT applied on Linux because it breaks PyInstaller executables

0 commit comments

Comments
 (0)