Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support no_sections option for isort #8653

Closed
jelmer opened this issue Nov 13, 2023 · 2 comments · Fixed by #8657
Closed

support no_sections option for isort #8653

jelmer opened this issue Nov 13, 2023 · 2 comments · Fixed by #8657
Labels
isort Related to import sorting

Comments

@jelmer
Copy link
Contributor

jelmer commented Nov 13, 2023

ruff's isort doesn't support the no_sections option that isort upstream has. This option puts all import sinto the same import bucket.

For example, consider this source file:

import os

import bar
import blah

isort --no-sections x.py format it as

import bar
import blah
import os

As far as I can tell, there is no set of options for ruff's isort that provides this behaviour (if there is and I've missed it, I'll volunteer to add a note to the docs)

@charliermarsh charliermarsh added the isort Related to import sorting label Nov 13, 2023
@charliermarsh
Copy link
Member

I don't believe we support this today.

@jelmer
Copy link
Contributor Author

jelmer commented Nov 13, 2023

FWIW I'm trying to come up with a PR for this.

jelmer added a commit to jelmer/ruff that referenced this issue Nov 13, 2023
This is similar to what exists in upstream isort.

Fixes astral-sh#8653
jelmer added a commit to jelmer/ruff that referenced this issue Nov 13, 2023
This is similar to what exists in upstream isort.

Fixes astral-sh#8653
jelmer added a commit to jelmer/ruff that referenced this issue Nov 13, 2023
This is similar to what exists in upstream isort.

Fixes astral-sh#8653
jelmer added a commit to jelmer/ruff that referenced this issue Nov 14, 2023
This is similar to what exists in upstream isort.

Fixes astral-sh#8653
charliermarsh pushed a commit that referenced this issue Nov 14, 2023
## Summary

This adds a ``no-sections`` option for isort in the linter, similar to
the ``no_sections`` option that exists in upstream isort
(https://pycqa.github.io/isort/docs/configuration/options.html#no-sections)

This option puts all imports except for ``__future__`` into the same
section, and is mostly used by monorepos.

I've taken a bit of a leap in assuming that ruff wants to support the
exact same option; more than happy to refactor if you'd prefer a
different way of setting this up.

Fixes #8653

## Test Plan

I've added a test and have run it on a large Python codebase that uses
isort with --no-sections. The option is disabled by default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
isort Related to import sorting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants