Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance EasyBuildMeta easyblock: auto-enable installing with pip + fix setup.py of easyconfigs package so installation with setuptools >= 61.0 works #2805

Merged
merged 5 commits into from
Oct 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 44 additions & 3 deletions easybuild/easyblocks/e/easybuildmeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import sys
from distutils.version import LooseVersion

from easybuild.easyblocks.generic.pythonpackage import PythonPackage
from easybuild.easyblocks.generic.pythonpackage import PythonPackage, det_pip_version
from easybuild.tools.build_log import EasyBuildError
from easybuild.tools.filetools import read_file
from easybuild.tools.filetools import apply_regex_substitutions, change_dir, read_file, which
from easybuild.tools.modules import get_software_root_env_var_name
from easybuild.tools.py2vs3 import OrderedDict
from easybuild.tools.utilities import flatten
Expand Down Expand Up @@ -66,6 +66,28 @@ def __init__(self, *args, **kwargs):
# consider setuptools first, in case it is listed as a sources
self.easybuild_pkgs.insert(0, 'setuptools')

# opt-in to using pip for recent version of EasyBuild, if:
# - EasyBuild is being installed for Python >= 3.6;
# - pip is available, and recent enough (>= 21.0);
# - use_pip is not specified;
pyver = sys.version.split(' ')[0]
pip = which('pip')
boegel marked this conversation as resolved.
Show resolved Hide resolved
self.log.info("Python version: %s - pip: %s", pyver, pip)
if sys.version_info >= (3, 6) and pip and self.cfg['use_pip'] is None:
# try to determine pip version, ignore any failures that occur while doing so;
# problems may occur due changes in environment ($PYTHONPATH, etc.)
pip_version = None
try:
pip_version = det_pip_version()
self.log.info("Found Python v%s + pip: %s", pyver, pip_version)
boegel marked this conversation as resolved.
Show resolved Hide resolved
except Exception as err:
self.log.warning("Failed to determine pip version: %s", err)

if pip_version and LooseVersion(pip_version) >= LooseVersion('21.0'):
self.log.info("Auto-enabling use of pip to install EasyBuild!")
self.cfg['use_pip'] = True
self.determine_install_command()

# Override this function since we want to respect the user choice for the python installation to use
# (which can be influenced by EB_PYTHON and EB_INSTALLPYTHON)
def prepare_python(self):
Expand All @@ -92,6 +114,21 @@ def build_step(self):
"""No building for EasyBuild packages."""
pass

def fix_easyconfigs_setup_py_setuptools61(self):
"""
Patch setup.py of easybuild-easyconfigs package if needed to make sure that installation works
for recent setuptools versions (>= 61.0).
"""
# cfr. https://github.com/easybuilders/easybuild-easyconfigs/pull/15206
cwd = os.getcwd()
regex = re.compile(r'packages=\[\]')
setup_py_txt = read_file('setup.py')
if regex.search(setup_py_txt) is None:
self.log.info("setup.py at %s needs to be fixed to install with setuptools >= 61.0", cwd)
apply_regex_substitutions('setup.py', [(r'^setup\(', 'setup(packages=[],')])
else:
self.log.info("setup.py at %s does not need to be fixed to install with setuptools >= 61.0", cwd)

def install_step(self):
"""Install EasyBuild packages one by one."""
try:
Expand All @@ -108,7 +145,11 @@ def install_step(self):

else:
self.log.info("Installing package %s", pkg)
os.chdir(os.path.join(self.builddir, seldirs[0]))
change_dir(os.path.join(self.builddir, seldirs[0]))

if pkg == 'easybuild-easyconfigs':
self.fix_easyconfigs_setup_py_setuptools61()

super(EB_EasyBuildMeta, self).install_step()

except OSError as err:
Expand Down
8 changes: 7 additions & 1 deletion easybuild/easyblocks/generic/pythonpackage.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ def __init__(self, *args, **kwargs):

# determine install command
self.use_setup_py = False
self.determine_install_command()

def determine_install_command(self):
"""
Determine install command to use.
"""
if self.cfg.get('use_pip', False) or self.cfg.get('use_pip_editable', False):
self.install_cmd = PIP_INSTALL_CMD

Expand Down Expand Up @@ -361,7 +367,7 @@ def __init__(self, *args, **kwargs):
else:
raise EasyBuildError("Installing zipped eggs requires using easy_install or pip")

self.log.debug("Using '%s' as install command", self.install_cmd)
self.log.info("Using '%s' as install command", self.install_cmd)

def set_pylibdirs(self):
"""Set Python lib directory-related class variables."""
Expand Down