https://pypi.org/project/flake8-isort/
This is the code:
"""Run the :exec subcommand."""
import os
import shlex
from typing import List
from typing import Optional
from typing import Tuple
from typing import Union
from . import _actions as actions
from ..app import App
from ..configuration_subsystem import ApplicationConfiguration
from ..configuration_subsystem.definitions import Constants
from ..runner import Command
The blank line in the froms
catches this error.
I like the blank line here as a delimiter between py and internal
isort has been implemented via a pre-commit hook 🙂
View full answer
another example of the same
import difflib
import json
import os
from pathlib import Path
from typing import Generator
from typing import Union
import pytest
from ..._common import fixture_path_from_request
from ..._common import update_fixtures
from ..._tmux_session import TmuxSession
from ..._interactions import SearchFor
from ..._interactions import Step
from ....defaults import FIXTURES_DIR
The error is thrown for the blank line between os and pathlib, the blank line separates the 2
2 replies
@cidrblock I don’t think you should attempt running isort, it’s disabled for two reasons — it’s not agreed and it’s not configured. I think some of these things need to be configured so that different tools would rely on the same config. Plus that specific plugin is known to behave weirdly and I often disable it: https://github.com/ansible/pylibssh/blob/0bd71bb/.flake8#L38. Maybe it’s gotten better since the last time I checked it out but I haven’t had a chance to reevaluate it yet. The bottom line is that it needs to be checked together with the tool config, like https://github.com/ansible/pylibssh/blob/0bd71bb/.isort.cfg and I don’t think we’re ready for that yet.
We’ll probably need to configure how it sees different sections/categories of imports and what the expected separator is before even starting to think about this.
isort has been implemented via a pre-commit hook 🙂
0 replies
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
Use isort to check if the imports on your python files are sorted the way you expect.
Add an .isort.cfg to define how you want your imports sorted and run flake8 as you usually do.
See isort documentation for .isort.cfg available options.
Install
Install with pip:
$ pip install flake8-isort
Install with conda:
$ conda install -c conda-forge flake8-isort
Configuration
If using the select option from flake8 be sure to enable the I category as well, see below for the specific error codes reported by flake8-isort.
See flake8 –help for available flake8-isort options.
Error codes
Error code |
Description |
---|---|
I001 |
isort found an import in the wrong position |
I002 |
no configuration found (.isort.cfg or [isort] in configs) |
I003 |
isort expected 1 blank line in imports, found 0 |
I004 |
isort found an unexpected blank line in imports |
I005 |
isort found an unexpected missing import |
Requirements
-
Python 3.7, 3.8, 3.9, 3.10, 3.11 and pypy3
-
flake8
-
isort
Relation to flake8-import-order
As an alternative to this flake8 plugin, there’s flake8-import-order that could be worth checking out. In contrast to this plugin that defers all logic to isort, the flake8-import-order comes bundled with it’s own logic.
flake8-import-order comes with a few predefined set of styles meanwhile this plugin can be customized a bit more. But the biggest difference could lie in that flake8-isort actually has the corresponding sorting engine isort that can sort the import orders of your existing python files. Meanwhile flake8-import-order has no such corresponding tool, hence big existing projects who want to adopt either would get a more automized experience choosing flake8-isort.
License
GPL 2.0
Changelog
6.0.0 (2022-12-22)
-
Drop isort 4.x support.
[gforcada] -
Add support for flake8 6.0.0.
[gforcada] -
Add –isort-no-skip-gitignore option to allow temporarily overriding the set
value of isort’s skip_gitignore option with False. This can cause
flake8-isort to run significantly faster at the cost of making flake8-isort’s
behavior differ slightly from the behavior of isort –check. [gschaffner]
5.0.3 (2022-11-20)
-
Fix broken add_options method, again. [casperdcl]
5.0.2 (2022-11-19)
-
Fix broken add_options method [casperdcl]
5.0.1 (2022-11-18)
-
Improve the config option is added and read back. [gforcada]
-
Bump plugin version. [gforcada]
5.0.0 (2022-10-08)
-
Update dependencies. [gforcada]
-
Revamp GitHub actions. [gforcada]
-
Drop python 3.6, and add python 3.10. [gforcada]
-
Use linters and formatters to keep code sane and beautiful. [gforcada]
4.2.0 (2022-08-04)
-
Fix compatibility with flake8 version 5. [nhymxu]
4.1.2.post0 (2022-07-25)
-
Release it as a wheel as well. [gforcada]
4.1.2 (2022-07-25)
-
The package no longer depends on testfixtures.
4.1.1 (2021-10-14)
-
Release py3 only wheels..
4.1.0 (2021-10-14)
-
Support flake8 4.x [g-as]
-
Switch from travis-ci to github actions. [g-as]
-
Drop python 2.7 support and 3.5 as well [g-as]
4.0.0 (2020-08-11)
-
Nothing changed yet.
4.0.0a0 (2020-08-07)
-
support isort >= 5 [bnavigator, pkolbus]
3.0.1 (2020-07-08)
-
Work around FailedToLoadPlugin exception by requiring isort 4.x. Likewise,
pin the major version of all dependencies, to reduce risk of any future
incompatibilities.
[pkolbus]
3.0.0 (2020-04-15)
-
Let isort search the configuration, rather than flake8-isort try to find it.
[jnns]
2.9.1 (2020-03-28)
-
Fix flake8 warning.
[sobolevn]
2.9.0 (2020-03-16)
-
Add python3.8 support.
[sobolevn]
2.8.0 (2019-12-05)
-
Look for isort configuration on .flake8 files as well.
[JohnHBrock] -
Document how to install flake8-isort on conda.
[marcelotrevisani] -
Look for isort configuration on pyproject.toml files as well.
[sanjioh]
2.7.0 (2019-03-19)
-
Improve the README.
[barbossa] -
Fix isort output when pipes are used.
[maerteijn]
2.6.0 (2018-12-01)
-
Use pytest to run tests.
[gforcada] -
New error code I005 isort foundan unexpected missing import.
[charettes] -
Add isort_show_traceback option to show verbose multi-line output
from isort, turned off by default
[sobolevn]
2.5 (2018-03-15)
-
Now requires isort >= 4.3.0.
[jleclanche]
2.4 (2018-02-25)
-
Fix input handling with flake8’s –stdin-display-name, and simplify it.
[blueyed] -
Remove flake8-polyfill dependency. flake8 >= 3.2.1 is required already, and
stdin is not read directly anymore.
[blueyed]
2.3 (2017-12-22)
-
Fix typo.
[paltman] -
Add tox.ini and .editorconfig to config search.
[cas–] -
Make this plugin compatible with flake8 hook.
As the hook copies the files out of tree,
flake8-isort never finds the correct configuration.
[jaysonsantos]
2.2.2 (2017-08-19)
-
Workaround for isort bug when skipping files.
[danpalmer]
2.2.1 (2017-05-12)
-
Release as universal wheel.
[gforcada]
2.2 (2017-03-26)
-
Support flake8 git hook.
[sergio-alonso] -
Support python 3.6.
[gforcada] -
Search configuration on home folder.
[gforcada]
2.1.3 (2016-11-25)
-
Fix yet another corner case.
[gforcada]
2.1.2 (2016-11-25)
-
Fix another corner case: ignored files.
[cas–]
2.1.1 (2016-11-25)
-
Fix corner cases of isort: newlines and grouped imports.
[cas–]
2.1.0 (2016-11-24)
-
Show the exact line and kind of error,
rather than a generic message.
[cas–]
2.0.3 (2016-11-22)
-
Update trove classifiers.
[gforcada]
2.0.2 (2016-11-22)
-
Add flake8 classifier.
[sigmavirus24] -
Require flake8 3.2.1.
flake8 series 3.1.x and 3.2.0 where not reporting flake8-isort errors.
[gforcada] -
Test on pypy and pypy3.
[gforcada] -
Fix tests and formatting.
[gforcada]
2.0.1 (2016-09-22)
-
Fix standard input processing.
[carljm]
2.0 (2016-09-14)
-
Refactor code to handle flake8 version 3.
[danpalmer] -
Require flake8 version 3.0.
[gforcada]
1.3 (2016-06-20)
-
Make error messages clearer.
[do3cc] -
Use either pep8 or pycodestyle (new name for pep8).
[Maxim Novikov] -
Fix coveralls.
[gforcada]
1.2 (2016-03-05)
-
Allow stdin processing, this way text editor can pass input to flake8.
[mjacksonw]
1.1.1 (2016-02-16)
-
Silence isort messages.
[gforcada] -
Improve wording.
[gforcada]
1.1 (2016-02-16)
-
Check for isort configuration on setup.cfg as well.
[plumdog]
1.0 (2015-12-16)
-
Check for an isort configuration file.
[gforcada]
0.2 (2015-09-14)
-
Fix entry point.
[gforcada]
0.1.post0 (2015-09-13)
-
Release wheels as well.
[gforcada]
0.1 (2015-09-13)
-
Initial release
[gforcada] -
Add all boilerplate files.
[gforcada] -
Create the flake8 plugin per se.
[gforcada]
What’s wrong
My lines.
import base64 import io import os import uuid import pandas as pd import config
Reviewdog on GitHub actions say False positive I004 isort found an unexpected blank line in imports
However, if I run isort and flake8-isort on the same content on my local environment, I get no errors as expected.
Githubactions
- wemake-services/wemake-python-styleguide@0.15.3
Local
- flake8: 4.0.1 (flake8_isort: 4.1.1, mccabe: 0.6.1, pycodestyle: 2.8.0, pyflakes: 2.4.0) CPython 3.8.7 on
Darwin - isort: 5.9.3
How it should be
Need consistency against local linters. This might be caused by flake8-isort version. Should be upgrade?
Flake8 version and plugins
local
{
"dependencies": [],
"platform": {
"python_implementation": "CPython",
"python_version": "3.8.7",
"system": "Darwin"
},
"plugins": [
{
"is_local": false,
"plugin": "flake8_isort",
"version": "4.1.1"
},
{
"is_local": false,
"plugin": "mccabe",
"version": "0.6.1"
},
{
"is_local": false,
"plugin": "pycodestyle",
"version": "2.8.0"
},
{
"is_local": false,
"plugin": "pyflakes",
"version": "2.4.0"
}
],
"version": "4.0.1"
}
pip information
local
pip 21.1.3 from /Users/traveroliver/workspace/masktap-spf/venv/lib/python3.8/site-packages/pip (python 3.8)
backports.entry-points-selectable==1.1.0
distlib==0.3.3
filelock==3.3.1
flake8==4.0.1
flake8-isort==4.1.1
isort==5.9.3
mccabe==0.6.1
numpy==1.21.2
packaging==21.0
pandas==1.3.2
platformdirs==2.4.0
pluggy==1.0.0
py==1.10.0
pycodestyle==2.8.0
pyflakes==2.4.0
pyparsing==3.0.1
python-dateutil==2.8.2
pytz==2021.1
six==1.16.0
testfixtures==6.18.3
toml==0.10.2
tox==3.24.4
virtualenv==20.9.0
OS information
local
macOS Big Sur version 11.6
Github Actions
ubuntu-latest
The issue has been closed
False positive I004 isort found an unexpected blank line in imports #2230
pomcho555 posted onGitHub
Fund this Issue
Pull requests