Ignite: Use isort for consistent PEP8-compliant imports layout

Created on 7 Apr 2020  路  4Comments  路  Source: pytorch/ignite

馃殌 Feature


I propose to use isort to automate and enforce PEP8-compliant imports layout, especially:

Imports should be grouped in the following order:

  1. Standard library imports.
  2. Related third party imports.
  3. Local application/library specific imports.

You should put a blank line between each group of imports.


Automated code quality tools lead to more consistent code and ease code review as code style is checked automatically. Ignite already relies on black for code formatting and uses pre-commit. In my opinion, isort would be a great addition.


Steps:

  • Add an isort hook in .pre-commit-config.yaml
  • Use isort in .travis.yml to check imports layout
  • Apply isort once to all Python files to fix imports layout where necessary
enhancement help wanted

All 4 comments

@sisp thank a lot for this suggestion! I agree, this would be a great addition !
If you would like to send a PR with that, it would be great :)
Do you think we could even set it in autopep workflow : https://github.com/pytorch/ignite/blob/master/.github/workflows/autopep8-black.yml for automatic formatting ?

I'd be happy to send a PR. I've not worked with GitHub Workflows, but I see no reason why it shouldn't be possible.

@sisp sounds good !

Concerning Github Workfow, we can try to use: https://github.com/marketplace/actions/sort-your-python-imports-with-isort

    - name: Run isort
      uses: olance/[email protected]
      with:
        args: .

and insert it into existing autopep8-black.yml (maybe renaming it into autopep8-black-isort.yml ?)

Closed by #901

Was this page helpful?
0 / 5 - 0 ratings