Skip to content

Commit 87b733a

Browse files
committed
add required flag to filetools.find_extension() method
1 parent d7195c7 commit 87b733a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

easybuild/tools/filetools.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,18 +1404,20 @@ def get_local_dirs_purged():
14041404
return new_dir
14051405

14061406

1407-
def find_extension(filename):
1407+
def find_extension(filename, required=True):
14081408
"""Find best match for filename extension."""
14091409
# sort by length, so longest file extensions get preference
14101410
suffixes = sorted(EXTRACT_CMDS.keys(), key=len, reverse=True)
14111411
pat = r'(?P<ext>%s)$' % '|'.join([s.replace('.', '\\.') for s in suffixes])
14121412
res = re.search(pat, filename, flags=re.IGNORECASE)
1413+
14131414
if res:
1414-
ext = res.group('ext')
1415-
else:
1415+
return res.group('ext')
1416+
1417+
if required:
14161418
raise EasyBuildError("%s has unknown file extension", filename)
14171419

1418-
return ext
1420+
return None
14191421

14201422

14211423
def extract_cmd(filepath, overwrite=False):
@@ -2682,7 +2684,7 @@ def get_source_tarball_from_git(filename, target_dir, git_config):
26822684
if not url:
26832685
raise EasyBuildError("url not specified in git_config parameter")
26842686

2685-
file_ext = find_extension(filename)
2687+
file_ext = find_extension(filename, required=False)
26862688
if file_ext:
26872689
print_warning(f"Ignoring extension of filename '{filename}' set in git_config parameter")
26882690
filename = filename[:-len(file_ext)]

0 commit comments

Comments
 (0)