Black: Make cache location configurable

Created on 18 Oct 2018  路  2Comments  路  Source: psf/black

hello,

It would be nice to make cache loccation configurable by cli argument.

Here's my use case: We use bitbucket pipelines, and in their workflow I can only cache/restore directories relative to the project's path.

So, if you could please make the cache location configurable, i could add black --check --cache-dir=./black_cache on bitbucket pipeline, cache that directory, and make black execution really really fast 馃樃

Thanks, awesome project!!

command line documentation help wanted

All 2 comments

Black uses appdirs for locating the folder where it should write the cache to. On Linux/Unix systems it's ~/.cache/black.

Looking at the source code for appdirs, we can see that we can change the path it gives Black by setting an environment variable:
https://github.com/ActiveState/appdirs/blob/0a7725ce30fbe6b7a6992458b0ba55f998195a6f/appdirs.py#L314

So if you set XDG_CACHE_HOME=.cache as an environment variable before you run Black, it will instead write the cache to the .cache/black folder.

We should document XDG_CACHE_HOME.

Was this page helpful?
0 / 5 - 0 ratings