Skip to content

Commit 1ca52c7

Browse files
authored
Merge pull request #101 from wpoely86/vub
Add support for VUB
2 parents ee7b08d + 717854f commit 1ca52c7

File tree

8 files changed

+83
-22
lines changed

8 files changed

+83
-22
lines changed

lib/vsc/install/headers.py

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def nicediff(txta, txtb, offset=5):
6363
res_idx = []
6464
# very bruteforce
6565
for didx in different_idx:
66-
for idx in range(max(didx-offset, 0), min(didx+offset, len(diff)-1)):
66+
for idx in range(max(didx - offset, 0), min(didx + offset, len(diff) - 1)):
6767
if idx not in res_idx:
6868
res_idx.append(idx)
6969
res_idx.sort()
@@ -102,7 +102,7 @@ def get_header(filename, script=False):
102102
blocks = ['', '']
103103
elif blocks[0] != '':
104104
# the block before the begin of text is always empty
105-
raise Exception('unexpected non-emtpy block with get_header %s: %s' % (filename, blocks))
105+
raise Exception('unexpected non-empty block with get_header %s: %s' % (filename, blocks))
106106

107107
header = blocks[1]
108108

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

136+
found = False
137+
for github_organ in institute_details.keys():
138+
if github_organ in kwargs.get('url', ''):
139+
kwargs.update(institute_details[github_organ])
140+
found = True
141+
break
142+
143+
if not found:
144+
raise Exception('Unable to find a known github organization in url %s' % kwargs.get('url'))
145+
136146
return template.format(**kwargs)
137147

138148

@@ -195,7 +205,7 @@ def check_header(filename, script=False, write=False):
195205
if file_ext == '.py':
196206
if shebang != SHEBANG_ENV_PYTHON:
197207
log.info("Wrong shebang for Python script %s: found '%s', should be '%s'",
198-
filename, shebang, SHEBANG_ENV_PYTHON)
208+
filename, shebang, SHEBANG_ENV_PYTHON)
199209
shebang = SHEBANG_ENV_PYTHON
200210

201211
elif file_ext in ['.sh', '']:
@@ -273,16 +283,32 @@ def check_header(filename, script=False, write=False):
273283
# return different or not
274284
return changed
275285

286+
287+
# mapping of the github organization to the details
288+
# to fill in the license templates
289+
institute_details = {
290+
'hpcugent': {
291+
'university_name': 'Ghent University',
292+
'university_url': 'http://ugent.be/hpc',
293+
'university_team_url': 'http://ugent.be/hpc/en',
294+
},
295+
'sisc-hpc': {
296+
'university_name': 'Vrije Universiteit Brussel',
297+
'university_url': 'https://www.vub.be',
298+
'university_team_url': 'https://hpc.vub.be',
299+
},
300+
}
301+
276302
#
277303
# Only template headers below
278304
#
279305

280306
LGPLv2_plus__TEMPLATE = """#
281-
# Copyright {beginyear}-{endyear} Ghent University
307+
# Copyright {beginyear}-{endyear} {university_name}
282308
#
283309
# This file is part of {name},
284-
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
285-
# with support of Ghent University (http://ugent.be/hpc),
310+
# originally created by the HPC team of {university_name} ({university_team_url}),
311+
# with support of {university_name} ({university_url}),
286312
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
287313
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
288314
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
@@ -305,11 +331,11 @@ def check_header(filename, script=False, write=False):
305331
"""
306332

307333
GPLv2_TEMPLATE = """#
308-
# Copyright {beginyear}-{endyear} Ghent University
334+
# Copyright {beginyear}-{endyear} {university_name}
309335
#
310336
# This file is part of {name},
311-
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
312-
# with support of Ghent University (http://ugent.be/hpc),
337+
# originally created by the HPC team of {university_name} ({university_team_url}),
338+
# with support of {university_name} ({university_url}),
313339
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
314340
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
315341
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
@@ -331,11 +357,11 @@ def check_header(filename, script=False, write=False):
331357
"""
332358

