gforcada/flake8-isort

Inconsistent behaviour to isort

Closed this issue ยท 8 comments

Hi,

for some strange reason I get inconsistent results by running flake8 with flake8-isort installed and running isort directly. The issue arises with these imports:#

from _pydecimal import Decimal, DecimalException

from django import forms
from django.core.exceptions import ValidationError

isort is fine with that. But flake8 gives me:

./fields.py:1:1: I001 isort found an import in the wrong position
./fields.py:2:1: I004 isort found an unexpected blank line in imports
./fields.py:5:1: I003 isort expected 1 blank line in imports, found 0

This is my setup.cfg

[isort]
line_length=120
default_section = THIRDPARTY
known_django = django
sections = STDLIB,DJANGO,THIRDPARTY,FIRSTPARTY,LOCALFOLDER

@larsrinn hi! Sorry for the long delay, I was on vacations ๐ŸŒด

I will try to reproduce it locally and see if I can cook a patch for it. We parse isort output, so knowing flake8, isort and flake8-isort versions would be helpful. Thanks in advance.

Again, thanks for reporting and sorry for the delay! ๐Ÿ™‡โ€โ™‚๏ธ

@larsrinn if I run flake8 with flake8-isort master branch I do get a few isort related errors:

bla.py:1:1: I001 isort found an import in the wrong position
bla.py:2:1: I004 isort found an unexpected blank line in imports
bla.py:6:1: I003 isort expected 1 blank line in imports, found 0

But if run isort (version 4.3.4), it fixes the code to look like this:

from _pydecimal import Decimal, DecimalException
from django import forms
from django.core.exceptions import ValidationError

flake8 version is:

3.5.0 (flake8_isort: 2.3, mccabe: 0.6.1, pycodestyle: 2.3.1, pyflakes: 1.6.0) CPython 2.7.14 on Linux

Take a look at #59. I think this is the same issue.

Please verify by doing pip install --upgrade flake8 and try again.

I believe it's potentially related to isort determining imports are THIRDPARTY, but flake8-isort not being able to.

In my case, I have a flake8 command that runs on saving a file in my text editor: however, this is different to the tox -e isort command that runs on CI, because the latter has all of the packages installed, whereas the flake8 command is in it's own virtualenv (which it needs to be, because sometimes I'm editing a file that is not in a virtualenv, so I can't just have isort/flake8 in each virtualenv).

isort comes with the ability to "point" toward a specific virtualenv (isort --virtual-env), but I'm not sure if it's possible to pass that through from flake8 to flake8-isort.

I'm currently running into this issue: flake8 works just fine on local, but in CI I get I004 isort found an unexpected blank line in imports error for a single line.

CI:

.gradle/python/bin/flake8 --version

3.8.3 (dlint: 0.10.3, flake-mutable: 1.2.0, flake8-bugbear: 20.1.4,
flake8-comprehensions: 3.2.3, flake8-django: 0.0.4, flake8-pytest-style:
1.2.3, flake8_isort: 4.0.0, mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes:
2.2.0) CPython 3.7.7 on Linux

local:

3.8.3 (dlint: 0.10.3, flake-mutable: 1.2.0, flake8-bugbear: 20.1.4,
flake8-comprehensions: 3.2.3, flake8-django: 0.0.4, flake8-pytest-style:
1.2.3, flake8_isort: 4.0.0, mccabe: 0.6.1, pycodestyle: 2.6.0, pyflakes:
2.2.0) CPython 3.7.7 on Darwin

flake8 works just fine on local, but in CI I get I004 isort found an unexpected blank line in imports error for a single line.

hello, I meet this issue too, do you solve it now?

@cihati @suluner Did you ever find a solution to that ? I'm running in the same problem. Works fine locally, failed in CI.

In my case, it was due to isort behaving differently in the CI because of Git submodules. Locally, isort was fine with submodules being considered as "local modules" where in a Gitlab CI job, it was considered as a "third party package".

I fixed this by adding my submodules' names/paths to the known_third_party isort setting.