Skip to content

Commit 7ffa9de

Browse files
Merge pull request #3936 from boegel/patch_ext_zipped
take into account that patch files can also be zipped when checking filename extension for patches
2 parents 96ec0c5 + 1b303db commit 7ffa9de

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

easybuild/tools/filetools.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@
163163
'.sh': "cp -a %(filepath)s .",
164164
}
165165

166+
ZIPPED_PATCH_EXTS = ('.bz2', '.gz', '.xz')
167+
166168
# global set of names of locks that were created in this session
167169
global_lock_names = set()
168170

@@ -1493,8 +1495,11 @@ def create_patch_info(patch_spec):
14931495
str(patch_spec))
14941496

14951497
elif isinstance(patch_spec, string_type):
1496-
if not patch_spec.endswith('.patch'):
1497-
_log.deprecated("Use of patch file with filename that doesn't end with .patch: %s" % patch_spec, '5.0')
1498+
allowed_patch_exts = ['.patch' + x for x in ('',) + ZIPPED_PATCH_EXTS]
1499+
if not any(patch_spec.endswith(x) for x in allowed_patch_exts):
1500+
msg = "Use of patch file with filename that doesn't end with correct extension: %s " % patch_spec
1501+
msg += "(should be any of: %s)" % (', '.join(allowed_patch_exts))
1502+
_log.deprecated(msg, '5.0')
14981503
patch_info = {'name': patch_spec}
14991504
else:
15001505
error_msg = "Wrong patch spec, should be string of 2-tuple with patch name + argument: %s"
@@ -1548,7 +1553,7 @@ def apply_patch(patch_file, dest, fn=None, copy=False, level=None, use_git_am=Fa
15481553
# split in stem (filename w/o extension) + extension
15491554
patch_stem, patch_extension = os.path.splitext(os.path.split(abs_patch_file)[1])
15501555
# Supports only bz2, gz and xz. zip can be archives which are not supported.
1551-
if patch_extension in ['.gz', '.bz2', '.xz']:
1556+
if patch_extension in ZIPPED_PATCH_EXTS:
15521557
# split again to get the second extension
15531558
patch_subextension = os.path.splitext(patch_stem)[1]
15541559
if patch_subextension == ".patch":

test/framework/filetools.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,11 +1638,14 @@ def test_create_patch_info(self):
16381638
stderr = self.get_stderr()
16391639
self.mock_stderr(False)
16401640
self.disallow_deprecated_behaviour()
1641-
expected_warning = "Use of patch file with filename that doesn't end with .patch: foo.txt"
1642-
self.assertTrue(expected_warning in stderr)
1641+
expected_warning = "Use of patch file with filename that doesn't end with correct extension: foo.txt "
1642+
expected_warning += "(should be any of: .patch, .patch.bz2, .patch.gz, .patch.xz)"
1643+
fail_msg = "Warning '%s' should appear in stderr output: %s" % (expected_warning, stderr)
1644+
self.assertTrue(expected_warning in stderr, fail_msg)
16431645

16441646
# deprecation warning is treated as an error in context of unit test suite
1645-
self.assertErrorRegex(EasyBuildError, expected_warning, ft.create_patch_info, 'foo.txt')
1647+
expected_error = expected_warning.replace('(', '\\(').replace(')', '\\)')
1648+
self.assertErrorRegex(EasyBuildError, expected_error, ft.create_patch_info, 'foo.txt')
16461649

16471650
# faulty input
16481651
error_msg = "Wrong patch spec"

0 commit comments

Comments
 (0)