Skip to content

Commit 6278e5a

Browse files
committed
Fix is_patch_for for patch dicts
The function only handled strings and lists but not the dict patch format. This caused a hard error because `p % templates` doesn't work when `p` is a dict --> `TypeError`. Factor out function to extract name of patchspec and use it. This avoids the 2 places where the bug was and simplifies the function.
1 parent 354d0b6 commit 6278e5a

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

easybuild/tools/github.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -1280,9 +1280,19 @@ def push_branch_to_github(git_repo, target_account, target_repo, branch):
12801280

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

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

12871297
with ec.disable_templating():
12881298
# take into account both list of extensions (via exts_list) and components (cfr. Bundle easyblock)
@@ -1294,17 +1304,9 @@ def is_patch_for(patch_name, ec):
12941304
'version': entry[1],
12951305
}
12961306
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
1307+
patches.extend(get_name(p) % templates for p in options.get('patches', []))
13061308

1307-
return res
1309+
return patch_name in patches
13081310

13091311

13101312
def det_patch_specs(patch_paths, file_info, ec_dirs):

test/framework/github.py

+9-2
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)