Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Use a subdirectory of $XDG_CONFIG_HOME instead of ~/.matplotlibrc on Linux#454
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
…and cache directories
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -146,19 +146,6 @@ | ||
sys.argv = ['modpython'] | ||
import sys, os, tempfile | ||
if sys.version_info[0] >= 3: | ||
@@ -525,50 +512,104 @@ def _create_tmp_config_dir(): | ||
get_home = verbose.wrap('$HOME=%s', _get_home, always=False) | ||
def_get_xdg_config_dir(): | ||
""" | ||
Returns the XDG configuration directory, according to the `XDG | ||
base directory spec | ||
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_. | ||
""" | ||
return os.environ.get('XDG_CONFIG_HOME', os.path.join(get_home(), '.config')) | ||
def _get_xdg_cache_dir(): | ||
""" | ||
Returns the XDG cache directory, according to the `XDG | ||
base directory spec | ||
<http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html>`_. | ||
""" | ||
return os.environ.get('XDG_CACHE_HOME', os.path.join(get_home(), '.cache')) | ||
def _get_config_or_cache_dir(xdg_base): | ||
from matplotlib.cbook import mkdirs | ||
configdir = os.environ.get('MPLCONFIGDIR') | ||
if configdir is not None: | ||
if not os.path.exists(configdir): | ||
from matplotlib.cbook import mkdirs | ||
mkdirs(configdir) | ||
if not _is_writable_dir(configdir): | ||
return _create_tmp_config_dir() | ||
return configdir | ||
h = get_home() | ||
ifsys.platform.startswith('linux'): | ||
xdg_path = os.path.join(xdg_base, 'matplotlib') | ||
p = os.path.join(h, '.matplotlib') | ||
if os.path.exists(p): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. This is the bit which causes the warning for people with a cache but not necessarily a matplotlibrc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Ah, I see. I'll fix that up. | ||
warnings.warn( | ||
"Found matplotlib configuration in ~/.matplotlib. " | ||
"To conform with the XDG base directory standard, " | ||
"this configuration directory has been deprecated " | ||
"on Linux, and the new location is now %r. Please " | ||
"move your configuration there to ensure that " | ||
"matplotlib will continue to find it in the future." % | ||
xdg_path) | ||
else: | ||
p = xdg_path | ||
else: | ||
p = os.path.join(h, '.matplotlib') | ||
if os.path.exists(p): | ||
if not _is_writable_dir(p): | ||
return _create_tmp_config_dir() | ||
else: | ||
if not _is_writable_dir(h): | ||
return _create_tmp_config_dir() | ||
mkdirs(p) | ||
return p | ||
def _get_configdir(): | ||
""" | ||
Return the string representing the configuration directory. | ||
The directory is chosen as follows: | ||
1. If the MPLCONFIGDIR environment variable is supplied, choose that. | ||
2a. On Linux, if `$HOME/.matplotlib` exists, choose that, but warn that | ||
that is the old location. Barring that, follow the XDG specification | ||
and look first in `$XDG_CONFIG_HOME`, if defined, or `$HOME/.config`. | ||
2b. On other platforms, choose `$HOME/.matplotlib`. | ||
3. If the chosen directory exists and is writable, use that as the | ||
configuration directory. | ||
4. If possible, create a temporary directory, and use it as the | ||
configuration directory. | ||
5. A writable directory could not be found or created; return None. | ||
""" | ||
return _get_config_or_cache_dir(_get_xdg_config_dir()) | ||
get_configdir = verbose.wrap('CONFIGDIR=%s', _get_configdir, always=False) | ||
def _get_cachedir(): | ||
""" | ||
Return the location of the cache directory. | ||
The procedure used to find the directory is the same as for | ||
_get_config_dir, except using `$XDG_CONFIG_HOME`/`~/.cache` instead. | ||
""" | ||
return _get_config_or_cache_dir(_get_xdg_cache_dir()) | ||
get_cachedir = verbose.wrap('CACHEDIR=%s', _get_cachedir, always=False) | ||
def _get_data_path(): | ||
'get the path to matplotlib data' | ||
@@ -643,50 +684,36 @@ def get_py2exe_datafiles(): | ||
def matplotlib_fname(): | ||
""" | ||
Get thelocation of theconfig file. | ||
The file location is determined in the followingorder | ||
- `$PWD/matplotlibrc` | ||
- environment variable `MATPLOTLIBRC` | ||
- `$MPLCONFIGDIR/matplotlib` | ||
- On Linux, | ||
- `$HOME/.matplotlib/matplotlibrc`, if it exists | ||
- or `$XDG_CONFIG_HOME/matplotlib/matplotlibrc` (if | ||
$XDG_CONFIG_HOME is defined) | ||
- or `$HOME/.config/matplotlib/matplotlibrc` (if | ||
$XDG_CONFIG_HOME is not defined) | ||
- On other platforms, | ||
- `$HOME/.matplotlib/matplotlibrc` if `$HOME` is defined. | ||
- Lastly, it looks in `$MATPLOTLIBDATA/matplotlibrc` for a | ||
system-defined copy. | ||
""" | ||
fname = os.path.join(os.getcwd(), 'matplotlibrc') | ||
if os.path.exists(fname): | ||
return fname | ||
if 'MATPLOTLIBRC' in os.environ: | ||
path = os.environ['MATPLOTLIBRC'] | ||
@@ -695,15 +722,17 @@ def matplotlib_fname(): | ||
if os.path.exists(fname): | ||
return fname | ||
configdir = _get_configdir() | ||
if configdir is not None: | ||
fname = os.path.join(configdir, 'matplotlibrc') | ||
if os.path.exists(fname): | ||
return fname | ||
path = get_data_path() # guaranteed to exist or raise | ||
fname = os.path.join(path, 'matplotlibrc') | ||
if not os.path.exists(fname): | ||
warnings.warn('Could not find matplotlibrc; using defaults') | ||
return fname | ||
Uh oh!
There was an error while loading.Please reload this page.