Page MenuHomePhabricator

Enable isort for pywikibot import rules
Closed, DeclinedPublic

Description

isort can re-order/check imports according to a predefined ruleset.

It looks like it doesnt support pywikibot's complex code 'correctly', but we may be able to develop a usable ruleset with some files excluded, in which case we can enable flake8-isort, and we can use that as the basis of documentation.

It might be necessary to improve isort to generate imports in the desired pep8 ordering.
And it may be beneficial to improve isort to better match our stylistic choices, however minor changes of our style would be acceptable when flake8-isort is enabled to ensure that the result style becomes a concrete enforced coding style.

Issues raised:

Event Timeline

I see @AbdealiJK is using isort for a different project; maybe has some experience of problems we'll experience.

One relevant issue has already been logged: https://github.com/timothycrosley/isort/issues/393

There was another issue about isort giving different results in different machines but that got fixed in 4.2.3+.

And there was another issue where in a file the ordering of the imports was important because of unusual dependency issues. This was a problem with the code base of that project rather than in isort. If such a thing is seen in pywikibot we should refactor that part to allow any import order.

That's about it from what I remember

https://github.com/timothycrosley/isort/issues/421 (imports in try: except: block forced under all other imports) was closed as wontfix. I think this means isort wont be feasable in the near future and we should look at the other similar tools:

https://pypi.python.org/pypi?%3Aaction=search&term=Sort+imports&submit=search

Why not simply add appropriate comments in those lines to ignore isort's results there ?
Like # noqa etc. ?

Why not simply add appropriate comments in those lines to ignore isort's results there ?
Like # noqa etc. ?

I couldnt get that to work. Maybe I missed something.

Change 459499 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [check] Don't care about import order any longer; use isort instead

https://gerrit.wikimedia.org/r/459499

Change 459502 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [PEP8] Import sorting order using isort for main folder

https://gerrit.wikimedia.org/r/459502

Change 459503 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [PEP8] Import sorting order using isort for docs folder

https://gerrit.wikimedia.org/r/459503

Change 459519 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [PEP8] Import sorting order using isort for pywikibot folder

https://gerrit.wikimedia.org/r/459519

Change 459522 had a related patch set uploaded (by Xqt; owner: Xqt):
[pywikibot/core@master] [PEP8] Import sorting order using isort for family files

https://gerrit.wikimedia.org/r/459522

Xqt removed a project: Patch-For-Review.

Change 459519 abandoned by Xqt:
[PEP8] Import sorting order using isort for pywikibot folder

https://gerrit.wikimedia.org/r/459519

Change 459522 abandoned by Xqt:
[PEP8] Import sorting order using isort for family files

https://gerrit.wikimedia.org/r/459522

Change 459503 abandoned by Xqt:
[PEP8] Import sorting order using isort for docs folder

https://gerrit.wikimedia.org/r/459503

Change 459502 abandoned by Xqt:
[PEP8] Import sorting order using isort for main folder

https://gerrit.wikimedia.org/r/459502

Change 459499 abandoned by Xqt:
[check] Don't care about import order any longer; use isort instead

https://gerrit.wikimedia.org/r/459499