333359
ARR_TEMPLATE = """#
334-
# Copyright {beginyear}-{endyear} Ghent University
360+
# Copyright {beginyear}-{endyear} {university_name}
335361
#
336362
# This file is part of {name},
337-
# originally created by the HPC team of Ghent University (http://ugent.be/hpc/en),
338-
# with support of Ghent University (http://ugent.be/hpc),
363+
# originally created by the HPC team of {university_name} ({university_team_url}),
364+
# with support of {university_name} ({university_url}),
339365
# the Flemish Supercomputer Centre (VSC) (https://www.vscentrum.be),
340366
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
341367
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).

lib/vsc/install/shared_setup.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ def _log(self, level, msg, args):
137137
lm = ('Luis Fernando Munoz Meji?as', '[email protected]')
138138
sdw = ('Stijn De Weirdt', '[email protected]')
139139
wdp = ('Wouter Depypere', '[email protected]')
140-
wp = ('Ward Poelmans', '[email protected]')
140+
wp = ('Ward Poelmans', '[email protected]')
141+
sm = ('Samuel Moors', '[email protected]')
141142

142143
# Regexp used to remove suffixes from scripts when installing(/packaging)
143144
REGEXP_REMOVE_SUFFIX = re.compile(r'(\.(?:py|sh|pl))$')
@@ -155,7 +156,7 @@ def _log(self, level, msg, args):
155156

156157
RELOAD_VSC_MODS = False
157158

158-
VERSION = '0.12.2'
159+
VERSION = '0.12.3'
159160

160161
log.info('This is (based on) vsc.install.shared_setup %s' % VERSION)
161162

@@ -324,8 +325,8 @@ def get_name_url(self, filename=None, version=None, license_name=None):
324325
],
325326
'url': [
326327
r'^Home-page:\s*(.*?)\s*$',
327-
r'^\s*url\s*=\s*((?:https?|ssh).*?github.*?[:/]hpcugent/.*?)\.git\s*$',
328-
r'^\s*url\s*=\s*(git[:@].*?github.*?[:/]hpcugent/.*?)(?:\.git)?\s*$',
328+
r'^\s*url\s*=\s*((?:https?|ssh).*?github.*?[:/](?:hpcugent|sisc-hpc)/.*?)\.git\s*$',
329+
r'^\s*url\s*=\s*(git[:@].*?github.*?[:/](?:hpcugent|sisc-hpc)/.*?)(?:\.git)?\s*$',
329330
],
330331
'download_url': [
331332
r'^Download-URL:\s*(.*?)\s*$',
@@ -349,7 +350,7 @@ def get_name_url(self, filename=None, version=None, license_name=None):
349350
self.private_repo = True
350351

351352
if 'url' not in res:
352-
raise KeyError("Missing url in git config %s. (Missing mandatory hpcugent (upstream) remote?)" % (res))
353+
raise KeyError("Missing url in git config %s. (Missing mandatory hpcugent or sisc-hpc remote?)" % (res))
353354

354355
# handle git://server/user/project
355356
reg = re.search(r'^(git|ssh)://', res.get('url', ''))

test/headers.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ def test_gen_license_header(self):
107107
'name': 'projectname',
108108
'beginyear': 1234,
109109
'endyear': 5678,
110-
'url': 'https://example.com/projectname',
110+
'url': 'https://github.com/hpcugent/projectname',
111+
}
112+
data_brussel = {
113+
'name': 'projectname',
114+
'beginyear': 1234,
115+
'endyear': 5678,
116+
'url': 'https://github.com/sisc-hpc/projectname',
111117
}
112118
for license in KNOWN_LICENSES.keys():
113119
res_fn = os.path.join(self.setup.REPO_TEST_DIR, 'headers', license)
@@ -117,6 +123,16 @@ def test_gen_license_header(self):
117123
self.assertEqual(gen_txt, result, msg='generated header for license %s as expected' % license)
118124
log.info('generated license header %s' % license)
119125

126+
gen_txt_bru = gen_license_header(license, **data_brussel)
127+
self.assertNotRegexpMatches(gen_txt_bru, 'Ghent University',
128+
msg='No reference to Ghent University in header')
129+
self.assertNotRegexpMatches(gen_txt_bru, r'ugent\.be',
130+
msg='No reference to ugent.be University in header')
131+
self.assertRegexpMatches(gen_txt_bru, r'the HPC team of Vrije Universiteit Brussel \(https://hpc.vub.be\)',
132+
msg='generted header for Brussel is correct for %s' % license)
133+
self.assertRegexpMatches(gen_txt_bru, r'support of Vrije Universiteit Brussel \(https://www.vub.be\)',
134+
msg='generted header for Brussel is correct for %s' % license)
135+
120136
def test_begin_end_from_header(self):
121137
"""Test begin_end_from_header method"""
122138

test/headers/ARR

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
99
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
1010
#
11-
# https://example.com/projectname
11+
# https://github.com/hpcugent/projectname
1212
#
1313
# All rights reserved.
1414
#

test/headers/GPLv2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
99
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
1010
#
11-
# https://example.com/projectname
11+
# https://github.com/hpcugent/projectname
1212
#
1313
# projectname is free software: you can redistribute it and/or modify
1414
# it under the terms of the GNU General Public License as published by

test/headers/LGPLv2+

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# the Flemish Research Foundation (FWO) (http://www.fwo.be/en)
99
# and the Department of Economy, Science and Innovation (EWI) (http://www.ewi-vlaanderen.be/en).
1010
#
11-
# https://example.com/projectname
11+
# https://github.com/hpcugent/projectname
1212
#
1313
# projectname is free software: you can redistribute it and/or modify
1414
# it under the terms of the GNU Library General Public License as

test/setup/git_config_6

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = false
5+
logallrefupdates = true
6+
[remote "origin"]
7+
url = [email protected]:sisc-hpc/vsc-jobs-brussel.git
8+
fetch = +refs/heads/*:refs/remotes/origin/*

test/shared_setup.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ def test_get_name_url(self):
6363
license_name='LGPLv2+'), res,
6464
msg='determined name and url from %s file with license' % fn)
6565

66+
fn = 'git_config_6'
67+
res_brussel = {
68+
'name': 'vsc-jobs-brussel',
69+
'url': 'https://github.com/sisc-hpc/vsc-jobs-brussel',
70+
'download_url': 'https://github.com/sisc-hpc/vsc-jobs-brussel/archive/0.1.0.tar.gz',
71+
}
72+
self.assertEqual(self.setup.get_name_url(os.path.join(self.setup.REPO_TEST_DIR, 'setup', fn), version='0.1.0'),
73+
res_brussel,
74+
msg='determined name and url from %s file with license' % fn)
75+
6676
def test_sanitize(self):
6777
"""Test sanitize function"""
6878
os.environ['VSC_RPM_PYTHON'] = '1'
@@ -124,7 +134,7 @@ def test_rel_gitignore(self):
124134
def test_import(self):
125135
"""Test importing things from shared_setup.py, these should not be broken for backward compatibility."""
126136
from vsc.install.shared_setup import SHARED_TARGET
127-
from vsc.install.shared_setup import ag, eh, jt, kh, kw, lm, sdw, wdp, wp
137+
from vsc.install.shared_setup import ag, eh, jt, kh, kw, lm, sdw, wdp, wp, sm
128138

129139
def test_action_target(self):
130140
"""Test action_target function, mostly w.r.t. backward compatibility."""

0 commit comments

Comments
 (0)