-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
configure .cache via $XDG_CACHE_DIR #1089
Comments
is there a good package that helps finding those paths and helps clearing unused caches after all if the cache folder is outside of the working directory, imagine for example a unaware ci system that makes one folder per build could easily DOS the ci server due to filling up ~/.cache of the ci user with the current mode of operation, cache and working directory are simply co-located and share a lifetime, so data management is easy, the cache is gone when one deletes the working directory im not per se opposed to following XDG, but it makes lifetimes of file-system objects more tricky on our case and seems not really available on windows either |
Those are good points... I don't have a good answer. The applications I've seen don't worry about cleaning up like that. |
This one at least helps find a good platform-specific cache dir: https://pypi.python.org/pypi/appdirs/1.4.0 |
This one helps manage expiry for a file-based cache. |
i shorty investigated appdirs and pyfscache, unfortunately both are unsuitable appdirs seems bug-ridden |
how about introducing a ini value/env variable to select the cache backend, @hpk42 oppinions? |
Personally I'd rather default to xdg instead of needing to add .cache to the gitignore in every one of my projects |
while i agree that it is a nice default, we cant do a change like that befor 3.0 also before we can do it propperly we need to come up with a solid way to clean things up |
Maybe introducing the cache plugin defaulted to on should have been in 3.0 too :/ |
since its a normal feature addition, it doesnt warrant a release that large |
i hate ".cache" folder for aesthetic reason. my projects folders are already populated by ide, git, python and others "support folders". sometimes i have more folders than actually python program files! please make ".cache" location configurable! |
Anyone is against this? While it may not be the best option, it is simple to implement and backward compatible. It should support variable expansion and default to [pytest]
cache_dir=$XDG_CACHE_DIR Or use an environment variable:
|
I'm against the most easy variant, I want a simple solution |
@RonnyPfannschmidt I've found that the function you'd need exists in pip.utils: https://github.com/pypa/pip/blob/develop/pip/utils/appdirs.py#L13 |
How about we add a configuration option that decides between the two systems? If we make a poll and people wants to change BTW, I'm just throwing some ideas so we can reach some consensus, I don't mind having the |
👍 |
For the implementation of On Wed, Dec 23, 2015 at 10:29 PM Ronny Pfannschmidt <
|
Actually, the pip function seems to be closely related to the appdirs package implementation. https://github.com/ActiveState/appdirs/blob/master/appdirs.py#L257 |
IMHO I would just copy the function over, licensing permitting... depend on the entire |
I'd go for publishing a minimalistic lib that implements it |
Hi, |
@antoche for now yes |
There's a Should we change the default of that option to |
the config dir is under all circumstances always the wrong folder for the cache we should use the cache home as according to the spec, and we should take a look at using the appdirs lib to facilitate those details |
@nicoddemus: No, the default should be $XDG_CACHE_DIR, which in turn has a default of $HOME/.cache.
If you want to support macos and windows in a natural way, you'll want a library for this. I think this is the right solution: https://github.com/ActiveState/appdirs#the-problem |
@bukzor thanks for the clarification and correcting my mistake |
What should it default then to? |
A hash oft the path element iis required ffor sanity |
Ok. Not really a fan of this myself though - I'd rather keep it with the repository, similar to Using a hash would not allow to prune only certain/known dirs for example. |
@blueyed we can make accompanying json files to make accompanying metadata and a prune command the in fact we ought to consider adding it even to the .pytest_cache folder like the readme/gitignore |
This is now possible because [pytest]
cache_dir=$XDG_CONFIG_DIR So I believe this can be closed. |
In xdg those have implied defaults, and the example you gave would nuke the entire config dir of the user if it was explicitly set while running cache clean |
Oh you mean it should have been But other than that, what else would a user need to use the |
Again incorrect, there are implicit defaults in the standard, and the config is NEVER to be used for caches Additionally there would be confusion about ownership if entirely different projects used the same setup |
I'm confused... is this issue invalid then?
Oh definitely I was naive on my quick late night reply. |
The initial comments had the correct var name, the title was wrong, i fixed that |
Can we please fix this? It should no be very hard to do the right thing as most of other python tools do that already: cpython, mypy, pip, pylint, pre-commit are just some examples of tools going to TBH, I am surprised that after so many years pytest still refuses to use the official cache directories and pollutes our directory trees with os.getenv("XDG_CACHE_HOME", os.path.expanduser("~/.cache") AFAIK it is usually a one-liner like https://github.com/ansible-community/ansible-lint/blob/08fae7af24de64c1ed4d583765728c21b38643f4/src/ansiblelint/__main__.py#L112 The example above is using a hash key to isolate the cache directories between projects, based on their folder. It is simple but effective. |
Ahh right, good idea. |
I don’t think that CPython uses XDG directories for anything, do you have other info @ssbarnea ? |
@ssbarnea feel free to invest the time to create a proper storage /eviction scheme, which even the named tools only partially implement |
It almost does, |
@ssbarnea this is about pytest cache, which is different from byte code cache You need at least one cache per test invocation root, but potentially more than one for virtualenvs/python versions And you need to be able to cleanup potentially independently of the existing folders |
I see two possible approaches here:
|
pytest is the only tool in my python stack which still pollutes my source directories. |
Forked from #1029
a) A very convenient, and standard, way to configure tools' cache location is to set $XDG_CACHE_DIR. Many of my project's fixtures do this for other reasons already. Similarly, the most convenient, and standard, way to set "basetmp" would be $TMPDIR.
b) "something a CI system can easily pick up" is exactly these environment variables. Many systems will already support this, and those that don't will support injecting environment variables.
c) "non-containered ci" will either support ~/.cache correctly, or set $XDG_CACHE_DIR, because this is necessary for other tools that use the standard. Again, this is already handled in many of my projects because of other tools.
The text was updated successfully, but these errors were encountered: