Skip to content

Add separate_packages option - #2313

Merged
DanielNoord merged 1 commit into
PyCQA:mainfrom
loft-orbital:loft-main
Mar 10, 2026
Merged

DanielNoord merged 1 commit into
PyCQA:mainfrom
loft-orbital:loft-main

Conversation

@alex-liang3

@alex-liang3 alex-liang3 commented Dec 12, 2024 •

Copy link
Copy Markdown
Contributor

Resolves #2104 by adding a separate_packages config option. This should also cover #2262.

Sections provided in this field will have the packages within them be separated by a blank line. This also works with custom known_OTHER sections; see tests for examples.

For reference, these changes increase the cyclomatic complexity (PY-R1000) of this function from 68 to 75, so I'm proposing to ignore the check on this function for the same reason as in https://github.com/PyCQA/isort/pull/2340/files#diff-d97e563d18af5b82fdf3bbb340c60da3e6955177a064fcbaf7e8676589933ddaR243

@vavanade

vavanade commented Jan 8, 2025

Copy link
Copy Markdown

Any chance of merging this one?

It would really help me. Now I had to write a very ugly hack for the config file to simulate this behavior.

@codecov

codecov Bot commented Feb 19, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.25%. Comparing base (a333737) to head (c5dee46).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2313   +/-   ##
=======================================
  Coverage   99.24%   99.25%           
=======================================
  Files          39       39           
  Lines        3057     3084   +27     
  Branches      675      682    +7     
=======================================
+ Hits         3034     3061   +27     
  Misses         13       13           
  Partials       10       10           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@staticdev staticdev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for your contributing @alex-liang3. I made some comments with suggestions of how to better benefit from the new option.

Comment thread isort/output.py
section_output.append("") # Empty line for black compatibility
section_output.append(section_comment_end)

if section in config.separate_packages:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this @alex-liang3. I know the complexy of this method was already high, but this pirce of code you added here is a perfect candidate for an extract method. With that we could start the needed refactor here to reduce the complexity. Could you please do this refactor?

Comment thread isort/output.py Outdated
from .settings import DEFAULT_CONFIG, Config


# Ignore DeepSource cyclomatic complexity check for this function. It was

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we dont need to add those lines (see my next comment).


## Separate Packages

Separate packages within the listed sections with newlines.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding an example here to make it more clear?

@alex-liang3

Copy link
Copy Markdown
Contributor Author

Thanks for the review @staticdev, and all your efforts on this project so far! I've made the requested changes now, but unfortunately the function call itself still adds +1 to the cyclomatic complexity (the criticality threshold is 50).

Let me know what you think of the changes :)

@lucas-bremond

Copy link
Copy Markdown

Hello @staticdev, I'm also interested in using this feature. Would it be possible to consider merging it?

@DanielNoord

Copy link
Copy Markdown
Member

@alex-liang3 Sorry this rotted.

Do you mind giving maintainers access to push to this branch? That way I can resolve merge conflicts and ensure this gets merged.

@alex-liang3
alex-liang3 force-pushed the loft-main branch 2 times, most recently from f4d1034 to 9cf9d50 Compare March 10, 2026 06:49
Adds the ability to separate packages within a section with blank lines.
---------

Co-authored-by: Lucas <lucas.bremond@gmail.com>

chore: make python3.8-compatible (#2)

chore: use python 3.8-style typing

ci: ignore PY-R1000

refactor: breakout function, add examples (#4)

* Revert "ci: ignore PY-R1000"

* refactor: breakout logic into separate function

* docs: add examples

chore: remove py3.8 types

style: fix format

style: fix formatting
@alex-liang3

Copy link
Copy Markdown
Contributor Author

Hi @DanielNoord, unfortunately I can't give maintainers access to that branch, but I've gone ahead and fixed up the merge conflicts. Let me know if you need any other changes :)

@DanielNoord
DanielNoord added this pull request to the merge queue Mar 10, 2026
Merged via the queue into PyCQA:main with commit ff24a9b Mar 10, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Option to add empty line(s) between top-level package imports

5 participants