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

implement EasyBuild API version checks to avoid mixing major versions across the EasyBuild components #4520

Merged
merged 14 commits into from
Jun 5, 2024
11 changes: 11 additions & 0 deletions easybuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
from easybuild.tools.repository.repository import init_repository
from easybuild.tools.systemtools import check_easybuild_deps
from easybuild.tools.testing import create_test_report, overall_test_report, regtest, session_state
from easybuild.tools.version import EASYBLOCKS_VERSION, FRAMEWORK_VERSION, UNKNOWN_EASYBLOCKS_VERSION
from easybuild.tools.version import different_major_versions


_log = None
Expand Down Expand Up @@ -618,6 +620,15 @@ def main(args=None, logfile=None, do_build=None, testing=False, modtool=None, pr
(build_specs, _log, logfile, robot_path, search_query, eb_tmpdir, try_to_generate,
from_pr_list, tweaked_ecs_paths) = cfg_settings

# compare running Framework and EasyBlocks versions
if EASYBLOCKS_VERSION == UNKNOWN_EASYBLOCKS_VERSION:
# most likely reason is running framework unit tests with no easyblocks installation
# so log a warning, to avoid test related issues
_log.warning("Unable to determine EasyBlocks version, so we'll assume it is not different from Framework")
elif different_major_versions(FRAMEWORK_VERSION, EASYBLOCKS_VERSION):
raise EasyBuildError("Framework (%s) and EasyBlock (%s) major versions are different." % (FRAMEWORK_VERSION,
EASYBLOCKS_VERSION))

# load hook implementations (if any)
hooks = load_hooks(options.hooks)

Expand Down
31 changes: 31 additions & 0 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
from easybuild.tools.py2vs3 import HTTPError, URLError, ascii_letters, urlopen
from easybuild.tools.systemtools import UNKNOWN, get_tool_version
from easybuild.tools.utilities import nub, only_if_module_is_available
from easybuild.tools.version import FRAMEWORK_VERSION, different_major_versions


_log = fancylogger.getLogger('github', fname=False)
Expand Down Expand Up @@ -587,9 +588,39 @@ def fetch_files_from_pr(pr, path=None, github_user=None, github_account=None, gi
else:
raise EasyBuildError("Couldn't find path to patched file %s", full_path)

if github_repo == GITHUB_EASYCONFIGS_REPO:
ver = _get_version_for_repo(os.path.join(final_path, 'setup.py'))
elif github_repo == GITHUB_EASYBLOCKS_REPO:
ver = _get_version_for_repo(os.path.join(final_path, 'easybuild', 'easyblocks', '__init__.py'))

if different_major_versions(FRAMEWORK_VERSION, ver):
raise EasyBuildError("Framework (%s) is a different major version than used in %s/%s PR #%s (%s)",
FRAMEWORK_VERSION, github_account, github_repo, pr, ver)

return files


def _get_version_for_repo(filename):
"""Extract version from filename."""
_log.debug("Extract version from %s" % filename)

try:
ver_line = ""
with open(filename) as f:
for line in f.readlines():
if line.startswith("VERSION "):
ver_line = line
break

# version can be a string or LooseVersion
res = re.search(r"""^VERSION = .*['"](.*)['"].?$""", ver_line)

_log.debug("PR target version is %s" % res.group(1))
return res.group(1)
except Exception:
raise EasyBuildError("Couldn't determine version of PR from %s" % filename)


def fetch_easyblocks_from_pr(pr, path=None, github_user=None):
"""Fetch patched easyblocks for a particular PR."""
return fetch_files_from_pr(pr, path, github_user, github_repo=GITHUB_EASYBLOCKS_REPO)
Expand Down
14 changes: 13 additions & 1 deletion easybuild/tools/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
# This causes problems further up the dependency chain...
VERSION = LooseVersion('4.9.2.dev0')
UNKNOWN = 'UNKNOWN'
UNKNOWN_EASYBLOCKS_VERSION = '0.0.UNKNOWN.EASYBLOCKS'


def get_git_revision():
Expand Down Expand Up @@ -87,7 +88,7 @@ def get_git_revision():
try:
from easybuild.easyblocks import VERBOSE_VERSION as EASYBLOCKS_VERSION
except Exception:
EASYBLOCKS_VERSION = '0.0.UNKNOWN.EASYBLOCKS' # make sure it is smaller then anything
EASYBLOCKS_VERSION = UNKNOWN_EASYBLOCKS_VERSION # make sure it is smaller then anything


def this_is_easybuild():
Expand All @@ -103,3 +104,14 @@ def this_is_easybuild():
msg = msg.encode('ascii')

return msg


def different_major_versions(v1, v2):
"""Compare major versions"""
# Deal with version instances being either strings or LooseVersion
if isinstance(v1, str):
v1 = LooseVersion(v1)
if isinstance(v2, str):
v2 = LooseVersion(v2)

return v1.version[0] != v2.version[0]
Loading