Skip to content

Commit 4fc1270

Browse files
authored
Merge pull request #4865 from Flamefire/fix-patch-for
Fix `is_patch_for` for patch dicts
2 parents 8a4e45b + 64ad44b commit 4fc1270

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

easybuild/tools/github.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
* Toon Willems (Ghent University)
3333
"""
3434
import base64
35-
import copy
3635
import getpass
3736
import glob
3837
import functools
@@ -1280,9 +1279,19 @@ def push_branch_to_github(git_repo, target_account, target_repo, branch):
12801279

12811280
def is_patch_for(patch_name, ec):
12821281
"""Check whether specified patch matches any patch in the provided EasyConfig instance."""
1283-
res = False
1282+
# Extract name from patch entry
1283+
def get_name(patch):
1284+
if isinstance(patch, (tuple, list)):
1285+
patch = patch[0]
1286+
elif isinstance(patch, dict):
1287+
try:
1288+
patch = patch['name']
1289+
except KeyError:
1290+
raise EasyBuildError(f"Invalid patch spec in {ec.path}: Missing 'name' key",
1291+
exit_code=EasyBuildExit.VALUE_ERROR)
1292+
return patch
12841293

1285-
patches = copy.copy(ec['patches'])
1294+
patches = [get_name(p) for p in ec['patches']]
12861295

12871296
with ec.disable_templating():
12881297
# take into account both list of extensions (via exts_list) and components (cfr. Bundle easyblock)
@@ -1294,17 +1303,9 @@ def is_patch_for(patch_name, ec):
12941303
'version': entry[1],
12951304
}
12961305
options = entry[2]
1297-
patches.extend(p[0] % templates if isinstance(p, (tuple, list)) else p % templates
1298-
for p in options.get('patches', []))
1299-
1300-
for patch in patches:
1301-
if isinstance(patch, (tuple, list)):
1302-
patch = patch[0]
1303-
if patch == patch_name:
1304-
res = True
1305-
break
1306+
patches.extend(get_name(p) % templates for p in options.get('patches', []))
13061307

1307-
return res
1308+
return patch_name in patches
13081309

13091310

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

test/framework/github.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,8 @@ def test_is_patch_for(self):
13811381
self.assertFalse(is_patch_for('pi.patch', ec))
13821382
self.assertTrue(is_patch_for('pi-3.14.patch', ec))
13831383

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

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

1394-
ec['components'] = [('foo', '1.2.3', {'patches': ['pi.patch']})]
1395+
ec['components'] = [('foo', '1.2.3',
1396+
{'patches': [
1397+
'pi.patch',
1398+
{'name': 'ext_%(name)s-%(version)s.patch'},
1399+
],
1400+
})]
13951401
self.assertTrue(is_patch_for('pi.patch', ec))
1402+
self.assertTrue(is_patch_for('ext_foo-1.2.3.patch', ec))
13961403

13971404

13981405
def suite():

0 commit comments

Comments
 (0)