Skip to content

Commit 7ec33f4

Browse files
committed
use search_file and fix EBPYTHONPREFIXES variable during tests
1 parent 482309d commit 7ec33f4

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

easybuild/easyblocks/generic/pythonpackage.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@
4949
from easybuild.framework.extensioneasyblock import ExtensionEasyBlock
5050
from easybuild.tools.build_log import EasyBuildError, print_msg
5151
from easybuild.tools.config import build_option, PYTHONPATH, EBPYTHONPREFIXES
52-
from easybuild.tools.filetools import change_dir, mkdir, read_file, remove_dir, symlink, which, write_file
53-
from easybuild.tools.filetools import find_glob_pattern
52+
from easybuild.tools.filetools import change_dir, mkdir, read_file, remove_dir, symlink, which, write_file, search_file
5453
from easybuild.tools.modules import ModEnvVarType, get_software_root
5554
from easybuild.tools.run import run_shell_cmd
5655
from easybuild.tools.utilities import nub
@@ -643,24 +642,14 @@ def using_ebpythonprefixes(self) -> bool:
643642
# Our sitecustomize.py adds paths in $EBPYTHONPREFIXES to the sitedir path though, allowing
644643
# these .pth files to work as expected. See: https://docs.python.org/3/library/site.html#module-site
645644
# .pth files always should be in the site folder, so most of the path is fixed.
646-
try:
647-
glob_pattern = "%s/lib/python*/site-packages/*.pth"
648-
# Try the installation directory first
649-
if find_glob_pattern(glob_pattern % self.installdir,
650-
fail_on_no_match=False):
651-
self.log.info("Found path configuration file in installation directory."
652-
"Enabling $EBPYTHONPREFIXES...")
653-
use_ebpythonprefixes = True
654-
# If we did a test installation, check that one as well
655-
if self.testinstall and find_glob_pattern(glob_pattern % self.pypkg_test_installdir,
656-
fail_on_no_match=False):
657-
self.log.info("Found path configuration file in test installation directory."
658-
"Enabling $EBPYTHONPREFIXES...")
659-
use_ebpythonprefixes = True
660-
except EasyBuildError:
661-
# find_glob_pattern found more than one match. This is still sufficient for us to assume
662-
# that we need $EBPYTHONPREFIXES.
663-
self.log.info("Found more than one match while searching for path configuration files."
645+
# Try the installation directory first
646+
if search_file([self.installdir], r".*\.pth$", silent=True):
647+
self.log.info("Found path configuration file in installation directory."
648+
"Enabling $EBPYTHONPREFIXES...")
649+
use_ebpythonprefixes = True
650+
# If we did a test installation, check that one as well
651+
if self.testinstall and search_file([self.pypkg_test_installdir], r".*\.pth$", silent=True):
652+
self.log.info("Found path configuration file in test installation directory."
664653
"Enabling $EBPYTHONPREFIXES...")
665654
use_ebpythonprefixes = True
666655

@@ -899,7 +888,7 @@ def test_step(self, return_output_ec=False):
899888
abs_pylibdirs = [os.path.join(actual_installdir, pylibdir) for pylibdir in self.all_pylibdirs]
900889
extrapath = "export PYTHONPATH=%s && " % os.pathsep.join(abs_pylibdirs + ['$PYTHONPATH'])
901890
if self.using_ebpythonprefixes():
902-
extrapath += "export EBPYTHONPREFIXES=%s && " % os.pathsep.join(abs_pylibdirs +
891+
extrapath += "export EBPYTHONPREFIXES=%s && " % os.pathsep.join([self.pypkg_test_installdir] +
903892
['$EBPYTHONPREFIXES'])
904893
extrapath += "export PATH=%s:$PATH && " % os.path.join(actual_installdir, 'bin')
905894

0 commit comments

Comments
 (0)