Skip to content

Allow cache dir configuration via command-line argument #5174

Description

@MatheusCylo

Is your feature request related to a problem? Please describe.

I work with a monorepo, and all my Python-related tools have their cache directories under python/out/{tool_name}/cache. I've configured my usages of black with the BLACK_CACHE_DIR environment variable appropriately (IDE run configurations, for instance).

Recently, I've added black as a pre-commit hook. Unfortunately, this has made it start writing its cache directory on the project root. I've browsed the issues of pre-commit, and the author seems pretty adamant about not introducing an env configuration option at the hook level (for some valid reasons, might I add).

Describe the solution you'd like

I would like Black to accept the path it should use for its cache directory as a command-line argument. It should probably take precedence over the environment variable, in accordance with how the BLACK_NUM_WORKERS/--workers pair currently operates. Additionally, this might make the --no-cache-dir option “redundant”, if the new option is configured to interpret an empty path string as “do not attempt to read/write to the cache”.

Describe alternatives you've considered

I've conceded to using --no-cache-dir as an extra argument when running black as a pre-commit hook. Alternative solutions, such as using a custom binary or maybe altering the git hook that pre-commit runs with, seem either too error-prone or difficult to propagate throughout a team strictly via VCS (but I'm open to suggestions!).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions