Repository: easybuilders/easybuild-framework

Issue:
inject-checksums adds an extra checksums = [...] when an empty checksum= [] exists
Example
```
easyblock = 'CMakeMake'

name = 'mpifileutils'
version = "0.10.1"

homepage = 'https://hpc.github.io/mpifileutils/'

description = """
 MPI-Based File Utilities For Distributed Systems
"""

toolchain = {'name': 'gompi', 'version': '2020a'}

source_urls = ['https://github.com/hpc/%(name)s/archive/']
sources = ['v%(version)s.tar.gz']
patches = ['mpifileutils-%(version)s_fix_acl_xattr_problem.patch']
checksums = []
...
```
doing inject-checksums on the above results in
```
source_urls = ['https://github.com/hpc/%(name)s/archive/']
sources = ['v%(version)s.tar.gz']
patches = ['mpifileutils-%(version)s_fix_acl_xattr_problem.patch']
checksums = [
    '4c8409ef4140f6f557d0e93f0c1267baf5d893c203b29fb7a33d9bc3c5a5d25c',  # v0.10.1.tar.gz
    # mpifileutils-0.10.1_fix_acl_xattr_problem.patch
    'e540ceaeb99758f4776252069d56b703411824ba83f48b474fc18785868151a2',
]

checksums = []
```



Discussion:

Resolving patch:
diff --git a/easybuild/framework/easyblock.py b/easybuild/framework/easyblock.py
--- a/easybuild/framework/easyblock.py
+++ b/easybuild/framework/easyblock.py
@@ -3657,11 +3657,11 @@ def make_checksum_lines(checksums, indent_level):
 
         checksums_txt = '\n'.join(checksum_lines)
 
-        # if any checksums were provided before, get rid of them
-        if app.cfg['checksums']:
+        # if 'checksums' is specified in easyconfig file, get rid of it (even if it's just an empty list)
+        checksums_regex = re.compile(r'^checksums(?:.|\n)+?\]\s*$', re.M)
+        if checksums_regex.search(ectxt):
             _log.debug("Removing existing 'checksums' easyconfig parameter definition...")
-            regex = re.compile(r'^checksums(?:.|\n)+?\]\s*$', re.M)
-            ectxt = regex.sub('', ectxt)
+            ectxt = checksums_regex.sub('', ectxt)
 
         # it is possible no sources (and hence patches) are listed, e.g. for 'bundle' easyconfigs
         if app.src:


Test patch:
diff --git a/test/framework/options.py b/test/framework/options.py
--- a/test/framework/options.py
+++ b/test/framework/options.py
@@ -5128,6 +5128,32 @@ def test_inject_checksums(self):
         ]
         self.assertEqual(ec['checksums'], checksums)
 
+        # check whether empty list of checksums is stripped out by --inject-checksums
+        toy_ec_txt = read_file(toy_ec)
+
+        regex = re.compile(r'^checksums(?:.|\n)*?\]\s*$', re.M)
+        toy_ec_txt = regex.sub('', toy_ec_txt)
+
+        toy_ec_txt += "\nchecksums = []"
+
+        write_file(test_ec, toy_ec_txt)
+        args = [test_ec, '--inject-checksums', '--force']
+        self._run_mock_eb(args, raise_error=True, strip=True)
+
+        ec_txt = read_file(test_ec)
+        regex = re.compile(r"^checksums = \[\]", re.M)
+        self.assertFalse(regex.search(ec_txt), "Pattern '%s' should not be found in: %s" % (regex.pattern, ec_txt))
+
+        ec = EasyConfigParser(test_ec).get_config_dict()
+        expected_checksums = [
+            '44332000aa33b99ad1e00cbd1a7da769220d74647060a10e807b916d73ea27bc',
+            '81a3accc894592152f81814fbf133d39afad52885ab52c25018722c7bda92487',
+            '4196b56771140d8e2468fb77f0240bc48ddbf5dabafe0713d612df7fafb1e458'
+        ]
+        self.assertEqual(ec['checksums'], expected_checksums)
+
+        # passing easyconfig filename as argument to --inject-checksums results in error being reported,
+        # because it's not a valid type of checksum
         args = ['--inject-checksums', test_ec]
         self.mock_stdout(True)
         self.mock_stderr(True)