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

jayvdb created this task.Apr 8 2016, 1:58 AM
Restricted Application added a project: Documentation. · View Herald TranscriptApr 8 2016, 1:58 AM

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

jayvdb moved this task from Backlog to Reported Upstream on the Upstream board.

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

jayvdb updated the task description. (Show Details)Apr 8 2016, 4:52 PM

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

jayvdb triaged this task as Low priority.Apr 25 2016, 6:36 AM

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

jayvdb updated the task description. (Show Details)May 7 2016, 1:53 PM
jayvdb added a comment.May 7 2016, 2:07 PM

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

Dvorapa updated the task description. (Show Details)Sep 10 2018, 1:12 PM
Xqt moved this task from Backlog to Needs Review on the Pywikibot board.Feb 3 2019, 11:23 AM
Xqt closed this task as Declined.Apr 9 2019, 12:56 PM
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