sqlalchemyorg / zimports

Python import rewriter
MIT License
75 stars 6 forks source link

Respect max-line-length option of flake8 #9

Closed lvt-mm closed 2 years ago

lvt-mm commented 4 years ago

When using --multi-imports, the import line will grow to arbitrary lengths, even though this will fail the line length lint check.

This change adds a --max-line-length option to set the maximum line length to use, using the value from the setup.cfg file as default. This option is then used to break from-imports lines into multiple lines if they are longer than the specified length.

For example, this line

from zimports import ClassifiedImport, ImportVisitor, sort_imports, main

will, when run with --max-line-length=72 be transformed to

from zimports import (
    ClassifiedImport, ImportVisitor, sort_imports, main)

The heavy lifting is done using the built-in textwrap module.

The tests did not pass when using the asname= keyword argument to ast_cls, I'm assuming this is due to running on python 3.6.

I've also taken the liberty to use the built-in version of the mock module, which has been there since python 3.3.

zzzeek commented 2 years ago

this PR has gone stale, closing