Skip to content

Commit

Permalink
fall back to getting values with unresolved templates in EasyBlock.ch…
Browse files Browse the repository at this point in the history
…eck_checksums_for
  • Loading branch information
boegel committed Dec 19, 2024
1 parent 64bd214 commit 95e071e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
21 changes: 18 additions & 3 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2584,9 +2584,24 @@ def check_checksums_for(self, ent, sub='', source_cnt=None):
ec_fn = os.path.basename(self.cfg.path)
checksum_issues = []

sources = ent.get('sources', [])
patches = ent.get('patches', []) + ent.get('postinstallpatches', [])
checksums = ent.get('checksums', [])
if isinstance(ent, EasyConfig):
# try to get value with templates resolved, but fall back to not resolving templates;
# this is better for error reporting that includes names of source files
try:
sources = ent.get('sources', [])
patches = ent.get('patches', []) + ent.get('postinstallpatches', [])
checksums = ent.get('checksums', [])
except EasyBuildError:
sources = ent.get_ref('sources')
patches = ent.get_ref('patches') + ent.get_ref('postinstallpatches')
checksums = ent.get_ref('checksums')
elif isinstance(ent, dict):
sources = ent.get('sources', [])
patches = ent.get('patches', []) + ent.get('postinstallpatches', [])
checksums = ent.get('checksums', [])
else:
raise EasyBuildError(f"Unexpected value type in EasyBlock.check_checksums_for: {type(ent)}")

# Single source should be re-wrapped as a list, and checksums with it
if isinstance(sources, dict):
sources = [sources]
Expand Down
15 changes: 15 additions & 0 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,21 @@ def run_checks():
eb.json_checksums = None
self.assertEqual(eb.check_checksums(), [])

# more checks for check_checksums_for method, which also takes regular dict as input
self.assertEqual(eb.check_checksums_for({}), [])
expected = "Checksums missing for one or more sources/patches in test.eb: "
expected += "found 1 sources + 0 patches vs 0 checksums"
self.assertEqual(eb.check_checksums_for({'sources': ['test.tar.gz']}), [expected])

# example from QuantumESPRESSO easyconfig, template used in extract_cmd should not cause trouble
eb.cfg['sources'] = [{
'filename': 'q-e-qe-%(version)s.tar.gz',
'extract_cmd': 'mkdir -p %(builddir)s/qe-%(version)s && tar xzvf %s --strip-components=1 -C $_',
'source_urls': ['https://gitlab.com/QEF/q-e/-/archive/qe-%(version)s'],
}]
res = eb.check_checksums_for(eb.cfg)
print(res)

def test_this_is_easybuild(self):
"""Test 'this_is_easybuild' function (and get_git_revision function used by it)."""
# make sure both return a non-Unicode string
Expand Down

0 comments on commit 95e071e

Please sign in to comment.