Skip to content

change default for change_into_dir option in extract_file function to to False #4246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions easybuild/tools/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ def change_dir(path):
return cwd


def extract_file(fn, dest, cmd=None, extra_options=None, overwrite=False, forced=False, change_into_dir=None):
def extract_file(fn, dest, cmd=None, extra_options=None, overwrite=False, forced=False, change_into_dir=False):
"""
Extract file at given path to specified directory
:param fn: path to file to extract
Expand All @@ -439,15 +439,9 @@ def extract_file(fn, dest, cmd=None, extra_options=None, overwrite=False, forced
:param extra_options: extra options to pass to extract command
:param overwrite: overwrite existing unpacked file
:param forced: force extraction in (extended) dry run mode
:param change_into_dir: change into resulting directory;
None (current default) implies True, but this is deprecated,
this named argument should be set to False or True explicitely
(in a future major release, default will be changed to False)
:param change_into_dir: change into resulting directorys
:return: path to directory (in case of success)
"""
if change_into_dir is None:
_log.deprecated("extract_file function was called without specifying value for change_into_dir", '5.0')
change_into_dir = True

if not os.path.isfile(fn) and not build_option('extended_dry_run'):
raise EasyBuildError("Can't extract file %s: no such file", fn)
Expand Down
20 changes: 0 additions & 20 deletions test/framework/filetools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2276,29 +2276,9 @@ def test_extract_file(self):

ft.remove_dir(os.path.join(self.test_prefix, 'toy-0.0'))

# a deprecation warning is printed (which is an error in this context)
# if the 'change_into_dir' named argument was left unspecified
error_pattern = "extract_file function was called without specifying value for change_into_dir"
self.assertErrorRegex(EasyBuildError, error_pattern, ft.extract_file, toy_tarball, self.test_prefix)
self.allow_deprecated_behaviour()

# make sure we're not in self.test_prefix now (checks below assumes so)
self.assertFalse(os.path.samefile(os.getcwd(), self.test_prefix))

# by default, extract_file changes to directory in which source file was unpacked
self.mock_stderr(True)
path = ft.extract_file(toy_tarball, self.test_prefix)
stderr = self.get_stderr().strip()
self.mock_stderr(False)
self.assertTrue(os.path.samefile(path, self.test_prefix))
self.assertTrue(os.path.samefile(os.getcwd(), self.test_prefix))
regex = re.compile("^WARNING: .*extract_file function was called without specifying value for change_into_dir")
self.assertTrue(regex.search(stderr), "Pattern '%s' found in: %s" % (regex.pattern, stderr))

ft.change_dir(cwd)
self.assertFalse(os.path.samefile(os.getcwd(), self.test_prefix))

# no deprecation warning when change_into_dir is set to True
self.mock_stderr(True)
path = ft.extract_file(toy_tarball, self.test_prefix, change_into_dir=True)
stderr = self.get_stderr().strip()
Expand Down