Skip to content

Commit

Permalink
Use new --prefer-python-search-path
Browse files Browse the repository at this point in the history
  • Loading branch information
Micket committed Sep 20, 2024
1 parent 0d7b4ca commit a663110
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
15 changes: 8 additions & 7 deletions easybuild/easyblocks/generic/pythonbundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import sys

from easybuild.easyblocks.generic.bundle import Bundle
from easybuild.easyblocks.generic.pythonpackage import EBPYTHONPREFIXES, EXTS_FILTER_PYTHON_PACKAGES
from easybuild.easyblocks.generic.pythonpackage import EXTS_FILTER_PYTHON_PACKAGES
from easybuild.easyblocks.generic.pythonpackage import PythonPackage, get_pylibdirs, pick_python_cmd
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.config import build_option
from easybuild.tools.config import build_option, PYTHONPATH, EBPYTHONPREFIXES
from easybuild.tools.filetools import which
from easybuild.tools.modules import get_software_root
import easybuild.tools.environment as env
Expand Down Expand Up @@ -145,10 +145,11 @@ def make_module_extra(self, *args, **kwargs):
# or if we prefer it
runtime_deps = [dep['name'] for dep in self.cfg.dependencies(runtime_only=True)]
use_ebpythonprefixes = 'Python' in runtime_deps and \
build_option('prefer_ebpythonprefixes') and self.cfg['prefer_ebpythonprefixes']
build_option('prefer_python_search_path') == EBPYTHONPREFIXES and not self.cfg['force_pythonpath']
if self.multi_python or use_ebpythonprefixes:
if EBPYTHONPREFIXES not in self.module_generator.added_paths_per_key:
txt += self.module_generator.prepend_paths(EBPYTHONPREFIXES, '')
path = '' # EBPYTHONPREFIXES are relative to the install dir
if path not in self.module_generator.added_paths_per_key[EBPYTHONPREFIXES]:
txt += self.module_generator.prepend_paths(EBPYTHONPREFIXES, path)
else:

# the temporary module file that is generated before installing extensions
Expand All @@ -163,8 +164,8 @@ def make_module_extra(self, *args, **kwargs):
]

for pylibdir in new_pylibdirs:
if pylibdir not in self.module_generator.added_paths_per_key['PYTHONPATH']:
txt += self.module_generator.prepend_paths('PYTHONPATH', pylibdir)
if pylibdir not in self.module_generator.added_paths_per_key[PYTHONPATH]:
txt += self.module_generator.prepend_paths(PYTHONPATH, pylibdir)

return txt

Expand Down
11 changes: 6 additions & 5 deletions easybuild/easyblocks/generic/pythonpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@

import easybuild.tools.environment as env
from easybuild.base import fancylogger
from easybuild.easyblocks.python import EBPYTHONPREFIXES, EXTS_FILTER_PYTHON_PACKAGES
from easybuild.easyblocks.python import EXTS_FILTER_PYTHON_PACKAGES
from easybuild.framework.easyconfig import CUSTOM
from easybuild.framework.easyconfig.default import DEFAULT_CONFIG
from easybuild.framework.easyconfig.templates import PYPI_SOURCE
from easybuild.framework.extensioneasyblock import ExtensionEasyBlock
from easybuild.tools.build_log import EasyBuildError, print_msg
from easybuild.tools.config import build_option
from easybuild.tools.config import build_option, PYTHONPATH, EBPYTHONPREFIXES
from easybuild.tools.filetools import change_dir, mkdir, remove_dir, symlink, which
from easybuild.tools.modules import get_software_root
from easybuild.tools.run import run_shell_cmd, subprocess_popen_text
Expand Down Expand Up @@ -1143,15 +1143,16 @@ def make_module_extra(self, *args, **kwargs):
# or if we prefer it
runtime_deps = [dep['name'] for dep in self.cfg.dependencies(runtime_only=True)]
use_ebpythonprefixes = 'Python' in runtime_deps and \
build_option('prefer_ebpythonprefixes') and self.cfg['prefer_ebpythonprefixes']
build_option('prefer_python_search_path') == EBPYTHONPREFIXES and not self.cfg['force_pythonpath']
if self.multi_python or use_ebpythonprefixes:
txt += self.module_generator.prepend_paths(EBPYTHONPREFIXES, '')
path = '' # EBPYTHONPREFIXES are relative to the install dir
text += self.module_generator.prepend_paths(EBPYTHONPREFIXES, path)
elif self.require_python:
self.set_pylibdirs()
for path in self.all_pylibdirs:
fullpath = os.path.join(self.installdir, path)
# only extend $PYTHONPATH with existing, non-empty directories
if os.path.exists(fullpath) and os.listdir(fullpath):
txt += self.module_generator.prepend_paths('PYTHONPATH', path)
txt += self.module_generator.prepend_paths(PYTHONPATH, path)

return super(PythonPackage, self).make_module_extra(txt, *args, **kwargs)
6 changes: 2 additions & 4 deletions easybuild/easyblocks/p/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from easybuild.framework.easyconfig import CUSTOM
from easybuild.framework.easyconfig.templates import PYPI_SOURCE
from easybuild.tools.build_log import EasyBuildError, print_warning
from easybuild.tools.config import build_option, ERROR, log_path
from easybuild.tools.config import build_option, ERROR, log_path, PYTHONPATH, EBPYTHONPREFIXES
from easybuild.tools.modules import get_software_libdir, get_software_root, get_software_version
from easybuild.tools.filetools import apply_regex_substitutions, change_dir, mkdir
from easybuild.tools.filetools import read_file, remove_dir, symlink, write_file
Expand All @@ -59,8 +59,6 @@
# magic value for unlimited stack size
UNLIMITED = 'unlimited'

EBPYTHONPREFIXES = 'EBPYTHONPREFIXES'

# We want the following import order:
# 1. Packages installed into VirtualEnv
# 2. Packages installed into $EBPYTHONPREFIXES (e.g. our modules)
Expand Down Expand Up @@ -643,6 +641,6 @@ def make_module_extra(self, *args, **kwargs):
txt = super(EB_Python, self).make_module_extra()

if self.cfg.get('ebpythonprefixes'):
txt += self.module_generator.prepend_paths('PYTHONPATH', self.pythonpath)
txt += self.module_generator.prepend_paths(PYTHONPATH, self.pythonpath)

return txt

0 comments on commit a663110

Please sign in to comment.