Skip to content

Different paths for get_configdir and matplotlib_fname() #3062

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
amelio-vazquez-reina opened this issue May 14, 2014 · 11 comments
Closed

Different paths for get_configdir and matplotlib_fname() #3062

amelio-vazquez-reina opened this issue May 14, 2014 · 11 comments
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Documentation
Milestone

Comments

@amelio-vazquez-reina
Copy link

I work in a Linux system that uses a rather unconventional HOME directory. However, the HOME environment is always set up properly.

> echo $HOME
> /opt/my_home_directory/

I have set up the init files for matplotlib properly under:
$HOME/matplotlib/matplotlibrc
and also, just in case under:
$HOME/.matplotlib/matplotlibrc

However, when I ask matplotlib, it looks confused:

> matplotlib.get_configdir()
'/opt/my_home_directory/.matplotlib`
>matplotlib.matplotlib_fname()
'/some/long/path/anaconda/envs/py27/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc

The second one is wrong. I want to use matplotlibrc under my $HOME directory. Why does matplotlib return two different paths, and how can I make it use the one I want?

@tacaswell
Copy link
Member

what does echo $XDG_CONFIG_HOME give and what version of mpl are you using? The code is in matplotlib/__init__.py if you want to take a look at it.

@amelio-vazquez-reina
Copy link
Author

Thanks @tacaswell echo $XDG_CONFIG_HOME returns nothing (i.e. empty).

@tacaswell
Copy link
Member

What version of mpl are you using? Could you try using the master branch if you are not already?

@pelson
Copy link
Member

pelson commented May 21, 2014

The code for matplotlib_fname is found in https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/__init__.py#L715. In pseudo code:

def matplotlib_fname():
     * look for matplotlibrc in PWD
     * look for matplotlibrc in the directory pointed to in the MATPLOTLIBRC environment variable 
     * look for matplotlibrc in get_configdir
     * look for matplotlibrc in get_data_path **OR** raise an exception

So it looks like the 3rd item isn't being triggered. Do you have a MATPLOTLIBRC environment variable defined?

@amelio-vazquez-reina
Copy link
Author

I didn't have it set, so I just did:

export MATPLOTLIBRC=/opt/my_home_directory/.matplotlib/.matplotlibrc

(I also tried making that variable point to .matplotlib instead)

but it didn't fix the problem:

In [1]: import os, matplotlib

In [2]: os.getenv("MATPLOTLIBRC")
Out[2]: '/opt/my_home_directory/.matplotlib/.matplotlibrc'

In [2]: matplotlib.get_configdir()
Out[3]: '/opt/my_home_directory/.matplotlib'

In [4]: matplotlib.matplotlib_fname()
Out[4]: '/some/long/path/anaconda/envs/py27/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc'

The file .matplotlibrc exists:

$ cat $MATPLOTLIBRC
backend: Agg
font.family        : serif
font.serif         : Times, Palatino, New Century Schoolbook, Bookman, Computer Modern Roman
font.sans-serif    : Helvetica, Avant Garde, Computer Modern Sans serif
font.cursive       : Zapf Chancery
font.monospace     : Courier, Computer Modern Typewriter
text.usetex        : true%    

@amelio-vazquez-reina
Copy link
Author

It looks like matplotlib fails to find the file if MATPLOTLIBRC points to a .matplotlibrc instead of a matplotlibrc file (note the preceding dot). If I change MATPLOTLIBRC to piont to a matplotlibrc, it seems to work, although I get a warning saying that I have defined in a deprecated location (instead of ~/.config/matplotlib/matplotlibrc). Is this intentional? (e.g. if I want to use a different location why should I get a warning?).

Also, it seems that matplotlib uses a different location from IPython for its config files (IPython moved everything back to ~/.ipython). Why the disagreement?

@tacaswell
Copy link
Member

@ribonoous I don't think you have told us what version of mpl you are using (what does matplotlib.__version__ give?).

@amelio-vazquez-reina
Copy link
Author

Thanks I am using 1.3.1 of matplotlib. I will try master to see if that changes anything.

@tacaswell
Copy link
Member

@ribonoous Any progress?

@tacaswell tacaswell added this to the unassigned milestone Jul 12, 2014
@pelson
Copy link
Member

pelson commented Aug 26, 2014

Also, it seems that matplotlib uses a different location from IPython for its config files (IPython moved everything back to ~/.ipython). Why the disagreement?

Hmmm, I hadn't seen that. (ipython/ipython#4457). It is fair enough if a project wants to aim for consistency accross platforms, but I would be a strong proponent of using OS specific recommendations wherever possible in general (and ergo for mpl).

It looks like matplotlib fails to find the file if MATPLOTLIBRC points to a .matplotlibrc instead of a matplotlibrc file (note the preceding dot).

The pseudo code I posted would confirm that - the MATPLOTLIBRC environmental variable (apparently undocumented in my search for it) is used to define the directory containing a matplotlibrc file.

If I change MATPLOTLIBRC to piont to a matplotlibrc, it seems to work, although I get a warning saying that I have defined in a deprecated location (instead of ~/.config/matplotlib/matplotlibrc). Is this intentional? (e.g. if I want to use a different location why should I get a warning?).

This does seem a little odd. I wonder if there is a little bit of logic missing in the identification of whether a warning needs to be issued.

So, in summary, I think the actions for this issue are:

  • To improve the documentation about this (given my pseudo code above)
  • To investigate whether the warning needs to be issued in all cases of non .config/matplotlib config dirs.

@tacaswell tacaswell modified the milestones: unassigned, v1.4.x Aug 26, 2014
@tacaswell tacaswell modified the milestones: v1.4.x, v1.4.1 Sep 3, 2014
@tacaswell tacaswell modified the milestones: 1.5.0, v1.4.x Feb 7, 2015
@tacaswell tacaswell added this to the proposed next point release milestone Jul 17, 2015
@tacaswell tacaswell removed this from the next point release milestone Jul 17, 2015
@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Oct 3, 2017
@dstansby dstansby added Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues and removed low hanging fruit labels Jun 1, 2019
@anntzer anntzer modified the milestones: needs sorting, v2.1 Jun 1, 2019
@anntzer
Copy link
Contributor

anntzer commented Jun 1, 2019

I think this has almost certainly been fixed by #5268. Feel free to request a reopen if not.

@anntzer anntzer closed this as completed Jun 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues Documentation
Projects
None yet
Development

No branches or pull requests

5 participants