Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working with isort new release v5.0.0 #88

Closed
srtab opened this issue Jul 4, 2020 · 10 comments · Fixed by #92
Closed

Not working with isort new release v5.0.0 #88

srtab opened this issue Jul 4, 2020 · 10 comments · Fixed by #92

Comments

@srtab
Copy link

srtab commented Jul 4, 2020

Hi,

I'm using flake8-isort plugin in my projects and since isort released the new version, v5.0.0, the plugin stopped working.
Here is the log with traceback:

Traceback (most recent call last):
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/plugins/manager.py", line 157, in load_plugin
    self._load()
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/plugins/manager.py", line 134, in _load
    self._plugin = self.entry_point.load()
  File "/app/.tox/lint/lib/python3.6/site-packages/importlib_metadata/__init__.py", line 105, in load
    module = import_module(match.group('module'))
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8_isort.py", line 3, in <module>
    from isort import SortImports
ImportError: cannot import name 'SortImports'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/app/.tox/lint/bin/flake8", line 8, in <module>
    sys.exit(main())
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/main/cli.py", line 22, in main
    app.run(argv)
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/main/application.py", line 360, in run
    self._run(argv)
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/main/application.py", line 347, in _run
    self.initialize(argv)
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/main/application.py", line 328, in initialize
    self.find_plugins(config_finder)
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/main/application.py", line 159, in find_plugins
    self.check_plugins.load_plugins()
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/plugins/manager.py", line 415, in load_plugins
    plugins = list(self.manager.map(load_plugin))
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/plugins/manager.py", line 302, in map
    yield func(self.plugins[name], *args, **kwargs)
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/plugins/manager.py", line 413, in load_plugin
    return plugin.load_plugin()
  File "/app/.tox/lint/lib/python3.6/site-packages/flake8/plugins/manager.py", line 164, in load_plugin
    raise failed_to_load
flake8.exceptions.FailedToLoadPlugin: Flake8 failed to load plugin "I00" due to cannot import name 'SortImports'.
@pkolbus
Copy link
Contributor

pkolbus commented Jul 4, 2020

It looks like setup.py doesn't specify a maximum version of isort. And it looks like the API and supported Python versions have changed between v4 and v5. Making a quick release that pins to <5 would help until this can be figured out. Likewise, the requirement for flake8 is unbounded, which represents a risk (should be <4).

Since Semantic Versioning (or a close approximation) is widely used in the Python community, I've found pinning the major version of dependencies to be an excellent way to minimize breakage for my users. (And once the next major version stabilizes enough to work well, expanding or adjusting the ranges.)

@mar10
Copy link

mar10 commented Jul 5, 2020

My quick-fix for tox:

[testenv:lint]
...
deps =
    flake8
    flake8-isort
    ...
    # can be relaxed, once flake8-isort dependency is resolved (https://github.com/gforcada/flake8-isort/issues/88)
    isort<5  

arthurdejong added a commit to arthurdejong/python-stdnum that referenced this issue Jul 5, 2020
Do not install the latest isort because it currently breaks
flake8-isort. This pinning should be removed as soon as
gforcada/flake8-isort#88 is resolved.
ColdHeat added a commit to CTFd/CTFd that referenced this issue Jul 6, 2020
@webknjaz
Copy link
Contributor

webknjaz commented Jul 6, 2020

Did the same hotfix: ansible/pylibssh@2d7b003.

ColdHeat added a commit to CTFd/CTFd that referenced this issue Jul 6, 2020
* Closes #1530 
* Clean up some wording and comments
* Pin isort version to fix flake8 issue (gforcada/flake8-isort#88)
mjpieters added a commit to mjpieters/flakehell that referenced this issue Jul 7, 2020
flake8-isort has [pinned itself to isort 4.x](gforcada/flake8-isort#88), and [so has pylint](https://github.com/PyCQA/pylint/blob/master/pylint/__pkginfo__.py#L41), but dephell hits some kind of infinite recursion trying to resolve this between those two packages, and the unqualified `isort[pyproject]` dependency in pyproject.toml.

By restricting isort, dephell can complete installing.
mnencia added a commit to EnterpriseDB/barman that referenced this issue Jul 7, 2020
This pinning should be removed as soon as gforcada/flake8-isort#88 is
resolved.

Signed-off-by: Marco Nenciarini <marco.nenciarini@2ndquadrant.it>
@153957
Copy link

153957 commented Jul 8, 2020

Fixed in flake8-isort 3.0.1.

@stevepiercy
Copy link

@153957 it is not a fix. It is a workaround that avoids isort v.5.0.x. See #89 (comment)

@stevepiercy
Copy link

stevepiercy commented Jul 8, 2020

We just got an issue in Pyramid that refers to the isort 5.0.0 upgrade guide. Perhaps that will be of assistance to updating flake8-isort?

@153957
Copy link

153957 commented Jul 9, 2020

arthurdejong added a commit to arthurdejong/munin-plot that referenced this issue Jul 9, 2020
Do not install the latest isort because it currently breaks
flake8-isort. This pinning should be removed as soon as
gforcada/flake8-isort#88 is resolved.
@pkolbus
Copy link
Contributor

pkolbus commented Jul 12, 2020

@153957 - thanks for the link. Sadly, that doesn't discuss the API that flake8-isort uses.

I did some prototyping this evening to figure out the level of difficulty here. From what I can tell, a lot of the details from the SortImport class just aren't in the API anymore. The best replacements seem to be isort.api.check_file() and isort.api.check_code_string(), using these I've gotten flake-isort to fail and show a diff in the simplest of cases, but most of the tests are still red. Preserving the granularity in Flake8Isort.sortimports_linenum_msg() probably requires parsing the unified diff, and might need to pass in a Config object too.

Additionally, isort 5 dropped support for python 2.7 and 3.5, so keeping these older Python working is going to take additional complexity to support both ways. Pylint supports both isort 4 and isort 5 with a wrapper class (pylint-dev/pylint#3725) but that usage is less entangled to the isort design and even then some tests are skipped for isort 4.

I've pushed the prototype to my fork, at https://github.com/pkolbus/flake8-isort/tree/isort-5 -- will need to put further work on hold for now, but hopefully it helps someone else take it forward.

@bnavigator
Copy link
Contributor

I've pushed the prototype to my fork, at https://github.com/pkolbus/flake8-isort/tree/isort-5 -- will need to put further work on hold for now, but hopefully it helps someone else take it forward.

I started to work on #92 before I saw your comment, but I basically took the same approach. Tests failed mostly because of the different config file handling, so I adjusted them too.

@gforcada
Copy link
Owner

Thanks a lot for the discussions and effort! 🙇 I will try to review the PR and get as less in the way as possible 😓 though I will be on vacations for the next 10 days, do my availability will be scarce 😕

joolean added a commit to HearthSim/python-hearthstone that referenced this issue Jul 14, 2020
@gbroques gbroques mentioned this issue Aug 9, 2020
thomaspreece pushed a commit to thomaspreece/rd-ctf-2020 that referenced this issue Nov 24, 2020
* Closes #1530 
* Clean up some wording and comments
* Pin isort version to fix flake8 issue (gforcada/flake8-isort#88)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants