Skip to content

Commit ed36d26

Browse files
authoredDec 25, 2021
πŸ“š Replace reorder-python-imports with isort (#1097)
* πŸ“š [README] Add isort to list of features * πŸ“š [guide] Update table of dependencies * πŸ“š [guide] Replace reorder-python-imports with isort
1 parent 0b1af65 commit ed36d26

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed
 

β€ŽREADME.rst

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ Features
7575
- Automated release notes with `Release Drafter`_
7676
- Automated dependency updates with Dependabot_
7777
- Code formatting with Black_ and Prettier_
78+
- Import sorting with isort_
7879
- Testing with pytest_
7980
- Code coverage with Coverage.py_
8081
- Coverage reporting with Codecov_
@@ -104,6 +105,7 @@ The template supports Python 3.7, 3.8, 3.9, and 3.10.
104105
.. _Flake8: http://flake8.pycqa.org
105106
.. _GitHub Actions: https://github.com/features/actions
106107
.. _Hypermodern Python: https://medium.com/@cjolowicz/hypermodern-python-d44485d9d769
108+
.. _isort: https://pycqa.github.io/isort/
107109
.. _Nox: https://nox.thea.codes/
108110
.. _Poetry: https://python-poetry.org/
109111
.. _Prettier: https://prettier.io/

β€Ždocs/guide.rst

+42-35
Original file line numberDiff line numberDiff line change
@@ -745,32 +745,32 @@ See the table below for an overview of the dependencies of generated projects:
745745
.. table:: Dependencies
746746
:widths: auto
747747

748-
======================= ====================================================================================
749-
black_ The uncompromising code formatter.
750-
click_ Composable command line interface toolkit
751-
coverage__ Code coverage measurement for Python
752-
darglint_ A utility for ensuring Google-style docstrings stay up to date with the source code.
753-
flake8_ the modular source code checker: pep8 pyflakes and co
754-
flake8-bandit_ Automated security testing with bandit and flake8.
755-
flake8-bugbear_ A plugin for flake8 finding likely bugs and design problems in your program.
756-
flake8-docstrings_ Extension for flake8 which uses pydocstyle to check docstrings
757-
flake8-rst-docstrings_ Python docstring reStructuredText (RST) validator
758-
furo_ A clean customisable Sphinx documentation theme.
759-
mypy_ Optional static typing for Python
760-
pep8-naming_ Check PEP-8 naming conventions, plugin for flake8
761-
pre-commit_ A framework for managing and maintaining multi-language pre-commit hooks.
762-
pre-commit-hooks_ Some out-of-the-box hooks for pre-commit.
763-
pygments_ Pygments is a syntax highlighting package written in Python.
764-
pytest_ pytest: simple powerful testing with Python
765-
pyupgrade_ A tool to automatically upgrade syntax for newer versions.
766-
reorder-python-imports_ Tool for reordering python imports
767-
safety_ Checks installed dependencies for known vulnerabilities.
768-
sphinx_ Python documentation generator
769-
sphinx-autobuild_ Rebuild Sphinx documentation on changes, with live-reload in the browser.
770-
sphinx-click_ Sphinx extension that automatically documents click applications
771-
typeguard_ Run-time type checker for Python
772-
xdoctest_ A rewrite of the builtin doctest module
773-
======================= ====================================================================================
748+
====================== ====================================================================================
749+
black_ The uncompromising code formatter.
750+
click_ Composable command line interface toolkit
751+
coverage__ Code coverage measurement for Python
752+
darglint_ A utility for ensuring Google-style docstrings stay up to date with the source code.
753+
flake8_ the modular source code checker: pep8 pyflakes and co
754+
flake8-bandit_ Automated security testing with bandit and flake8.
755+
flake8-bugbear_ A plugin for flake8 finding likely bugs and design problems in your program.
756+
flake8-docstrings_ Extension for flake8 which uses pydocstyle to check docstrings
757+
flake8-rst-docstrings_ Python docstring reStructuredText (RST) validator
758+
furo_ A clean customisable Sphinx documentation theme.
759+
isort_ A Python utility / library to sort Python imports.
760+
mypy_ Optional static typing for Python
761+
pep8-naming_ Check PEP-8 naming conventions, plugin for flake8
762+
pre-commit_ A framework for managing and maintaining multi-language pre-commit hooks.
763+
pre-commit-hooks_ Some out-of-the-box hooks for pre-commit.
764+
pygments_ Pygments is a syntax highlighting package written in Python.
765+
pytest_ pytest: simple powerful testing with Python
766+
pyupgrade_ A tool to automatically upgrade syntax for newer versions.
767+
safety_ Checks installed dependencies for known vulnerabilities.
768+
sphinx_ Python documentation generator
769+
sphinx-autobuild_ Rebuild Sphinx documentation on changes, with live-reload in the browser.
770+
sphinx-click_ Sphinx extension that automatically documents click applications
771+
typeguard_ Run-time type checker for Python
772+
xdoctest_ A rewrite of the builtin doctest module
773+
====================== ====================================================================================
774774

775775
__ Coverage.py_
776776

@@ -1635,7 +1635,7 @@ validating changes staged for a commit.
16351635

16361636
Requiring changes to be staged allows for a nice property:
16371637
Many pre-commit hooks support fixing offending lines automatically,
1638-
for example ``black``, ``prettier``, and ``reorder-python-imports``.
1638+
for example ``black``, ``prettier``, and ``isort``.
16391639
When this happens,
16401640
your original changes are in the staging area,
16411641
while the fixes are in the work tree.
@@ -1659,13 +1659,13 @@ The |HPC| comes with a pre-commit configuration consisting of the following hook
16591659
======================== ===============================================
16601660
`black <Black_>`__ Run the Black_ code formatter
16611661
`flake8 <Flake8_>`__ Run the Flake8_ linter
1662+
isort_ Rewrite source code to sort Python imports
16621663
`prettier <Prettier_>`__ Run the Prettier_ code formatter
16631664
pyupgrade_ Upgrade syntax to newer versions of Python
16641665
check-added-large-files_ Prevent giant files from being committed
16651666
check-toml_ Validate TOML_ files
16661667
check-yaml_ Validate YAML_ files
16671668
end-of-file-fixer_ Ensure files are terminated by a single newline
1668-
reorder-python-imports_ Rewrites source to reorder python imports
16691669
trailing-whitespace_ Ensure lines do not contain trailing whitespace
16701670
======================== ===============================================
16711671

@@ -1702,15 +1702,23 @@ Flake8_ is an extensible linter framework for Python.
17021702
For more details, see the section :ref:`Linting with Flake8`.
17031703

17041704

1705-
The reorder-python-imports hook
1706-
-------------------------------
1705+
The isort hook
1706+
--------------
17071707

1708-
reorder-python-imports_ sorts imports in your Python code.
1708+
isort_ reorders imports in your Python code.
17091709
Imports are separated into three sections,
17101710
as recommended by `PEP 8`_: standard library, third party, first party.
1711-
The tool also splits ``from`` imports onto separate lines to avoid merge conflicts,
1712-
and moves them after normal imports.
1713-
Any duplicate imports are removed.
1711+
There are two additional sections,
1712+
one at the top for `future imports <https://docs.python.org/3/library/__future__.html>`__,
1713+
the other at the bottom for `relative imports <https://docs.python.org/3/reference/import.html#package-relative-imports>`__.
1714+
Within each section, ``from`` imports follow normal imports.
1715+
Imports are then sorted alphabetically.
1716+
1717+
The |HPC| activates the `Black profile <https://pycqa.github.io/isort/docs/configuration/black_compatibility.html>`__ for compatibility with the Black code formatter.
1718+
Furthermore, the `force_single_line <https://pycqa.github.io/isort/docs/configuration/options.html#force-single-line>`__ setting is enabled.
1719+
This splits imports onto separate lines to avoid merge conflicts.
1720+
Finally, two blank lines are enforced after imports for consistency,
1721+
via the `lines_after_imports <https://pycqa.github.io/isort/docs/configuration/options.html#lines-after-imports>`__ setting.
17141722

17151723

17161724
The pyupgrade hook
@@ -2651,6 +2659,5 @@ __ https://cjolowicz.github.io/posts/hypermodern-python-01-setup/
26512659
.. _pydocstyle: http://www.pydocstyle.org/
26522660
.. _pyflakes: https://github.com/PyCQA/pyflakes
26532661
.. _pygments: https://pygments.org/
2654-
.. _reorder-python-imports: https://github.com/asottile/reorder_python_imports
26552662
.. _reStructuredText: https://docutils.sourceforge.io/rst.html
26562663
.. _sphinx-autobuild: https://github.com/executablebooks/sphinx-autobuild

0 commit comments

Comments
 (0)
Please sign in to comment.