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

  • delete is supported even on Python 3.11

Added in version 8.0.0.

Parameters:
namespace: str, 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.

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