Skip to content
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

Update tmpdir and tmpfile context manager docstrings #8270

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions dask/utils.py
Expand Up @@ -165,6 +165,33 @@ def import_required(mod_name, error_msg):

@contextmanager
def tmpfile(extension="", dir=None):
"""
Function to create and return a unique temporary file with the given extension, if provided.

Parameters
----------
extension : str
The extension of the temporary file to be created
dir : str
The name of the directory to create the file, if is not None, the file will be created in that directory,
otherwise a default directory is used.
mesejo marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
out : str
The name of the temporary file
mesejo marked this conversation as resolved.
Show resolved Hide resolved

See Also
--------
NamedTemporaryFile : Built-in alternative for creating temporary files
tmp_path : pytest fixture for creating a temporary directory unique to the test invocation

Notes
-----
This function is meant to be used for testing purposes. Should be preferred over
pytest fixture tmp_path when multiple files are needed inside a test invocation.
As opposed to the built-in NamedTemporaryFile can be used in Windows NT or later
mesejo marked this conversation as resolved.
Show resolved Hide resolved
"""
extension = "." + extension.lstrip(".")
handle, filename = tempfile.mkstemp(extension, dir=dir)
os.close(handle)
Expand All @@ -183,6 +210,25 @@ def tmpfile(extension="", dir=None):

@contextmanager
def tmpdir(dir=None):
"""
Function to create and return a unique temporary directory.

Parameters
----------
dir : str
The name of the directory to create the file, if is not None, the file will be created in that directory,
otherwise a default directory is used.
mesejo marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
out : str
The name of the temporary directory
mesejo marked this conversation as resolved.
Show resolved Hide resolved

Notes
-----
This function is meant to be used for testing purposes. Should be preferred over
pytest fixture tmp_path when multiple directories are needed inside a test invocation.
mesejo marked this conversation as resolved.
Show resolved Hide resolved
"""
dirname = tempfile.mkdtemp(dir=dir)

try:
Expand Down