# Source: https://fastcore.fast.ai/xdg.html.md

# XDG


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

See the [XDG Base Directory
Specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)
for more information.

## Overview

[`xdg_cache_home`](https://fastcore.fast.ai/xdg.html#xdg_cache_home),
[`xdg_config_home`](https://fastcore.fast.ai/xdg.html#xdg_config_home),
[`xdg_data_home`](https://fastcore.fast.ai/xdg.html#xdg_data_home), and
[`xdg_state_home`](https://fastcore.fast.ai/xdg.html#xdg_state_home)
return `pathlib.Path` objects containing the value of the environment
variable named `XDG_CACHE_HOME`, `XDG_CONFIG_HOME`, `XDG_DATA_HOME`, and
`XDG_STATE_HOME` respectively, or the default defined in the
specification if the environment variable is unset, empty, or contains a
relative path rather than absolute path.

[`xdg_config_dirs`](https://fastcore.fast.ai/xdg.html#xdg_config_dirs)
and [`xdg_data_dirs`](https://fastcore.fast.ai/xdg.html#xdg_data_dirs)
return a list of `pathlib.Path` objects containing the value, split on
colons, of the environment variable named `XDG_CONFIG_DIRS` and
`XDG_DATA_DIRS` respectively, or the default defined in the
specification if the environment variable is unset or empty. Relative
paths are ignored, as per the specification.

[`xdg_runtime_dir`](https://fastcore.fast.ai/xdg.html#xdg_runtime_dir)
returns a `pathlib.Path` object containing the value of the
`XDG_RUNTIME_DIR` environment variable, or `None` if the environment
variable is not set, or contains a relative path rather than absolute
path.

## Helpers

We’ll start by defining a context manager that temporarily sets an
environment variable to demonstrate the behaviour of each helper
function:

``` python
from contextlib import contextmanager
```

``` python
@contextmanager
def env(variable, value):
    old = os.environ.get(variable, None)
    try:
        os.environ[variable] = value
        yield
    finally:
        if old is None: del os.environ[variable]
        else: os.environ[variable] = old
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xdg.py#L27"
target="_blank" style="float:right; font-size:smaller">source</a>

### xdg_cache_home

``` python

def xdg_cache_home(
    
):

```

*Path corresponding to `XDG_CACHE_HOME`*

``` python
from fastcore.test import *
```

``` python
test_eq(xdg_cache_home(), Path.home()/'.cache')
with env('XDG_CACHE_HOME', '/home/fastai/.cache'):
    test_eq(xdg_cache_home(), Path('/home/fastai/.cache'))
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xdg.py#L32"
target="_blank" style="float:right; font-size:smaller">source</a>

### xdg_config_dirs

``` python

def xdg_config_dirs(
    
):

```

*Paths corresponding to `XDG_CONFIG_DIRS`*

``` python
test_eq(xdg_config_dirs(), [Path('/etc/xdg')])
with env('XDG_CONFIG_DIRS', '/home/fastai/.xdg:/home/fastai/.config'):
    test_eq(xdg_config_dirs(), [Path('/home/fastai/.xdg'), Path('/home/fastai/.config')])
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xdg.py#L37"
target="_blank" style="float:right; font-size:smaller">source</a>

### xdg_config_home

``` python

def xdg_config_home(
    
):

```

*Path corresponding to `XDG_CONFIG_HOME`*

``` python
test_eq(xdg_config_home(), Path.home()/'.config')
with env('XDG_CONFIG_HOME', '/home/fastai/.config'):
    test_eq(xdg_config_home(), Path('/home/fastai/.config'))
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xdg.py#L42"
target="_blank" style="float:right; font-size:smaller">source</a>

### xdg_data_dirs

``` python

def xdg_data_dirs(
    
):

```

*Paths corresponding to XDG_DATA_DIRS\`*

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xdg.py#L47"
target="_blank" style="float:right; font-size:smaller">source</a>

### xdg_data_home

``` python

def xdg_data_home(
    
):

```

*Path corresponding to `XDG_DATA_HOME`*

``` python
test_eq(xdg_data_home(), Path.home()/'.local/share')
with env('XDG_DATA_HOME', '/home/fastai/.data'):
    test_eq(xdg_data_home(), Path('/home/fastai/.data'))
```

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xdg.py#L52"
target="_blank" style="float:right; font-size:smaller">source</a>

### xdg_runtime_dir

``` python

def xdg_runtime_dir(
    
):

```

*Path corresponding to `XDG_RUNTIME_DIR`*

------------------------------------------------------------------------

<a
href="https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/xdg.py#L58"
target="_blank" style="float:right; font-size:smaller">source</a>

### xdg_state_home

``` python

def xdg_state_home(
    
):

```

*Path corresponding to `XDG_STATE_HOME`*

``` python
test_eq(xdg_state_home(), Path.home()/'.local/state')
with env('XDG_STATE_HOME', '/home/fastai/.state'):
    test_eq(xdg_state_home(), Path('/home/fastai/.state'))
```

------------------------------------------------------------------------

Copyright © 2016-2021 Scott Stevenson <scott@stevenson.io>

Modifications copyright © 2022 onwards Jeremy Howard