Skip to content

Commit

Permalink
feat: fast by default, --deep flag when needed
Browse files Browse the repository at this point in the history
Previous commit made fix-python way too slow for most use cases, but it
is still needed in some (e.g. PyQt).
This change introduces a flag `--deep` to look for every executable in
those specific use cases, but prevents being too slow in most use cases.
  • Loading branch information
GuillaumeDesforges committed Jan 15, 2025
1 parent e48a60c commit e9162f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ Usage: fix-python --venv .venv [--libs libs.nix] [--no-default-libs]
--no-default-libs: don't patch C++ standard libraries, glibc, and zlib by default
--gpu: enable GPU support
--with-torch: fix pytorch dependencies issues
--deep: looks for anything executable to patch, very slow but needed sometimes (e.g. PyQt)
--verbose: increase verbosity
```
15 changes: 13 additions & 2 deletions fix-python
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if [ "$1" = "--help" ]; then
echo "--no-default-libs: don't patch C++ standard libraries, glibc, and zlib by default" >&2
echo "--gpu: enable GPU support" >&2
echo "--with-torch: fix pytorch dependencies issues" >&2
echo "--deep: looks for anything executable to patch, very slow but needed sometimes (e.g. PyQt)" >&2
echo "--verbose: increase verbosity" >&2
exit 0
fi
Expand All @@ -50,6 +51,9 @@ while [ $# -gt 0 ]; do
--with-torch)
enable_torch="1"
;;
--deep)
deep="1"
;;
--verbose)
verbose="1"
;;
Expand Down Expand Up @@ -150,10 +154,17 @@ fi
# patch each binary file found in the virtual environment
# shellcheck disable=SC2156
echo "Searching for files to patch in $VENV_PATH" >&2
# NOTE: used to be faster, but `find -executable` is excluding too many files, see #19
binary_files=$(find "$(realpath "$VENV_PATH")" -type f -exec sh -c "file -i '{}' | grep -qE 'application/x-(executable|sharedlib); charset=binary'" \; -print)
if [ "$deep" ]; then
echo "Deep search for binary files" >&2
# For context, see #19
binary_files=$(find "$(realpath "$VENV_PATH")" -type f -exec sh -c "file -i '{}' | grep -qE 'application/x-(executable|sharedlib); charset=binary'" \; -print)
else
echo "Fast search for binary files" >&2
binary_files=$(find "$(realpath "$VENV_PATH")" -type f -executable -exec sh -c "file -i '{}' | grep -qE 'x-(.*); charset=binary'" \; -print)
fi
n_binary_files=$(wc -l <<< "$binary_files")
echo "Found $n_binary_files binary files" >&2

cat <<< "$binary_files" \
| while read -r file
do
Expand Down

0 comments on commit e9162f7

Please sign in to comment.