temporary_config_dir_path#

astropy.config.temporary_config_dir_path(dir_=None, /, *, namespace, suffix=None, prefix=None, delete=True)[source]#

A context manager to create a temporary directory and define it as the configuration directory associated with some namespace.

The directory returned will shadow both ASTROPY_CONFIG_DIR and XDG_CONFIG_HOME environment variable if defined.

This may also be used as a decorator on a function to set the config path just within that function.

Thread safety is guaranteed, but concurrency isn’t: only a single thread at a time may execute code within this context.

All arguments from tempfile.TemporaryDirectory are optionally supported, with a couple differences:

  • dir is positional-only and must come first

  • all other arguments are keyword-only

Added in version 8.0.

Parameters:
dir_path-like object or None, optional, positional-only

The directory in which to create the temporary directory. None (default) uses the platform default, as in tempfile.TemporaryDirectory.

namespacestr, keyword-only

A mandatory unique identifier for the namespace associated to a temporary directory, which will used to name the directory itself. This string must be non-empty, and can only contain alphanumeric characters, _, - or .. . is special cased to represent a path separator (see os.sep) in the output directory.

suffixstr or None, optional, keyword-only

Passed to tempfile.TemporaryDirectory.

prefixstr or None, optional, keyword-only

Passed to tempfile.TemporaryDirectory.

deletebool, optional, keyword-only

Whether to delete the directory when exiting the context. Default is True. Passed to tempfile.TemporaryDirectory.

See also

temporary_cache_dir_path

a similar function for cache directories

set_temp_config

a legacy function with similar goals but a much less predictable behavior