Skip to content

Commit 771ad84

Browse files
committed
enable same EBPYTHONPREFIXES changes in pythonbundle
1 parent 7ec33f4 commit 771ad84

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

easybuild/easyblocks/generic/pythonbundle.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from easybuild.tools.build_log import EasyBuildError
3636
from easybuild.tools.config import build_option, PYTHONPATH, EBPYTHONPREFIXES
3737
from easybuild.tools.modules import get_software_root
38+
from easybuild.tools.filetools import search_file
3839

3940

4041
class PythonBundle(Bundle):
@@ -123,6 +124,19 @@ def make_module_extra(self, *args, **kwargs):
123124
self.log.info("Preferred Python search path is $EBPYTHONPREFIXES, so using that")
124125
use_ebpythonprefixes = True
125126

127+
# Check if the installdir or sources contain any .pth files. For them to work correctly,
128+
# Python needs these files to be in the sitedir path. While this typically works system-wide
129+
# or in a venv, having Python modules in separate directories is unusual, and only having
130+
# $PYTHONPATH will ignore these files.
131+
# Our sitecustomize.py adds paths in $EBPYTHONPREFIXES to the sitedir path though, allowing
132+
# these .pth files to work as expected. See: https://docs.python.org/3/library/site.html#module-site
133+
# .pth files always should be in the site folder, so most of the path is fixed.
134+
# Try the installation directory first
135+
if self.installdir and search_file([self.installdir], r".*\.pth$", silent=True):
136+
self.log.info("Found path configuration file in installation directory. "
137+
"Enabling $EBPYTHONPREFIXES...")
138+
use_ebpythonprefixes = True
139+
126140
if self.multi_python or use_ebpythonprefixes:
127141
path = '' # EBPYTHONPREFIXES are relative to the install dir
128142
if path not in self.module_generator.added_paths_per_key[EBPYTHONPREFIXES]:

easybuild/easyblocks/generic/pythonpackage.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,15 +643,17 @@ def using_ebpythonprefixes(self) -> bool:
643643
# these .pth files to work as expected. See: https://docs.python.org/3/library/site.html#module-site
644644
# .pth files always should be in the site folder, so most of the path is fixed.
645645
# 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."
646+
if self.installdir and search_file([self.installdir], r".*\.pth$", silent=True):
647+
self.log.info("Found path configuration file in installation directory. "
653648
"Enabling $EBPYTHONPREFIXES...")
654649
use_ebpythonprefixes = True
650+
# If we did a test installation, check that one as well. Ensure that pypkg_test_installdir is set,
651+
# since that might not be the case for sanity_check_only or module_only.
652+
if self.testinstall and self.pypkg_test_installdir:
653+
if search_file([self.pypkg_test_installdir], r".*\.pth$", silent=True):
654+
self.log.info("Found path configuration file in test installation directory. "
655+
"Enabling $EBPYTHONPREFIXES...")
656+
use_ebpythonprefixes = True
655657

656658
return self.multi_python or use_ebpythonprefixes
657659

0 commit comments

Comments
 (0)