=
=
# Kinds of temporary directories. Only needed for ones that are
# globally-managed.
=
: = None
global
, = ,
yield
=
"""Manages temp directory behavior"""
: =
"""Indicate whether a TempDirectory of the given kind should be
auto-deleted.
"""
=
"""Get configured auto-delete flag for a given TempDirectory type,
default True.
"""
return
: = None
"""Provides a scoped global tempdir registry that can be used to dictate
whether directories should be deleted.
"""
global
=
=
yield
=
pass
=
"""Helper class that owns and cleans up a temporary directory.
This class can be used as a context manager or as an OO representation of a
temporary directory.
Attributes:
path
Location to the created temporary directory
delete
Whether the directory should be deleted when exiting
(when used as a contextmanager)
Methods:
cleanup()
Deletes the temporary directory
When used as a context manager, if the delete attribute is True, on
exiting the context the temporary directory is deleted.
"""
# If we were given an explicit directory, resolve delete option
# now.
= False
# Otherwise, we wait until cleanup and see what
# tempdir_registry says.
= None
# The only time we specify path is in for editables where it
# is the value of the --src option.
=
=
= False
=
=
=
assert is not None
assert not , f
return
return f
return
=
:
=
= True
"""Create a temporary directory and store its path in self.path"""
# We realpath here because some systems have their default tmpdir
# symlinked to another directory. This tends to confuse build
# scripts, so we canonicalize the path by traversing potential
# symlinks here.
=
return
"""Remove the temporary directory created and reset state"""
= True
return
: =
"""Log a warning for a `rmtree` error and continue"""
=
= # remove trailing new line
# first try with tenacity; retrying to handle ephemeral errors
# last pass ignore/log all errors
"""Helper class that creates a temporary directory adjacent to a real one.
Attributes:
original
The original directory to create a temp directory for.
path
After calling create() or entering, contains the full
path to the temporary directory.
delete
Whether the directory should be deleted when exiting
(when used as a contextmanager)
"""
# The characters that may be used to name the temp directory
# We always prepend a ~ and then rotate through these until
# a usable name is found.
# pkg_resources raises a different error for .dist-info folder
# with leading '-' and invalid metadata
=
=
"""Generates a series of temporary names.
The algorithm replaces the leading characters in the name
with ones that are valid filesystem characters, but are not
valid package names (for both Python and pip definitions of
package).
"""
= + +
yield
# If we make it this far, we will have to make a longer name
= + +
yield
, =
=
# Continue if the name exists already
=
break
# Final fallback on the default behavior.
=
return