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
provide a way to mix stdlib and third party libraries in one section #761
Comments
I think this kind of combine syntax is really intuitive and a great feature addition. I usually just sort my imports like this: What's the status on a feature like this? Does any maintainer have any opinions? Is it open for PRs? Sad to see it just sit here all alone. EDIT: Actually, this issue is very similar to/same as #447. They both essentially want a way to merge sections. |
FWIW I'm having success by just dropping the
|
Closing as duplicate of 447 |
@timothycrosley this isn't a dupe of #447 since that was resolved with (posting this in hopes that this issue can be re-opened rather than me going and creating yet another issue) From @mmerickel
From @fgblomqvist
My use case is that I am running |
The main issue is setting |
That makes sense, I don't know how to resolve that generally to differentiate between local packages and system packages without maintaining a list. I solve this at $work in our monorepo by placing all the packages into the same namespace (namespace packages), and tagging that namespace as known_first_party. |
Overall, I'm fine mixing first-party and third-party, its a small price to pay to get |
Hi @epage I'm sorry you've encountered issues using isort around this! In my opinion, @mmerickel's solution is the right one, and I know it is used by some major projects. You can combine any sections, simply by correctly setting the
And everything will end up in the third_party section.
I appreciate the goal to reduce the number of issues. I will say, I do as a general rule, encourage new issues to be raised, since I get a lot of email and am not the only maintainer. isort only has 20 open issues, but > 800 closed ones. It is much more likely that comments in open issues will be actioned, and not forgotten simply because of communication overload!
What version of isort are you using? If you are using 5.x.x there is a good chance everything will work correctly simply putting by listing out the src_paths of your monorepo with an isort config at the root. If not the solution above can be used. If you are not using 5.x.x see the upgrade guide here: https://pycqa.github.io/isort/docs/major_releases/introducing_isort_5/ If these steps don't help resolve your issue, please feel empowered to create a new one Thanks! |
I'm assuming that is not literal but that I should be populating those fields with all my source and third party (since loading that config fails). Digging into it, it looks like
is accepted by It also looks like all the fancy finders have been removed so third-party is only determined by the default section and So I think that should cover my use case in a maintainable way (since the alternative involved maintaining an explicit list of either source or third party in a constantly evolving repo is adding more friction to the process and could tip the balance in to dropping |
@epage exactly right! I did initially intend to make something you could literally copy, but failed in my at the time sleep deprived state - I'm glad you figured out the correct config, and listed it here for future users who run into this issue.
🎉 I'm so glad that will work for you! The other thing that can work in a monorepo is just putting the .isort.cfg in the root of the repo, and then it will pick up all source paths automatically from there. But, this is highly dependent on how your monorepo is set up. Either way, maybe not worth risking the good thing you've got going with the updated config. |
stdlib dependencies and third party dependencies are indistinguishable in many cases and I would like to sort them into the same section, separately from local dependencies.
For example,
enum
is stdlib on Python 3 but third party on Python 2 when using a backport. The order of the sorting is different based on whether I runisort
using Python 2 or Python 3.It's possible to fix this with
known_standard_library=...
but this is tedious to maintain if I want to sort every single third party library along with stdlibs.I'd propose some form of
+
syntax allowing me to specifysections=FUTURE,STDLIB+THIRDPARTY,FIRSTPARTY,LOCALFOLDER
.Even if my rationale is not interesting, I think the syntax is very useful to be able to combine a couple sections which is not currently possible. You can specify a line break or not between sections, but there's no current way to actually just combine them.
The text was updated successfully, but these errors were encountered: