From 1ec53a50c6ab92e671c51629de87d63218b6f3b7 Mon Sep 17 00:00:00 2001 From: Simon Branford Date: Mon, 6 May 2024 13:59:27 +0100 Subject: [PATCH] version check on from pr --- easybuild/tools/github.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index 9a70109c00..5691be973c 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -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) @@ -588,13 +589,38 @@ def fetch_files_from_pr(pr, path=None, github_user=None, github_account=None, gi raise EasyBuildError("Couldn't find path to patched file %s", full_path) if github_repo == GITHUB_EASYCONFIGS_REPO: - print('get ecs version', os.path.join(final_path, 'setup.py')) + ver = _get_version_for_repo(os.path.join(final_path, 'setup.py')) elif github_repo == GITHUB_EASYBLOCKS_REPO: - print('get blocks version', sys.path, final_path) + 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 PR target (%s)." % (FRAMEWORK_VERSION, + 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: + 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)