Skip to content

Commit

Permalink
Merge pull request #4725 from boegel/unresolved_templates_fixes
Browse files Browse the repository at this point in the history
fall back to getting values with unresolved templates in `EasyBlock.check_checksums_for`
  • Loading branch information
lexming authored Dec 19, 2024
2 parents 64bd214 + b2bee28 commit d336035
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
15 changes: 12 additions & 3 deletions easybuild/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2584,9 +2584,18 @@ 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', [])
# 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:
if isinstance(ent, EasyConfig):
sources = ent.get_ref('sources')
patches = ent.get_ref('patches') + ent.get_ref('postinstallpatches')
checksums = ent.get_ref('checksums')

# Single source should be re-wrapped as a list, and checksums with it
if isinstance(sources, dict):
sources = [sources]
Expand Down
14 changes: 14 additions & 0 deletions test/framework/easyblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2906,6 +2906,20 @@ 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)

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 d336035

Please sign in to comment.