black icon indicating copy to clipboard operation
black copied to clipboard

Request: supporting sub-configs (aka per-directory config)

Open jamesbraza opened this issue 2 years ago • 4 comments

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

I like black's default of 88-char line length, except for docs/ renderings, where code blocks may be rendered via Sphinx with 79 char width. This leads to unnecessary scrolling left/right to see the last 9 chars.

It would be useful to enable black to have sub-configurations. This was requested in https://github.com/psf/black/issues/1370, and was postponed into the future.

Describe the solution you'd like

Enabling subdirectories to have their own pyproject.toml, and black will accept overrides from that sub-pyproject.toml.

Describe alternatives you've considered

ruff is a project that adopted sub-configs through use of the extend keyword. It has been great, I have:

  • One repo-wide config
  • Two sub-configs: docs/ and tests/

This can be an example successful implementation of sub-configs.

Additional context

One counter argument is simplying invoking black once/config:

  • Once for the repo root
  • Once for the subdirectory with its special config

I think this complicates things (e.g. multiple make commands or multiple pre-commit hooks), though it is a valid workaround

jamesbraza avatar Oct 17 '23 16:10 jamesbraza

+1 to this request -- I am running into the same issue with sphinx docs and want a different line length for that code.

skrawcz avatar Jan 31 '24 20:01 skrawcz

+1 for this. We have also usecases where we have different types of modules and scripts and for some of them it makes sense to have a different config. For example, formatting for a utility library, compared to a pyspark code can be different and one might need to customize the formatting for different modules in the code

maanijou avatar Mar 04 '24 10:03 maanijou

+1. I just ran into the exact same use-case that for examples which are included in Sphinx documentation, a shorter line-length would be good.

luator avatar Apr 30 '24 08:04 luator