Skip to content
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

[ENH]: move .matplotlib folder from %USERPROFILE% on Windows #20779

Open
Erithax opened this issue Aug 1, 2021 · 12 comments
Open

[ENH]: move .matplotlib folder from %USERPROFILE% on Windows #20779

Erithax opened this issue Aug 1, 2021 · 12 comments
Labels
Good first issue Open a pull request against these issues if there are no active ones! OS: Microsoft

Comments

@Erithax
Copy link

Erithax commented Aug 1, 2021

Problem

The folder contains "fontlist-v330.json" in my case.

Proposed solution

Move the directory to a subdirectory in %APPDATA%, where it belongs (as the name suggests).

Additional context and prior art

No response

@tacaswell
Copy link
Member

Do you have a reference for what "should" be in various places?

I suspect that this would be addressed by #12549 , but if we do not want to pick up that dependency, the place in the code to make the change is

else:
configdir = Path.home() / ".matplotlib"
try:
configdir.mkdir(parents=True, exist_ok=True)
except OSError:
pass
else:
if os.access(str(configdir), os.W_OK) and configdir.is_dir():
return str(configdir)

Even though this is an internal cache, we should document that we are moving it on windows (as I'm sure there exist other users who have discovered where it lives and are either deleting it (for reasons) or pre-populating it (again, for reasons).

@tacaswell tacaswell added this to the v3.6.0 milestone Aug 2, 2021
@tacaswell tacaswell added OS: Microsoft Good first issue Open a pull request against these issues if there are no active ones! and removed New feature labels Aug 2, 2021
@tacaswell
Copy link
Member

Milestoned for 3.6, but if it is ready it can go in for 3.5. Labeled good first issue because it only requires changing details of how we discover the cache directory and should not touch our public API (other than a sideeffect of where files go), but may require intermediate Python (as I think we want to generalize _get_xgd_cache_dir to also have a windows path) and familiarity with Windows.

@Erithax
Copy link
Author

Erithax commented Aug 2, 2021

Do you have a reference for what "should" be in various places?

https://docs.microsoft.com/en-us/windows/apps/design/app-settings/store-and-retrieve-app-data

@NeilGirdhar
Copy link

(as I think we want to generalize _get_xgd_cache_dir to also have a windows path) and familiarity with Windows.

Why not just use appdirs as suggested in #12549?

@StefRe
Copy link
Contributor

StefRe commented Nov 25, 2021

Move the directory to a subdirectory in %APPDATA%, where it belongs (as the name suggests).

I think it should go into %LOCALAPPDATA%, not %APPDATA% which is for roaming app data. Cached fonts data are certainly not applicable on other devices. See also https://docs.microsoft.com/en-us/windows/win32/shell/knownfolderid.

@StefRe
Copy link
Contributor

StefRe commented Nov 25, 2021

On Windows, the get_configdir and get_cachedir currently return the same value:

elif sys.platform.startswith(('linux', 'freebsd')):
# Only call _xdg_base_getter here so that MPLCONFIGDIR is tried first,
# as _xdg_base_getter can throw.
configdir = Path(xdg_base_getter(), "matplotlib")
else:
configdir = Path.home() / ".matplotlib"

On Windows, I think we need to differentiate between %APPDATA% for roaming config data (get_configdir) and %LOCALAPPDATA% for local cache data (get_cachedir).

@NeilGirdhar
Copy link

@StefRe I think it should go into %LOCALAPPDATA%, not %APPDATA% which is for roaming app data.

appdirs already figures this out for you if you pass roaming=True: https://github.com/ActiveState/appdirs/blob/8eacfa312d77aba28d483fbfb6f6fc54099622be/appdirs.py#L165

@StefRe
Copy link
Contributor

StefRe commented Nov 26, 2021

@NeilGirdhar Thanks for mentioning, but all I wanted to say was just what files should go to what folders, not how to obtain these folder locations.

@StefRe
Copy link
Contributor

StefRe commented Nov 26, 2021

@tacaswell If we want to fix this particular issue #20779 for Windows, I can make a PR.
(Switching to appdirs #12549 is beyond me as I have no masOS or FreeBSD to test it and update the documention of get_configdir and get_cachedir. I couldn't find docs for appdirs (apart from the README file) that we could refer to for the details about folder selection on different OSs.)

@NeilGirdhar
Copy link

NeilGirdhar commented Nov 26, 2021

@StefRe Yes, I understand, but if you're going to fix this, I really think using appdirs is the right approach. They have already tested to make sure that their folder choices are correct. Otherwise, you'll just be fixing it for one OS for now, and it could easily break again one day. More importantly, the folders are messed up on all operating systems for the rest of us.

I also don't think it's that much harder to use appdirs than to do this manually. Just call appdirs.user_data_dir(appname='matplotlib', appauthor='matplotlib', version=..., roaming=False) and use that path.

@StefRe
Copy link
Contributor

StefRe commented Nov 26, 2021

@NeilGirdhar I didn't say that it's hard to use appdirs (quite the contrary), I just see the documentation issue as I don't trust myself to properly document folder locations for the different operating systems in the matplotlib documentation when using appdirs. Right now it's easy: we only have three cases to document: Linux, Windows and all other. I don't know on what different Unix or macOS systems matplotlib can be run and what appdirs will return in each single case (ok, I could check the source and document it myself, but it would be much easier if they had some authorative documentation one could refer to). So it's not that I wouldn't like appdirs, I'm just feeling a bit uncomfortable relying on a third party programm without proper documentation (at least I couldn't find it).

Just call appdirs.user_data_dir(appname='matplotlib', appauthor='matplotlib', version=..., roaming=False) ...

I'd use ...\matplotlib instead of ...\matplotlib\matplotlib as do for instance Python, Spyder, Gimp and other programs that don't have a company as an author (i.e. set appauthor='' in the call to user_data_dir)

@NeilGirdhar
Copy link

I'd use ...\matplotlib instead of ...\matplotlib\matplotlib as do for instance Python, Spyder, Gimp and other programs that don't have a company as an author (i.e. set appauthor='' in the call to user_data_dir)

You're right! Good point.

I'm just feeling a bit uncomfortable relying on a third party programm without proper documentation (at least I couldn't find it).

I understand. That's fair. But the issue with just hacking a custom solution is that it remains messed up for the rest of us :/ I didn't think about the documentation issue.

@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Aug 24, 2022
@QuLogic QuLogic modified the milestones: v3.7.0, future releases Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Good first issue Open a pull request against these issues if there are no active ones! OS: Microsoft
Projects
None yet
Development

No branches or pull requests

5 participants