Skip to content
Snippets Groups Projects
Commit 2ec50ebd authored by Chris Lamb's avatar Chris Lamb :eyes:
Browse files

If we specify a suffix for temporary file or directory, ensure it starts with...

If we specify a suffix for temporary file or directory, ensure it starts with a "_" to make the generated filenames a bit more human-readable.
parent 07c016a3
No related branches found
No related tags found
No related merge requests found
Pipeline #280822 passed
......@@ -35,6 +35,9 @@ logger = logging.getLogger(__name__)
def get_named_temporary_file(*args, **kwargs):
kwargs["dir"] = kwargs.pop("dir", _get_base_temporary_directory())
if not kwargs.get("suffix", "_").startswith("_"):
kwargs["suffix"] = "_{}".format(kwargs["suffix"])
f = tempfile.NamedTemporaryFile(*args, **kwargs)
_FILES.append(f.name)
......@@ -61,6 +64,9 @@ def get_temporary_directory(*args, **kwargs):
"""
kwargs["dir"] = kwargs.pop("dir", _get_base_temporary_directory())
if not kwargs.get("suffix", "_").startswith("_"):
kwargs["suffix"] = "_{}".format(kwargs["suffix"])
d = tempfile.TemporaryDirectory(*args, **kwargs)
return d
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment