Add isort pre-commit hook and configuration to all repos
Sorting Python imports manually is quite cumbersome so we should use the isort tool to handle that process and get consistent imports ordering across all swh modules.
As an example, swh-web!404 (closed) adds a new pre-commit hook in swh-web
to call isort
when committing with a configuration
compatible with black
formatter.
That task is here to define the isort
configuration that will be used in all modules. Proposed one is the following:
[tool.isort]
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
line_length = 88
force_sort_within_sections = true
Basically it corresponds to the recommended settings when using black plus the addition of force_sort_within_sections = true
(which sorts from x import y
before import z
instead of grouping from imports together at the bottom)
More options are available here.
Migrated from T2610 (view on Phabricator)
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- Antoine Lambert added Development environment priority:Normal labels
added Development environment priority:Normal labels
- Maintainer
+1 to the idea (and to the specific config as I have already bikeshed it)
- Maintainer
LGTM
(I was initially surprised by the mixing together of "import" lines with "from ... import" ones, but upon reflection it makes a lot of sense, because one might have to switch between the two forms, and it's silly to have to move the line back and forth between import blocks when that happens.)
- Author Maintainer
You might need to skip .py files in tests/*/data (eg. swh-web iirc)
Right ! Once global isort config will be pushed to repos, I will update swh-web!404 (closed) with specific
swh-web
configuration only (django import grouping, paths exclusion). - Phabricator Migration user mentioned in commit swh-core@ba8a9783
mentioned in commit swh-core@ba8a9783
- Author Maintainer
Ok so the plan to integrate
isort
in all repos will be the following:- Integrate the following diff (manually) in all repos using the
change-all-repos
script from @vlorentz but do not push to remote yet
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ab0e08..df70797 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,11 @@ repos: language: system types: [python] +- repo: https://github.com/PyCQA/isort + rev: 5.5.2 + hooks: + - id: isort + - repo: https://github.com/python/black rev: 19.10b0 hooks: diff --git a/pyproject.toml b/pyproject.toml index b5413f6..206af2c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,12 @@ [tool.black] target-version = ['py37'] + +[tool.isort] +multi_line_output = 3 +include_trailing_comma = true +force_grid_wrap = 0 +use_parentheses = true +ensure_newline_before_comments = true +line_length = 88 +force_sort_within_sections = true +
- Run
make check
in all repos to apply imports ordering - Run
make test
in all repos to check and fix possible side effects - Once it is done, add a new commit for the imports ordering
- Push to remotes
- Integrate the following diff (manually) in all repos using the
- Phabricator Migration user mentioned in commit swh-dataset@c33e8ea7
mentioned in commit swh-dataset@c33e8ea7
- Phabricator Migration user mentioned in commit swh-deposit@52c057db
mentioned in commit swh-deposit@52c057db
- Phabricator Migration user mentioned in commit swh-docs@b60869d8
mentioned in commit swh-docs@b60869d8
- Phabricator Migration user mentioned in commit swh-graph@ecb7cca2
mentioned in commit swh-graph@ecb7cca2
- Phabricator Migration user mentioned in commit swh-icinga-plugins@832a11a6
mentioned in commit swh-icinga-plugins@832a11a6
- Phabricator Migration user mentioned in commit swh-indexer@c6fcd222
mentioned in commit swh-indexer@c6fcd222
- Phabricator Migration user mentioned in commit swh-journal@b5969a7a
mentioned in commit swh-journal@b5969a7a
- Phabricator Migration user mentioned in commit swh-lister@d24846a9
mentioned in commit swh-lister@d24846a9
- Phabricator Migration user mentioned in commit swh-loader-core@cc2ffe15
mentioned in commit swh-loader-core@cc2ffe15
- Phabricator Migration user mentioned in commit swh-loader-git@152eece9
mentioned in commit swh-loader-git@152eece9
- Phabricator Migration user mentioned in commit swh-loader-mercurial@21a66f4f
mentioned in commit swh-loader-mercurial@21a66f4f
- Phabricator Migration user mentioned in commit swh-model@5bda22fb
mentioned in commit swh-model@5bda22fb
- Phabricator Migration user mentioned in commit swh-objstorage@35a796bf
mentioned in commit swh-objstorage@35a796bf
- Phabricator Migration user mentioned in commit swh-objstorage-replayer@915721a1
mentioned in commit swh-objstorage-replayer@915721a1
- Phabricator Migration user mentioned in commit swh-py-template@53ca9e43
mentioned in commit swh-py-template@53ca9e43
- Phabricator Migration user mentioned in commit swh-scanner@64381b25
mentioned in commit swh-scanner@64381b25
- Phabricator Migration user mentioned in commit swh-search@9b7516f4
mentioned in commit swh-search@9b7516f4
- Phabricator Migration user mentioned in commit swh-storage@d27a0464
mentioned in commit swh-storage@d27a0464
- Phabricator Migration user mentioned in commit swh-vault@cf35fb7e
mentioned in commit swh-vault@cf35fb7e
- Phabricator Migration user mentioned in commit swh-web@d24922fc
mentioned in commit swh-web@d24922fc
- Phabricator Migration user mentioned in commit swh-web-client@814057d3
mentioned in commit swh-web-client@814057d3
- Phabricator Migration user mentioned in commit swh-loader-svn@c1ac9322
mentioned in commit swh-loader-svn@c1ac9322
- Phabricator Migration user mentioned in commit swh-scheduler@8d8b58f4
mentioned in commit swh-scheduler@8d8b58f4
- Phabricator Migration user mentioned in commit swh-core@28d61c8c
mentioned in commit swh-core@28d61c8c
- Author Maintainer
Ok so I applied the above process locally and no bad surprises when running all test suites. I will push the changes to remote then and close that task once it is done.
- Phabricator Migration user mentioned in commit swh-dataset@48ba2a40
mentioned in commit swh-dataset@48ba2a40
- Maintainer
awesome, thanks.
- Phabricator Migration user mentioned in commit swh-deposit@a12b1195
mentioned in commit swh-deposit@a12b1195
- Phabricator Migration user mentioned in commit swh-docs@643141a2
mentioned in commit swh-docs@643141a2
- Phabricator Migration user mentioned in commit swh-graph@685a232a
mentioned in commit swh-graph@685a232a
- Phabricator Migration user mentioned in commit swh-icinga-plugins@ca1f5f73
mentioned in commit swh-icinga-plugins@ca1f5f73
- Phabricator Migration user mentioned in commit swh-indexer@27524b20
mentioned in commit swh-indexer@27524b20
- Phabricator Migration user mentioned in commit swh-journal@c8a14b0a
mentioned in commit swh-journal@c8a14b0a
- Phabricator Migration user mentioned in commit swh-lister@22f71812
mentioned in commit swh-lister@22f71812
- Phabricator Migration user mentioned in commit swh-loader-core@7b2c80e7
mentioned in commit swh-loader-core@7b2c80e7
- Phabricator Migration user mentioned in commit swh-loader-git@d733c4c4
mentioned in commit swh-loader-git@d733c4c4
- Phabricator Migration user mentioned in commit swh-loader-mercurial@6d22cbeb
mentioned in commit swh-loader-mercurial@6d22cbeb
- Phabricator Migration user mentioned in commit swh-loader-svn@40f407c7
mentioned in commit swh-loader-svn@40f407c7
- Phabricator Migration user mentioned in commit swh-model@a2737185
mentioned in commit swh-model@a2737185
- Phabricator Migration user mentioned in commit swh-objstorage@eca35aa1
mentioned in commit swh-objstorage@eca35aa1
- Phabricator Migration user mentioned in commit swh-objstorage-replayer@91adace7
mentioned in commit swh-objstorage-replayer@91adace7
- Phabricator Migration user mentioned in commit swh-py-template@f7cf1023
mentioned in commit swh-py-template@f7cf1023
- Phabricator Migration user mentioned in commit swh-scanner@f47dc800
mentioned in commit swh-scanner@f47dc800
- Phabricator Migration user mentioned in commit swh-scheduler@7b0d48fa
mentioned in commit swh-scheduler@7b0d48fa
- Phabricator Migration user mentioned in commit swh-search@74e1faf7
mentioned in commit swh-search@74e1faf7
- Phabricator Migration user mentioned in commit swh-storage@b0027abc
mentioned in commit swh-storage@b0027abc
- Phabricator Migration user mentioned in commit swh-vault@2b6cc781
mentioned in commit swh-vault@2b6cc781
- Phabricator Migration user mentioned in commit swh-web@a35c45e8
mentioned in commit swh-web@a35c45e8
- Phabricator Migration user mentioned in commit swh-web-client@257409e1
mentioned in commit swh-web-client@257409e1
- Author Maintainer
All repositories have been successfully processed, closing this.
- Antoine Lambert assigned to @anlambert
assigned to @anlambert
- Antoine Lambert closed
closed
- Phabricator Migration user mentioned in merge request swh-loader-mercurial!30 (closed)
mentioned in merge request swh-loader-mercurial!30 (closed)
- Phabricator Migration user mentioned in merge request swh-web!404 (closed)
mentioned in merge request swh-web!404 (closed)