1 | initial version |
To set up isort to only sort within sections and leave existing sections as they are, you can use the "--profile" flag to create a custom configuration file and then modify the configuration as needed. Here are the steps you can follow:
isort --profile=create
to generate a default configuration file named pyproject.toml
.pyproject.toml
in a text editor and locate the [tool.isort]
configuration section.[tool.isort]
section to enable section sorting and prevent isort from creating new sections:force_sort_within_sections = true
force_single_line = true
known_first_party
and known_third_party
settings to specify the names of your project's modules and external packages, respectively. This will help isort group your imports more intelligently.pyproject.toml
file and run isort
again on your project directory. Isort will now only sort import statements within existing sections and leave the rest of the file's structure unchanged.Note that you may need to adjust the configuration settings depending on the specific structure of your codebase. For more information on all the available settings, see the isort documentation.