Skip to content

Commit

Permalink
utils/hooks: Fix result of is_module_satisfies() for packages not found.
Browse files Browse the repository at this point in the history
Previously, the module returned True, even if the package is not installed 
on the system.

Includes a test-case.

This fixes #3428.
  • Loading branch information
MagnumOpus21 authored and htgoebel committed Jun 28, 2018
1 parent c0819dd commit fd00db3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 6 additions & 2 deletions PyInstaller/utils/hooks/__init__.py
Expand Up @@ -490,8 +490,12 @@ class method (e.g., `idontevenknow<1.6,>1.9,!=1.9.6,<2.0a0,==2.4c1`) is
module_name = requirements_parsed.project_name
version = get_module_attribute(module_name, version_attr)

# Compare this version against the version parsed from these requirements.
return version in requirements_parsed
if not version:
# Module does not exist in the system.
return False
else:
# Compare this version against the one parsed from the requirements.
return version in requirements_parsed


def is_package(module_name):
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/test_hookutils.py
Expand Up @@ -15,7 +15,8 @@

from PyInstaller.utils.hooks import collect_data_files, collect_submodules, \
get_module_file_attribute, remove_prefix, remove_suffix, \
remove_file_extension, is_module_or_submodule
remove_file_extension, is_module_or_submodule, \
is_module_satisfies
from PyInstaller.compat import exec_python, ALL_SUFFIXES


Expand Down Expand Up @@ -188,6 +189,10 @@ def test_is_module_or_submodule():
assert not is_module_or_submodule('foo', 'foo.bar')


def test_is_module_satisfies_package_not_installed():
assert is_module_satisfies('pytest')
assert not is_module_satisfies('magnumopus-no-package-test-case')


_DATA_BASEPATH = join(TEST_MOD_PATH, TEST_MOD)
_DATA_PARAMS = [
Expand Down

0 comments on commit fd00db3

Please sign in to comment.