Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* Toon Willems (Ghent University)
"""
import base64
import copy
import getpass
import glob
import functools
Expand Down Expand Up @@ -1280,9 +1279,19 @@ def push_branch_to_github(git_repo, target_account, target_repo, branch):

def is_patch_for(patch_name, ec):
"""Check whether specified patch matches any patch in the provided EasyConfig instance."""
res = False
# Extract name from patch entry
def get_name(patch):
if isinstance(patch, (tuple, list)):
patch = patch[0]
elif isinstance(patch, dict):
try:
patch = patch['name']
except KeyError:
raise EasyBuildError(f"Invalid patch spec in {ec.path}: Missing 'name' key",
exit_code=EasyBuildExit.VALUE_ERROR)
return patch

patches = copy.copy(ec['patches'])
patches = [get_name(p) for p in ec['patches']]

with ec.disable_templating():
# take into account both list of extensions (via exts_list) and components (cfr. Bundle easyblock)
Expand All @@ -1294,17 +1303,9 @@ def is_patch_for(patch_name, ec):
'version': entry[1],
}
options = entry[2]
patches.extend(p[0] % templates if isinstance(p, (tuple, list)) else p % templates
for p in options.get('patches', []))

for patch in patches:
if isinstance(patch, (tuple, list)):
patch = patch[0]
if patch == patch_name:
res = True
break
patches.extend(get_name(p) % templates for p in options.get('patches', []))

return res
return patch_name in patches


def det_patch_specs(patch_paths, file_info, ec_dirs):
Expand Down Expand Up @@ -1395,7 +1396,7 @@ def ec_key(path):
soft_name = ec['ec']['name']
break
except EasyBuildError as err:
_log.debug("Ignoring easyconfig %s that fails to parse: %s", path, err)
_log.warning("Ignoring easyconfig %s that fails to parse: %s", path, err)
sys.stdout.write('\r%s of %s easyconfigs checked' % (idx + 1, nr_of_ecs))
sys.stdout.flush()

Expand Down
11 changes: 9 additions & 2 deletions test/framework/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,8 @@ def test_is_patch_for(self):
self.assertFalse(is_patch_for('pi.patch', ec))
self.assertTrue(is_patch_for('pi-3.14.patch', ec))

ec['patches'] = []
ec['patches'] = [{'name': '%(name)s-%(version)s.patch'}]
self.assertTrue(is_patch_for('pi-3.14.patch', ec))

for patch_fn in ('foo.patch', '%(name)s.patch', '%(namelower)s.patch'):
ec['exts_list'] = [('foo', '1.2.3', {'patches': [patch_fn]})]
Expand All @@ -1391,8 +1392,14 @@ def test_is_patch_for(self):
ec['components'] = None
self.assertFalse(is_patch_for('pi.patch', ec))

ec['components'] = [('foo', '1.2.3', {'patches': ['pi.patch']})]
ec['components'] = [('foo', '1.2.3',
{'patches': [
'pi.patch',
{'name': 'ext_%(name)s-%(version)s.patch'},
],
})]
self.assertTrue(is_patch_for('pi.patch', ec))
self.assertTrue(is_patch_for('ext_foo-1.2.3.patch', ec))


def suite():
Expand Down