diff --git a/easybuild/main.py b/easybuild/main.py index 42bd83dff5..451152f322 100644 --- a/easybuild/main.py +++ b/easybuild/main.py @@ -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 @@ -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) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index ae9b78b5ed..6a8401d7ae 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) @@ -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) diff --git a/easybuild/tools/version.py b/easybuild/tools/version.py index c01c8fc5c3..e29f6f0b29 100644 --- a/easybuild/tools/version.py +++ b/easybuild/tools/version.py @@ -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(): @@ -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(): @@ -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]