Skip to content

Commit

Permalink
utils/hooks: Fix crash when running from Python build directory.
Browse files Browse the repository at this point in the history
When running from a Python build directory (without installing), the prefix
for Makefile and config.h is none of the ones tested. So this routine did not
find a possible prefix, leading to an IndexError.

We must not add `dirname(filename)` to the list of prefixes to be tested,
since this would always win the "longest matching prefix" contest.
  • Loading branch information
htgoebel committed Aug 30, 2020
1 parent 1862d6b commit 4d66c7d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions PyInstaller/utils/hooks/__init__.py
Expand Up @@ -826,6 +826,9 @@ def _find_prefix(filename):
common = os.path.commonprefix([prefix, filename])
if common == prefix:
possible_prefixes.append(prefix)
if not possible_prefixes:
# no matching prefix, assume running from build directory
possible_prefixes = [os.path.dirname(filename)]
possible_prefixes.sort(key=lambda p: len(p), reverse=True)
return possible_prefixes[0]

Expand Down

0 comments on commit 4d66c7d

Please sign in to comment.