From 3630112427d2e45918d702eae576caa6f214c40a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20=C3=96hman?= Date: Thu, 4 May 2023 17:38:03 +0200 Subject: [PATCH 1/3] Use version suffixes in title instead of Python versions --- easybuild/tools/github.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index bc3a6b3e27..588cbf8241 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -1714,19 +1714,18 @@ def new_pr_from_branch(branch_name, title=None, descr=None, pr_target_repo=None, title = "{%s}[%s] %s" % (class_label, toolchain_label, main_title) - # if Python is listed as a dependency, then mention Python version(s) in PR title - pyver = [] + # Find all suffixes + suffixes = [] for ec in file_info['ecs']: - # iterate over all dependencies (incl. build dependencies & multi-deps) - for dep in ec.dependencies(): - if dep['name'] == 'Python': - # check whether Python is listed as a multi-dep if it's marked as a build dependency - if dep['build_only'] and 'Python' not in ec['multi_deps']: - continue - else: - pyver.append(dep['version']) - if pyver: - title += " w/ Python %s" % ' + '.join(sorted(nub(pyver))) + if 'versionsuffix' in ec and ec['versionsuffix']: + suffixes.append(ec['versionsuffix'].strip('-').replace('-', ' ')) + if suffixes: + suffixes = sorted(nub(suffixes)) + if len(suffixes) <= 2: + title_suffix = ', '.join(suffixes) + else: + title_suffix = ', '.join(suffixes[:2] + ['...']) + title += " w/ " + title_suffix elif pr_target_repo == GITHUB_EASYBLOCKS_REPO: if file_info['eb_names'] and all(file_info['new']) and not deleted_paths: plural = 's' if len(file_info['eb_names']) > 1 else '' From bc86c9d3dd70d0e36345cebd5f2396f4fbf9fa6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20=C3=96hman?= Date: Thu, 15 Jun 2023 17:46:33 +0200 Subject: [PATCH 2/3] Move automated easyconfig pr title into separate function. --- easybuild/tools/github.py | 72 ++++++++++++++++++++++----------------- 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/easybuild/tools/github.py b/easybuild/tools/github.py index 588cbf8241..78846ac539 100644 --- a/easybuild/tools/github.py +++ b/easybuild/tools/github.py @@ -1581,6 +1581,45 @@ def new_branch_github(paths, ecs, commit_msg=None): return res +def det_pr_title(ecs): + """ + Create title for PR based on first easyconfigs + :param ecs: list of parsed easyconfigs + """ + + # only use most common toolchain(s) in toolchain label of PR title + toolchains = ['%(name)s/%(version)s' % ec['toolchain'] for ec in ecs] + toolchains_counted = sorted([(toolchains.count(tc), tc) for tc in nub(toolchains)]) + toolchain_label = ','.join([tc for (cnt, tc) in toolchains_counted if cnt == toolchains_counted[-1][0]]) + + # only use most common module class(es) in moduleclass label of PR title + classes = [ec['moduleclass'] for ec in ecs] + classes_counted = sorted([(classes.count(c), c) for c in nub(classes)]) + class_label = ','.join([tc for (cnt, tc) in classes_counted if cnt == classes_counted[-1][0]]) + + names_and_versions = nub(["%s v%s" % (ec.name, ec.version) for ec in ecs]) + if len(names_and_versions) <= 3: + main_title = ', '.join(names_and_versions) + else: + main_title = ', '.join(names_and_versions[:3] + ['...']) + + title = "{%s}[%s] %s" % (class_label, toolchain_label, main_title) + + # Find all suffixes + suffixes = [] + for ec in ecs: + if 'versionsuffix' in ec and ec['versionsuffix']: + suffixes.append(ec['versionsuffix'].strip('-').replace('-', ' ')) + if suffixes: + suffixes = sorted(nub(suffixes)) + if len(suffixes) <= 2: + title += ' w/ ' + ', '.join(suffixes) + else: + title += ' w/ ' + ', '.join(suffixes[:2] + ['...']) + + return title + + @only_if_module_is_available('git', pkgname='GitPython') def new_pr_from_branch(branch_name, title=None, descr=None, pr_target_repo=None, pr_metadata=None, commit_msg=None): """ @@ -1691,41 +1730,10 @@ def new_pr_from_branch(branch_name, title=None, descr=None, pr_target_repo=None, labels = det_pr_labels(file_info, pr_target_repo) - if pr_target_repo == GITHUB_EASYCONFIGS_REPO: - # only use most common toolchain(s) in toolchain label of PR title - toolchains = ['%(name)s/%(version)s' % ec['toolchain'] for ec in file_info['ecs']] - toolchains_counted = sorted([(toolchains.count(tc), tc) for tc in nub(toolchains)]) - toolchain_label = ','.join([tc for (cnt, tc) in toolchains_counted if cnt == toolchains_counted[-1][0]]) - - # only use most common module class(es) in moduleclass label of PR title - classes = [ec['moduleclass'] for ec in file_info['ecs']] - classes_counted = sorted([(classes.count(c), c) for c in nub(classes)]) - class_label = ','.join([tc for (cnt, tc) in classes_counted if cnt == classes_counted[-1][0]]) - if title is None: if pr_target_repo == GITHUB_EASYCONFIGS_REPO: if file_info['ecs'] and all(file_info['new']) and not deleted_paths: - # mention software name/version in PR title (only first 3) - names_and_versions = nub(["%s v%s" % (ec.name, ec.version) for ec in file_info['ecs']]) - if len(names_and_versions) <= 3: - main_title = ', '.join(names_and_versions) - else: - main_title = ', '.join(names_and_versions[:3] + ['...']) - - title = "{%s}[%s] %s" % (class_label, toolchain_label, main_title) - - # Find all suffixes - suffixes = [] - for ec in file_info['ecs']: - if 'versionsuffix' in ec and ec['versionsuffix']: - suffixes.append(ec['versionsuffix'].strip('-').replace('-', ' ')) - if suffixes: - suffixes = sorted(nub(suffixes)) - if len(suffixes) <= 2: - title_suffix = ', '.join(suffixes) - else: - title_suffix = ', '.join(suffixes[:2] + ['...']) - title += " w/ " + title_suffix + title = det_pr_title(file_info['ecs']) elif pr_target_repo == GITHUB_EASYBLOCKS_REPO: if file_info['eb_names'] and all(file_info['new']) and not deleted_paths: plural = 's' if len(file_info['eb_names']) > 1 else '' From f2d9d1612e24da796790c9c89ec93cfc15cb6195 Mon Sep 17 00:00:00 2001 From: Simon Branford Date: Thu, 22 Jun 2023 19:38:41 +0100 Subject: [PATCH 3/3] add tests for det_pr_title --- test/framework/github.py | 67 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/test/framework/github.py b/test/framework/github.py index 84d3f5c821..c6962a4623 100644 --- a/test/framework/github.py +++ b/test/framework/github.py @@ -50,7 +50,7 @@ from easybuild.tools.filetools import read_file, write_file from easybuild.tools.github import GITHUB_EASYCONFIGS_REPO, GITHUB_EASYBLOCKS_REPO, GITHUB_MERGEABLE_STATE_CLEAN from easybuild.tools.github import VALID_CLOSE_PR_REASONS -from easybuild.tools.github import is_patch_for, pick_default_branch +from easybuild.tools.github import det_pr_title, is_patch_for, pick_default_branch from easybuild.tools.testing import create_test_report, post_pr_test_report, session_state from easybuild.tools.py2vs3 import HTTPError, URLError, ascii_letters import easybuild.tools.github as gh @@ -116,6 +116,71 @@ def tearDown(self): super(GithubTest, self).tearDown() + def test_det_pr_title(self): + """Test det_pr_title function""" + # check if patches for extensions are found + rawtxt = textwrap.dedent(""" + easyblock = 'ConfigureMake' + name = '%s' + version = '%s' + homepage = 'http://foo.com/' + description = '' + toolchain = {'name': '%s', 'version': '%s'} + moduleclass = '%s' + %s + """) + + # 1 easyconfig, with no versionsuffix + ecs = [] + ecs.append(EasyConfig(None, rawtxt=rawtxt % ('prog', '1', 'GCC', '11.2.0', 'tools', ''))) + self.assertEqual(det_pr_title(ecs), '{tools}[GCC/11.2.0] prog v1') + + # 2 easyconfigs, with no versionsuffixes + ecs.append(EasyConfig(None, rawtxt=rawtxt % ('otherprog', '2', 'GCCcore', '11.2.0', 'lib', ''))) + self.assertEqual(det_pr_title(ecs), '{lib,tools}[GCC/11.2.0,GCCcore/11.2.0] prog v1, otherprog v2') + + # 3 easyconfigs, with no versionsuffixes + ecs.append(EasyConfig(None, rawtxt=rawtxt % ('extraprog', '3', 'foss', '2022a', 'astro', ''))) + self.assertEqual(det_pr_title(ecs), + '{astro,lib,tools}[GCC/11.2.0,GCCcore/11.2.0,foss/2022a] prog v1, otherprog v2, extraprog v3') + + # 2 easyconfigs for the same prog, with no versionsuffixes + ecs[1] = EasyConfig(None, rawtxt=rawtxt % ('prog', '2', 'GCC', '11.3.0', 'tools', '')) + ecs.pop(2) + self.assertEqual(det_pr_title(ecs), '{tools}[GCC/11.2.0,GCC/11.3.0] prog v1, prog v2') + + # 1 easyconfig, with versionsuffix + ecs = [] + ecs.append(EasyConfig(None, rawtxt=rawtxt % ('prog', '1', 'GCC', '11.2.0', 'tools', + 'versionsuffix = "-Python-3.10.4"'))) + self.assertEqual(det_pr_title(ecs), '{tools}[GCC/11.2.0] prog v1 w/ Python 3.10.4') + + # 1 easyconfig, with versionsuffix + ecs[0] = EasyConfig(None, rawtxt=rawtxt % ('prog', '1', 'GCC', '11.2.0', 'tools', + 'versionsuffix = "-Python-3.10.4-CUDA-11.3.1"')) + self.assertEqual(det_pr_title(ecs), '{tools}[GCC/11.2.0] prog v1 w/ Python 3.10.4 CUDA 11.3.1') + + # 2 easyconfigs, with same versionsuffix + ecs[0] = EasyConfig(None, rawtxt=rawtxt % ('prog', '1', 'GCC', '11.2.0', 'tools', + 'versionsuffix = "-Python-3.10.4"')) + ecs.append(EasyConfig(None, rawtxt=rawtxt % ('prog', '2', 'GCC', '11.3.0', 'tools', + 'versionsuffix = "-Python-3.10.4"'))) + self.assertEqual(det_pr_title(ecs), '{tools}[GCC/11.2.0,GCC/11.3.0] prog v1, prog v2 w/ Python 3.10.4') + + # 2 easyconfigs, with different versionsuffix + ecs[0] = EasyConfig(None, rawtxt=rawtxt % ('prog', '1', 'GCC', '11.2.0', 'tools', + 'versionsuffix = "-CUDA-11.3.1"')) + self.assertEqual(det_pr_title(ecs), + '{tools}[GCC/11.2.0,GCC/11.3.0] prog v1, prog v2 w/ CUDA 11.3.1, Python 3.10.4') + + # 2 easyconfigs, with unusual versionsuffixes + ecs[0] = EasyConfig(None, rawtxt=rawtxt % ('prog', '1', 'GCC', '11.2.0', 'tools', + 'versionsuffix = "-contrib"')) + ecs[1] = EasyConfig(None, rawtxt=rawtxt % ('prog', '1', 'GCC', '11.2.0', 'tools', + 'versionsuffix = "-Python-3.10.4-CUDA-11.3.1-contrib"')) + self.assertEqual(det_pr_title(ecs), + '{tools}[GCC/11.2.0] prog v1 w/ Python 3.10.4 CUDA 11.3.1 contrib, contrib') + def test_github_pick_default_branch(self): """Test pick_default_branch function."""