Skip to content

Commit d336035

Browse files
authored
Merge pull request #4725 from boegel/unresolved_templates_fixes
fall back to getting values with unresolved templates in `EasyBlock.check_checksums_for`
2 parents 64bd214 + b2bee28 commit d336035

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

easybuild/framework/easyblock.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2584,9 +2584,18 @@ def check_checksums_for(self, ent, sub='', source_cnt=None):
25842584
ec_fn = os.path.basename(self.cfg.path)
25852585
checksum_issues = []
25862586

2587-
sources = ent.get('sources', [])
2588-
patches = ent.get('patches', []) + ent.get('postinstallpatches', [])
2589-
checksums = ent.get('checksums', [])
2587+
# try to get value with templates resolved, but fall back to not resolving templates;
2588+
# this is better for error reporting that includes names of source files
2589+
try:
2590+
sources = ent.get('sources', [])
2591+
patches = ent.get('patches', []) + ent.get('postinstallpatches', [])
2592+
checksums = ent.get('checksums', [])
2593+
except EasyBuildError:
2594+
if isinstance(ent, EasyConfig):
2595+
sources = ent.get_ref('sources')
2596+
patches = ent.get_ref('patches') + ent.get_ref('postinstallpatches')
2597+
checksums = ent.get_ref('checksums')
2598+
25902599
# Single source should be re-wrapped as a list, and checksums with it
25912600
if isinstance(sources, dict):
25922601
sources = [sources]

test/framework/easyblock.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,20 @@ def run_checks():
29062906
eb.json_checksums = None
29072907
self.assertEqual(eb.check_checksums(), [])
29082908

2909+
# more checks for check_checksums_for method, which also takes regular dict as input
2910+
self.assertEqual(eb.check_checksums_for({}), [])
2911+
expected = "Checksums missing for one or more sources/patches in test.eb: "
2912+
expected += "found 1 sources + 0 patches vs 0 checksums"
2913+
self.assertEqual(eb.check_checksums_for({'sources': ['test.tar.gz']}), [expected])
2914+
2915+
# example from QuantumESPRESSO easyconfig, template used in extract_cmd should not cause trouble
2916+
eb.cfg['sources'] = [{
2917+
'filename': 'q-e-qe-%(version)s.tar.gz',
2918+
'extract_cmd': 'mkdir -p %(builddir)s/qe-%(version)s && tar xzvf %s --strip-components=1 -C $_',
2919+
'source_urls': ['https://gitlab.com/QEF/q-e/-/archive/qe-%(version)s'],
2920+
}]
2921+
res = eb.check_checksums_for(eb.cfg)
2922+
29092923
def test_this_is_easybuild(self):
29102924
"""Test 'this_is_easybuild' function (and get_git_revision function used by it)."""
29112925
# make sure both return a non-Unicode string

0 commit comments

Comments
 (0)