Skip to content

Commit 76fec7b

Browse files
committed
take into account multi_deps when determining whether to use $PYTHONPATH or $EBPYTHONPREFIXES
1 parent 5eb6d07 commit 76fec7b

File tree

2 files changed

+39
-16
lines changed

2 files changed

+39
-16
lines changed

easybuild/framework/easyblock.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,12 +1401,27 @@ def make_module_pythonpath(self):
14011401
candidate_paths = (os.path.relpath(path, self.installdir) for path in glob.glob(python_subdir_pattern))
14021402
python_paths = [path for path in candidate_paths if re.match(r'lib/python\d+\.\d+/site-packages', path)]
14031403

1404+
# determine whether Python is a runtime dependency;
1405+
# if so, we assume it was installed with EasyBuild, and hence is aware of $EBPYTHONPREFIXES
14041406
runtime_deps = [dep['name'] for dep in self.cfg.dependencies(runtime_only=True)]
1405-
use_ebpythonprefixes = all([
1406-
'Python' in runtime_deps,
1407-
build_option('prefer_python_search_path') == EBPYTHONPREFIXES,
1408-
not self.cfg['force_pythonpath']
1409-
])
1407+
1408+
# don't use $EBPYTHONPREFIXES unless we can and it's preferred or necesary (due to use of multi_deps)
1409+
use_ebpythonprefixes = False
1410+
multi_deps = self.cfg['multi_deps']
1411+
1412+
if self.cfg['force_pythonpath']:
1413+
self.log.info("Using $PYTHONPATH to specify Python search path, since 'force_pythonpath' is set")
1414+
1415+
elif 'Python' in runtime_deps:
1416+
self.log.info("Found Python runtime dependency, so considering $EBPYTHONPREFIXES...")
1417+
1418+
if build_option('prefer_python_search_path') == EBPYTHONPREFIXES:
1419+
self.log.info("Preferred Python search path is $EBPYTHONPREFIXES, so using that")
1420+
use_ebpythonprefixes = True
1421+
1422+
elif multi_deps and 'Python' in multi_deps:
1423+
self.log.info("Python is listed in 'multi_deps', so using $EBPYTHONPREFIXES instead of $PYTHONPATH")
1424+
use_ebpythonprefixes = True
14101425

14111426
if python_paths:
14121427
# add paths unless they were already added

test/framework/toy_build.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4242,15 +4242,16 @@ def test_toy_python(self):
42424242
"""
42434243
Test whether $PYTHONPATH or $EBPYTHONPREFIXES are set correctly.
42444244
"""
4245-
# generate fake Python module that we can use as runtime dependency for toy
4245+
# generate fake Python modules that we can use as runtime dependency for toy
42464246
# (required condition for use of $EBPYTHONPREFIXES)
42474247
fake_mods_path = os.path.join(self.test_prefix, 'modules')
4248-
fake_python_mod = os.path.join(fake_mods_path, 'Python', '3.6')
4249-
if get_module_syntax() == 'Lua':
4250-
fake_python_mod += '.lua'
4251-
write_file(fake_python_mod, '')
4252-
else:
4253-
write_file(fake_python_mod, '#%Module')
4248+
for pyver in ('2.7', '3.6'):
4249+
fake_python_mod = os.path.join(fake_mods_path, 'Python', pyver)
4250+
if get_module_syntax() == 'Lua':
4251+
fake_python_mod += '.lua'
4252+
write_file(fake_python_mod, '')
4253+
else:
4254+
write_file(fake_python_mod, '#%Module')
42544255
self.modtool.use(fake_mods_path)
42554256

42564257
test_ecs = os.path.join(os.path.dirname(__file__), 'easyconfigs', 'test_ecs')
@@ -4284,20 +4285,27 @@ def test_toy_python(self):
42844285
self.assertTrue(pythonpath_regex.search(toy_mod_txt),
42854286
f"Pattern '{pythonpath_regex.pattern}' found in: {toy_mod_txt}")
42864287

4287-
test_ec_txt += "\ndependencies = [('Python', '3.6', '', SYSTEM)]"
4288-
write_file(test_ec, test_ec_txt)
4288+
# if Python is listed as runtime dependency, then $EBPYTHONPREFIXES is used if it's preferred
4289+
write_file(test_ec, test_ec_txt + "\ndependencies = [('Python', '3.6', '', SYSTEM)]")
42894290
self.run_test_toy_build_with_output(ec_file=test_ec, extra_args=args)
42904291
toy_mod_txt = read_file(toy_mod)
42914292

42924293
ebpythonprefixes_regex = re.compile('^prepend.path.*EBPYTHONPREFIXES.*root', re.M)
42934294
self.assertTrue(ebpythonprefixes_regex.search(toy_mod_txt),
42944295
f"Pattern '{ebpythonprefixes_regex.pattern}' found in: {toy_mod_txt}")
42954296

4296-
test_ec_txt += "\nforce_pythonpath = True"
4297-
write_file(test_ec, test_ec_txt)
4297+
# if Python is listed in multi_deps, then $EBPYTHONPREFIXES is used, even if it's not explicitely preferred
4298+
write_file(test_ec, test_ec_txt + "\nmulti_deps = {'Python': ['2.7', '3.6']}")
42984299
self.run_test_toy_build_with_output(ec_file=test_ec)
42994300
toy_mod_txt = read_file(toy_mod)
43004301

4302+
self.assertTrue(ebpythonprefixes_regex.search(toy_mod_txt),
4303+
f"Pattern '{ebpythonprefixes_regex.pattern}' found in: {toy_mod_txt}")
4304+
4305+
write_file(test_ec, test_ec_txt + "\ndependencies = [('Python', '3.6', '', SYSTEM)]\nforce_pythonpath = True")
4306+
self.run_test_toy_build_with_output(ec_file=test_ec, extra_args=args)
4307+
toy_mod_txt = read_file(toy_mod)
4308+
43014309
self.assertTrue(pythonpath_regex.search(toy_mod_txt),
43024310
f"Pattern '{pythonpath_regex.pattern}' found in: {toy_mod_txt}")
43034311

0 commit comments

Comments
 (0)