Skip to content

mplstyle files: seach in ~/.local/share/matplotlib/ #17278

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
nschloe opened this issue Apr 30, 2020 · 4 comments
Closed

mplstyle files: seach in ~/.local/share/matplotlib/ #17278

nschloe opened this issue Apr 30, 2020 · 4 comments
Labels
Community support Users in need of help.

Comments

@nschloe
Copy link
Contributor

nschloe commented Apr 30, 2020

I would like to write a Python package that also installs an mpl style file. To do that, I can use the data_files attribute of setuptools. This allows me to install files anywhere in the installation directory, which, for pip on Linux, defaults to ~/.local. Unfortunately, mpl will search for mplstyle files only in ~/.config. This means that, for my package, I have to pull a weird stunt:

  1. Install the file in ~/.local with the rest of the package
  2. Upon "start-up" of the package (import or some function call), check if the file is already in mpl.get_configdir(), has the same content (for updates), and if not, copy it there. Possibly create the directory.

This feels a bit off.

I'd hence suggest that mpl also searches for mplstyle file in, e.g., ~/.local/share/matplotlib/. This would also better fit its nature, given that the file is not meant to be edited by the user.

@anntzer
Copy link
Contributor

anntzer commented Apr 30, 2020

As argued elsewhere, I think it would be much simpler from a distribution POV to distribute style files as plain python packages (see e.g. #14943.). Even if you do want to keep the mplstyle syntax, just distribute them in a subpackage of your normal python package and make the usage import mystyle; mpl.style.use(mystyle.get_rc()) or something similar.

@nschloe
Copy link
Contributor Author

nschloe commented Apr 30, 2020

I could also hide this like

import foobar
foobar.set_mpl_style()  # executes mpl.style.use(foobar.get_rc())

but this is less explicit and more verbose than

mpl.style.use("foobar")

I'd like to make it easy for my users.

@anntzer
Copy link
Contributor

anntzer commented Apr 30, 2020

It's just one import, and then mpl.style.use(foobar.style), which is really not that bad. And as argued elsewhere, if your user has access to foobar.style (a dict), they have much more freedom to poke into it (it's a plain dict, they know how to handle that), whereas if they have access to "foobar" (a string), they can't do anything with it (other than passing it to mpl.style.use).

@nschloe
Copy link
Contributor Author

nschloe commented Apr 30, 2020

I think you're right. I hadn't thought about the possibility of passing a dict to the style.use(). Thanks!

@nschloe nschloe closed this as completed Apr 30, 2020
@QuLogic QuLogic added the Community support Users in need of help. label Jun 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Community support Users in need of help.
Projects
None yet
Development

No branches or pull requests

3 participants