Use a subdirectory of $XDG_CONFIG_HOME instead of ~/.matplotlibrc on Linux #454

Merged
merged 2 commits into from May 28, 2013

Projects

None yet

6 participants

@mdboom
Matplotlib Developers member

The latest version of the XDG basedir spec seems to recommend this.

http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

Is this something we want to do? Will it only add to confusion for platforms that don't use this (presumably Mac OS-X)?

@fperez
Matplotlib Developers member

FWIW, here's what we've done on this topic:

http://ipython.org/ipython-doc/dev/config/overview.html#configuration-file-location

It is indeed a little more information to provide, since osx is now different than linux, but people felt that following the xdg standard was a good idea.

@jkseppan
Matplotlib Developers member

On Mac OS X, this kind of files tend to go in ~/Library/Application Support. I think that directory is strictly meant for applications, not libraries, so e.g. a hypothetical application named Pylab.app might place its files in ~/Library/Application Support/org.scipy.Pylab.

Even more strictly, application configuration should go in ~/Library/Preferences and be managed with the appropriate OS X APIs.

http://developer.apple.com/library/mac/#documentation/FileManagement/Conceptual/FileSystemProgrammingGUide/MacOSXDirectories/MacOSXDirectories.html

A lot of common Unix programs do keep their configuration in dotfiles in the home directory, though.

@WeatherGod
Matplotlib Developers member

Could we have it so that if that environment variable is set, then use it. Otherwise, stick with the old location for now?

However, there might be some issues if a person already has an rc file in both locations, how do we know which one to use?

@pelson
Matplotlib Developers member

Sounds like a good idea. Shall we get on and implement it? Anyone keen to give it a shot?

@mdboom
Matplotlib Developers member

+1 on doing this. This has obviously just fallen through the cracks. I think we should plan this for the next major release (I've added a milestone).

@eheintzmann

According to XDG Base directory specification:
User data should go into $XDG_DATA_HOME (which default to ~/.local/share),
user preferences should go into $XDG_CONFIG_HOME (which default to ~/.config)
and cached data should go to $XDG_CACHE_HOME (which default to ~/.cache).
More details at :
http://ploum.net/post/207-modify-your-application-to-use-xdg-folders
https://live.gnome.org/GnomeGoals/XDGConfigFolders

Full specification can be found at:
http://standards.freedesktop.org/basedir-spec/latest/

The Freedesktop.org XDG base directory specification have good de facto adoption.
It has been adopted by:

I think that matplotlib should use same locations than the vast majority of Desktop environment and applications.

There are real advantages of following this specification :

  • a lot less cluttered $HOME
  • Make backups a lot more safer and easier. Backuping your $XDG_DATA_HOME along with your files is enough (or just excluding $XDG_CACHE_HOME)
  • A lot easier to reset a default configuration if you want/need it (and without any risk to loose informations). Even for the software itself could choose to reset $XDG_CONFIG_HOME if needed.
  • Avoid some strange bugs that happens because you had a old version of some configuration file
  • A lot more of flexibility and portability because no path are hardcoded.
@mdboom
Matplotlib Developers member

@eheintzmann, @fperez: Anyone willing to test this, to make sure the migration path works? I'd like to get this in for 1.3. If a ~/.matplotlib/matplotlibrc file already exists on Linux, it will continue to use that, but display a big fat warning. I think this is better than just going on to use the new location and having users scratch their heads as to why their config appears to be "missing". It's just a matter of moving it to the new location (.config/matplotlib) and it should be quiet, though.

@WeatherGod: I deliberately didn't change behavior on OS-X. We could consider ~/Library/Applications etc., but I think that should be a follow-on PR.

@pelson
Matplotlib Developers member

@mdboom - the warning was good. But I wonder if we can do this migration automatically? Especially given that the only files in my .matplotlib folder are automatically generated caches anyway.

@mdboom
Matplotlib Developers member

Most of the files in ~/.matplotlib are auto-generated caches, but the most important one, matplotlibrc is not.

With this PR, all of the cache files will automatically (and silently) start being created and used in ~/.cache/matplotlib. It is only when the human-written matplotlibrc file exists in the old location that this warning will be generated. I'm not a fan of automatically moving the config file. I, for example, have the config files I care about as symlinks into a git repository so they get version controlled and backed up. If this file were to get moved, it might escape that process, (moving a symlink is probably fine, but we can't assume everyone works the way I do) and I would only get the warning that it was moved the first time (which might be easy to miss).

@pelson
Matplotlib Developers member

It is only when the human-written matplotlibrc file exists in the old location that this warning will be generated.

That was not my experience (I didn't look at the code, just ran it...). I'm happy with the approach you discuss though.

@pelson pelson and 1 other commented on an outdated diff May 24, 2013
lib/matplotlib/__init__.py
+ p = os.path.join(h, '.matplotlib')
if os.path.exists(p):
@pelson
pelson May 24, 2013

This is the bit which causes the warning for people with a cache but not necessarily a matplotlibrc.

@mdboom
mdboom May 24, 2013

Ah, I see. I'll fix that up.

@mdboom mdboom merged commit f870c35 into matplotlib:master May 28, 2013

1 check passed

Details default The Travis CI build passed
@herr-biber herr-biber added a commit to herr-biber/matplotlib that referenced this pull request Mar 20, 2014
@herr-biber herr-biber Fix paths in doc which are searched for matplotlibrc (XDG).
See pull request #454 (3ac8144)
82837cb
@mdboom mdboom deleted the mdboom:xdg_config branch Aug 7, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment