aleph icon indicating copy to clipboard operation
aleph copied to clipboard

BUG: black and flake8 have conflicting options

Open brassy-endomorph opened this issue 2 years ago • 1 comments

Describe the bug

The tools black and flake8 have conflicting options so that make format lint fails. These options should be configured in setup.cfg.

To Reproduce

  • Have a line longer than 100 chars

Or have lines like this:

foo = (
    "some string" +
    "more string"
)

or a line like this

some_var = \
    "very line foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz foo bar baz"
  • Run make format lint
  • flake8 fails because black
  • All of these will cause black to reformat in a way that is incompatible with flake8

brassy-endomorph avatar Sep 28 '22 07:09 brassy-endomorph

Long lines seem to be a tricky thing to handle with black. By default it won't redo lines that are over the max length. It is possible with the --preview setting to have long lines of text reformatted, but it also applies some other changes that I'm not so sure about.

Regardless of this it won't wrap text without spaces (urls etc). Our approach here has been to manually add a # noqa to such lines in order to prevent flake8 from failing on them. I'd be interested in any other workaround (sort of completely disabling this rule).

Some additional reading:

  • https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
  • https://github.com/PyCQA/flake8-bugbear

I've also created a branch to play around with possible solutions here:

  • https://github.com/alephdata/aleph/tree/rosencrantz/2359-flake-black-conflict

Rosencrantz avatar Sep 29 '22 14:09 Rosencrantz

Fixed in #2561

tillprochaska avatar Oct 18 '22 19:10 tillprochaska