Skip to content

Commit

Permalink
Merge pull request #101 from wpoely86/vub
Browse files Browse the repository at this point in the history
Add support for VUB
  • Loading branch information
stdweird authored Apr 10, 2019
2 parents ee7b08d + 717854f commit 1ca52c7
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 22 deletions.
50 changes: 38 additions & 12 deletions lib/vsc/install/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -133,6 +133,16 @@ def gen_license_header(license_name, **kwargs):
if template is None:
raise Exception('gen_license_header cannot find template name %s' % template_name)

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)


Expand Down Expand Up @@ -195,7 +205,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', '']:
Expand Down Expand Up @@ -273,16 +283,32 @@ def check_header(filename, script=False, write=False):
# return different or not
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).
Expand All @@ -305,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).
Expand All @@ -331,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).
Expand Down
11 changes: 6 additions & 5 deletions lib/vsc/install/shared_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ def _log(self, level, msg, args):
lm = ('Luis Fernando Munoz Meji?as', '[email protected]')
sdw = ('Stijn De Weirdt', '[email protected]')
wdp = ('Wouter Depypere', '[email protected]')
wp = ('Ward Poelmans', '[email protected]')
wp = ('Ward Poelmans', '[email protected]')
sm = ('Samuel Moors', '[email protected]')

# Regexp used to remove suffixes from scripts when installing(/packaging)
REGEXP_REMOVE_SUFFIX = re.compile(r'(\.(?:py|sh|pl))$')
Expand All @@ -155,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)

Expand Down Expand Up @@ -324,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*$',
Expand All @@ -349,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', ''))
Expand Down
18 changes: 17 additions & 1 deletion test/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ 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',
'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)
Expand All @@ -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"""

Expand Down
2 changes: 1 addition & 1 deletion test/headers/ARR
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
2 changes: 1 addition & 1 deletion test/headers/GPLv2
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/headers/LGPLv2+
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/setup/git_config_6
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = [email protected]:sisc-hpc/vsc-jobs-brussel.git
fetch = +refs/heads/*:refs/remotes/origin/*
12 changes: 11 additions & 1 deletion test/shared_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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."""
Expand Down

0 comments on commit 1ca52c7

Please sign in to comment.