From 1052f0e8567a4df0494c95519e607677c5120fe9 Mon Sep 17 00:00:00 2001 From: Ward Poelmans Date: Wed, 10 Apr 2019 11:00:56 +0200 Subject: [PATCH 1/6] Add VUB authors --- lib/vsc/install/shared_setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/vsc/install/shared_setup.py b/lib/vsc/install/shared_setup.py index ed51d34a..4547c9cd 100644 --- a/lib/vsc/install/shared_setup.py +++ b/lib/vsc/install/shared_setup.py @@ -137,7 +137,8 @@ def _log(self, level, msg, args): lm = ('Luis Fernando Munoz Meji?as', 'luis.munoz@ugent.be') sdw = ('Stijn De Weirdt', 'stijn.deweirdt@ugent.be') wdp = ('Wouter Depypere', 'wouter.depypere@ugent.be') -wp = ('Ward Poelmans', 'Ward.Poelmans@UGent.be') +wp = ('Ward Poelmans', 'ward.poelmans@vub.be') +sm = ('Samuel Moors', 'samuel.moors@vub.be') # Regexp used to remove suffixes from scripts when installing(/packaging) REGEXP_REMOVE_SUFFIX = re.compile(r'(\.(?:py|sh|pl))$') From 309f5f54354dd44be3115d3365eeee7f7c622da8 Mon Sep 17 00:00:00 2001 From: Ward Poelmans Date: Wed, 10 Apr 2019 11:28:13 +0200 Subject: [PATCH 2/6] Make pep8 happy --- lib/vsc/install/headers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/vsc/install/headers.py b/lib/vsc/install/headers.py index 4146b592..62173ee5 100644 --- a/lib/vsc/install/headers.py +++ b/lib/vsc/install/headers.py @@ -63,7 +63,7 @@ def nicediff(txta, txtb, offset=5): res_idx = [] # very bruteforce for didx in different_idx: - for idx in range(max(didx-offset, 0), min(didx+offset, len(diff)-1)): + for idx in range(max(didx - offset, 0), min(didx + offset, len(diff) - 1)): if idx not in res_idx: res_idx.append(idx) res_idx.sort() @@ -195,7 +195,7 @@ def check_header(filename, script=False, write=False): if file_ext == '.py': if shebang != SHEBANG_ENV_PYTHON: log.info("Wrong shebang for Python script %s: found '%s', should be '%s'", - filename, shebang, SHEBANG_ENV_PYTHON) + filename, shebang, SHEBANG_ENV_PYTHON) shebang = SHEBANG_ENV_PYTHON elif file_ext in ['.sh', '']: @@ -273,6 +273,7 @@ def check_header(filename, script=False, write=False): # return different or not return changed + # # Only template headers below # From b81eace5da0be5543530e1e505dcf65967459a39 Mon Sep 17 00:00:00 2001 From: Ward Poelmans Date: Wed, 10 Apr 2019 11:55:06 +0200 Subject: [PATCH 3/6] Add support for Brussel github upstream We use http://github.com/sisc-hpc as upstream source --- lib/vsc/install/shared_setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/vsc/install/shared_setup.py b/lib/vsc/install/shared_setup.py index 4547c9cd..07affa5a 100644 --- a/lib/vsc/install/shared_setup.py +++ b/lib/vsc/install/shared_setup.py @@ -325,8 +325,8 @@ def get_name_url(self, filename=None, version=None, license_name=None): ], 'url': [ r'^Home-page:\s*(.*?)\s*$', - r'^\s*url\s*=\s*((?:https?|ssh).*?github.*?[:/]hpcugent/.*?)\.git\s*$', - r'^\s*url\s*=\s*(git[:@].*?github.*?[:/]hpcugent/.*?)(?:\.git)?\s*$', + r'^\s*url\s*=\s*((?:https?|ssh).*?github.*?[:/](?:hpcugent|sisc-hpc)/.*?)\.git\s*$', + r'^\s*url\s*=\s*(git[:@].*?github.*?[:/](?:hpcugent|sisc-hpc)/.*?)(?:\.git)?\s*$', ], 'download_url': [ r'^Download-URL:\s*(.*?)\s*$', @@ -350,7 +350,7 @@ def get_name_url(self, filename=None, version=None, license_name=None): self.private_repo = True if 'url' not in res: - raise KeyError("Missing url in git config %s. (Missing mandatory hpcugent (upstream) remote?)" % (res)) + raise KeyError("Missing url in git config %s. (Missing mandatory hpcugent or sisc-hpc remote?)" % (res)) # handle git://server/user/project reg = re.search(r'^(git|ssh)://', res.get('url', '')) From 2c563cbf9b7fc8b4c691ecb04a1308633759c96d Mon Sep 17 00:00:00 2001 From: Ward Poelmans Date: Wed, 10 Apr 2019 11:55:37 +0200 Subject: [PATCH 4/6] Add license support for Brussel based on project URL --- lib/vsc/install/headers.py | 20 +++++++++++++++++++- lib/vsc/install/shared_setup.py | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/vsc/install/headers.py b/lib/vsc/install/headers.py index 62173ee5..c9a50ccb 100644 --- a/lib/vsc/install/headers.py +++ b/lib/vsc/install/headers.py @@ -102,7 +102,7 @@ def get_header(filename, script=False): blocks = ['', ''] elif blocks[0] != '': # the block before the begin of text is always empty - raise Exception('unexpected non-emtpy block with get_header %s: %s' % (filename, blocks)) + raise Exception('unexpected non-empty block with get_header %s: %s' % (filename, blocks)) header = blocks[1] @@ -117,6 +117,21 @@ def get_header(filename, script=False): return header, shebang +def gen_license_header_brussel(license_template): + """ + This adjusts the license template for use in Brussel + :param license_template: a license template + """ + # replace university name + new_license_template = re.sub("Ghent University", "Vrije Universiteit Brussel", license_template) + # replace URL of HPC team + new_license_template = re.sub(r"http://ugent.be/hpc/en", "https://hpc.vub.be", new_license_template) + # replace URL of university + new_license_template = re.sub(r"http://ugent.be/hpc", "https://www.vub.be", new_license_template) + + return new_license_template + + def gen_license_header(license_name, **kwargs): """ Create an appropriate license header for this project @@ -133,6 +148,9 @@ def gen_license_header(license_name, **kwargs): if template is None: raise Exception('gen_license_header cannot find template name %s' % template_name) + if 'sisc-hpc/' in kwargs.get('url', ''): + template = gen_license_header_brussel(template) + return template.format(**kwargs) diff --git a/lib/vsc/install/shared_setup.py b/lib/vsc/install/shared_setup.py index 07affa5a..7ddc8123 100644 --- a/lib/vsc/install/shared_setup.py +++ b/lib/vsc/install/shared_setup.py @@ -156,7 +156,7 @@ def _log(self, level, msg, args): RELOAD_VSC_MODS = False -VERSION = '0.12.2' +VERSION = '0.12.3' log.info('This is (based on) vsc.install.shared_setup %s' % VERSION) From 453f5ea49ead0cbc4c5ac376d59eccf70f6d37c8 Mon Sep 17 00:00:00 2001 From: Ward Poelmans Date: Wed, 10 Apr 2019 12:25:59 +0200 Subject: [PATCH 5/6] Add tests for Brussels parts --- test/headers.py | 16 ++++++++++++++++ test/setup/git_config_6 | 8 ++++++++ test/shared_setup.py | 12 +++++++++++- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/setup/git_config_6 diff --git a/test/headers.py b/test/headers.py index 2d4a1d71..42ec66f3 100644 --- a/test/headers.py +++ b/test/headers.py @@ -109,6 +109,12 @@ def test_gen_license_header(self): 'endyear': 5678, 'url': 'https://example.com/projectname', } + data_brussel = { + 'name': 'projectname', + 'beginyear': 1234, + 'endyear': 5678, + 'url': 'https://github.com/sisc-hpc/projectname', + } for license in KNOWN_LICENSES.keys(): res_fn = os.path.join(self.setup.REPO_TEST_DIR, 'headers', license) with open(res_fn) as fh: @@ -117,6 +123,16 @@ def test_gen_license_header(self): self.assertEqual(gen_txt, result, msg='generated header for license %s as expected' % license) log.info('generated license header %s' % license) + gen_txt_bru = gen_license_header(license, **data_brussel) + self.assertNotRegexpMatches(gen_txt_bru, 'Ghent University', + msg='No reference to Ghent University in header') + self.assertNotRegexpMatches(gen_txt_bru, r'ugent\.be', + msg='No reference to ugent.be University in header') + self.assertRegexpMatches(gen_txt_bru, r'the HPC team of Vrije Universiteit Brussel \(https://hpc.vub.be\)', + msg='generted header for Brussel is correct for %s' % license) + self.assertRegexpMatches(gen_txt_bru, r'support of Vrije Universiteit Brussel \(https://www.vub.be\)', + msg='generted header for Brussel is correct for %s' % license) + def test_begin_end_from_header(self): """Test begin_end_from_header method""" diff --git a/test/setup/git_config_6 b/test/setup/git_config_6 new file mode 100644 index 00000000..d38d58a5 --- /dev/null +++ b/test/setup/git_config_6 @@ -0,0 +1,8 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true +[remote "origin"] + url = git@github.com:sisc-hpc/vsc-jobs-brussel.git + fetch = +refs/heads/*:refs/remotes/origin/* diff --git a/test/shared_setup.py b/test/shared_setup.py index 9ad28183..f04f9f9a 100644 --- a/test/shared_setup.py +++ b/test/shared_setup.py @@ -63,6 +63,16 @@ def test_get_name_url(self): license_name='LGPLv2+'), res, msg='determined name and url from %s file with license' % fn) + fn = 'git_config_6' + res_brussel = { + 'name': 'vsc-jobs-brussel', + 'url': 'https://github.com/sisc-hpc/vsc-jobs-brussel', + 'download_url': 'https://github.com/sisc-hpc/vsc-jobs-brussel/archive/0.1.0.tar.gz', + } + self.assertEqual(self.setup.get_name_url(os.path.join(self.setup.REPO_TEST_DIR, 'setup', fn), version='0.1.0'), + res_brussel, + msg='determined name and url from %s file with license' % fn) + def test_sanitize(self): """Test sanitize function""" os.environ['VSC_RPM_PYTHON'] = '1' @@ -124,7 +134,7 @@ def test_rel_gitignore(self): def test_import(self): """Test importing things from shared_setup.py, these should not be broken for backward compatibility.""" from vsc.install.shared_setup import SHARED_TARGET - from vsc.install.shared_setup import ag, eh, jt, kh, kw, lm, sdw, wdp, wp + from vsc.install.shared_setup import ag, eh, jt, kh, kw, lm, sdw, wdp, wp, sm def test_action_target(self): """Test action_target function, mostly w.r.t. backward compatibility.""" From 717854fb116af72411e90175970b67bbe626695e Mon Sep 17 00:00:00 2001 From: Ward Poelmans Date: Wed, 10 Apr 2019 13:34:03 +0200 Subject: [PATCH 6/6] Use templating in license for university --- lib/vsc/install/headers.py | 59 +++++++++++++++++++++----------------- test/headers.py | 2 +- test/headers/ARR | 2 +- test/headers/GPLv2 | 2 +- test/headers/LGPLv2+ | 2 +- 5 files changed, 37 insertions(+), 30 deletions(-) diff --git a/lib/vsc/install/headers.py b/lib/vsc/install/headers.py index c9a50ccb..d8c71e61 100644 --- a/lib/vsc/install/headers.py +++ b/lib/vsc/install/headers.py @@ -117,21 +117,6 @@ def get_header(filename, script=False): return header, shebang -def gen_license_header_brussel(license_template): - """ - This adjusts the license template for use in Brussel - :param license_template: a license template - """ - # replace university name - new_license_template = re.sub("Ghent University", "Vrije Universiteit Brussel", license_template) - # replace URL of HPC team - new_license_template = re.sub(r"http://ugent.be/hpc/en", "https://hpc.vub.be", new_license_template) - # replace URL of university - new_license_template = re.sub(r"http://ugent.be/hpc", "https://www.vub.be", new_license_template) - - return new_license_template - - def gen_license_header(license_name, **kwargs): """ Create an appropriate license header for this project @@ -148,8 +133,15 @@ def gen_license_header(license_name, **kwargs): if template is None: raise Exception('gen_license_header cannot find template name %s' % template_name) - if 'sisc-hpc/' in kwargs.get('url', ''): - template = gen_license_header_brussel(template) + found = False + for github_organ in institute_details.keys(): + if github_organ in kwargs.get('url', ''): + kwargs.update(institute_details[github_organ]) + found = True + break + + if not found: + raise Exception('Unable to find a known github organization in url %s' % kwargs.get('url')) return template.format(**kwargs) @@ -292,16 +284,31 @@ def check_header(filename, script=False, write=False): return changed +# mapping of the github organization to the details +# to fill in the license templates +institute_details = { + 'hpcugent': { + 'university_name': 'Ghent University', + 'university_url': 'http://ugent.be/hpc', + 'university_team_url': 'http://ugent.be/hpc/en', + }, + 'sisc-hpc': { + 'university_name': 'Vrije Universiteit Brussel', + 'university_url': 'https://www.vub.be', + 'university_team_url': 'https://hpc.vub.be', + }, +} + # # Only template headers below # LGPLv2_plus__TEMPLATE = """# -# Copyright {beginyear}-{endyear} Ghent University +# Copyright {beginyear}-{endyear} {university_name} # # This file is part of {name}, -# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en), -# with support of Ghent University (http://ugent.be/hpc), +# originally created by the HPC team of {university_name} ({university_team_url}), +# with support of {university_name} ({university_url}), # the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be), # the Flemish Research Foundation (FWO) (http://www.fwo.be/en) # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). @@ -324,11 +331,11 @@ def check_header(filename, script=False, write=False): """ GPLv2_TEMPLATE = """# -# Copyright {beginyear}-{endyear} Ghent University +# Copyright {beginyear}-{endyear} {university_name} # # This file is part of {name}, -# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en), -# with support of Ghent University (http://ugent.be/hpc), +# originally created by the HPC team of {university_name} ({university_team_url}), +# with support of {university_name} ({university_url}), # the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be), # the Flemish Research Foundation (FWO) (http://www.fwo.be/en) # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). @@ -350,11 +357,11 @@ def check_header(filename, script=False, write=False): """ ARR_TEMPLATE = """# -# Copyright {beginyear}-{endyear} Ghent University +# Copyright {beginyear}-{endyear} {university_name} # # This file is part of {name}, -# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en), -# with support of Ghent University (http://ugent.be/hpc), +# originally created by the HPC team of {university_name} ({university_team_url}), +# with support of {university_name} ({university_url}), # the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be), # the Flemish Research Foundation (FWO) (http://www.fwo.be/en) # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). diff --git a/test/headers.py b/test/headers.py index 42ec66f3..8ce3f4a7 100644 --- a/test/headers.py +++ b/test/headers.py @@ -107,7 +107,7 @@ def test_gen_license_header(self): 'name': 'projectname', 'beginyear': 1234, 'endyear': 5678, - 'url': 'https://example.com/projectname', + 'url': 'https://github.com/hpcugent/projectname', } data_brussel = { 'name': 'projectname', diff --git a/test/headers/ARR b/test/headers/ARR index 7e491c80..d67eecbd 100644 --- a/test/headers/ARR +++ b/test/headers/ARR @@ -8,7 +8,7 @@ # the Flemish Research Foundation (FWO) (http://www.fwo.be/en) # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). # -# https://example.com/projectname +# https://github.com/hpcugent/projectname # # All rights reserved. # diff --git a/test/headers/GPLv2 b/test/headers/GPLv2 index 30f147f0..9479edf7 100644 --- a/test/headers/GPLv2 +++ b/test/headers/GPLv2 @@ -8,7 +8,7 @@ # the Flemish Research Foundation (FWO) (http://www.fwo.be/en) # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). # -# https://example.com/projectname +# https://github.com/hpcugent/projectname # # projectname is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by diff --git a/test/headers/LGPLv2+ b/test/headers/LGPLv2+ index c071bbe8..fba80662 100644 --- a/test/headers/LGPLv2+ +++ b/test/headers/LGPLv2+ @@ -8,7 +8,7 @@ # the Flemish Research Foundation (FWO) (http://www.fwo.be/en) # and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en). # -# https://example.com/projectname +# https://github.com/hpcugent/projectname # # projectname is free software: you can redistribute it and/or modify # it under the terms of the GNU Library General Public License as