-
-
Notifications
You must be signed in to change notification settings - Fork 582
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
Interopability with black #694
Comments
@timothycrosley if you would accept a PR for this it would be fantastic! |
In fact, Black now does what "Mode 3 + trailing commas" is doing in isort. This is no longer necessary. |
Unsure whether this is a black or isort thing, but I believe there's a bit of overlap about how many lines are added after imports when using both libraries. When using VSCode with both libraries set to format on save, the following script will be formatted alternatively with one or two line after imports. The two outputs will be set alternatively: from collections import Mapping
from typing import Optional
class Headers:
def __init__(seq: Optional[Mapping] = None, encoding: str = "utf-8") -> None: ... Will output alternatively (1 line after imports): from collections import Mapping
from typing import Optional
class Headers:
def __init__(seq: Optional[Mapping] = None, encoding: str = "utf-8") -> None: ... and (2 lines after imports): from collections import Mapping
from typing import Optional
class Headers:
def __init__(seq: Optional[Mapping] = None, encoding: str = "utf-8") -> None: ... ... back and forth. I don't want to hijack this issue, so maybe this should be better off discussed as a distinct issue. I'm unsure whether it should be created on Thanks for creating these nice libraries. |
Thanks for reopening. Black has since adopted what is almost exactly mode 3 in isort. There are a few edge cases that we can work through to ensure the tools are perfectly matched but they should be pretty close already :-) |
@ambv sounds good! Mostly, I realized this came up during a period where I was not as attentive to this project as I aim to be - and have been in the past. For the next release of isort in a week or so, I would like to ensure that there is an included black profile so that users don't have to mess with a ton of settings to use the two tools together. I'll start with the settings listed on the black GitHub page. And please, feel empowered to let me know of any incompatibilities and I'll do my best to resolve them in short order. Thanks! ~Timothy P.S. black is very cool, and something I've wanted to exist in the Python world for some time. I've introduced it in my work environment with great success and plan on using it with my open source code bases as well. So interoperability is very practically important for me :). |
That is so nice to hear! Infact we use both of the awesome tools. i.e. black and isort in our project https://github.com/einsteinpy/einsteinpy . And this incompatibility creates a lot of issues. Can we not add a CI check for every PR to check if compatibility with black is retained? |
It seems that isort is not compatible with black at the moment: psf/black#127 PyCQA/isort#694 Both isort and black are working on a solution, but at the moment, we'll use flake8-import-order instead
It seems that isort is not compatible with black at the moment: psf/black#127 PyCQA/isort#694 Both isort and black are working on a solution, but at the moment, we'll use flake8-import-order instead
It seems that isort is not compatible with black at the moment: psf/black#127 PyCQA/isort#694 Both isort and black are working on a solution, but at the moment, we'll use flake8-import-order instead
Not sure if this belongs here: The following line line is formatted differently by black and isort even though I am using the isort config Import:
Formatted by black:
Formatted by isort:
Would be nice if this gets taken care of. Personally I think the black format is the way to go as I am not a big fan of backslashes (also pep8 is not either, right?) |
@DavidS3141 you need to use |
I found the same question as @blueskyjunkie mentioned. When I attemp to format my python file in VSCode, isort and black will compete over the wihtespace before comment. |
I have encountered another scenario where they two are holding an exact opposite opinion. isort and black is conflicting on this line: the line length is 90. isort would like to format it to
after that, black would like to format it back:
these are my isort settings:
|
I have the same problem. How did you solve it? |
The conflict is due to these two lines:
and the As a solution, I have removed the The previously defined line length of |
Just now, I also solved this problem with my isort Settings:
Maybe I increased the line_length that solved the problem. |
Compatible with black (see PyCQA/isort#694)
* test: clean flake8 config root clutter * test: pre-commit: add isort Compatible with black (see PyCQA/isort#694) * lint: reorder imports * lint: more complex imports * lint: fix deepsource * config: isort: add first party dvc * tests: restyled: add isort * temp commit to revert before merge * Revert "temp commit to revert before merge" This reverts commit 11db0fd.
@timothycrosley Congratulations on the isort 5 release with profiles! https://timothycrosley.github.io/isort/docs/major_releases/introducing_isort_5/ Should the profile for Black include https://timothycrosley.github.io/isort/docs/configuration/profiles/ |
@hugovk Thanks! Good catch! Originally, profile where given the highest priority overriding any other settings - so I didn't include line_length as there would be no easy way to override it and it is configurable in black as well. However, testing showed that wasn't the best approach and now profile sit above the defaults but below custom settings. I've updated the black profile to be 88 line_length. |
This thread is a little bit confusing. As a black user, can I enable isort now or if so what do I need to do it in a way that does not conflict with black? |
@ssbarnea yes you can enable isort alongside black! isort has been compatible with black for a while (with a complex combination of settings). With the latest release isort is fully compatible with black simply by using the black profile |
Sadly using black profile does not change the default line length from 79 to 88. Also isort seems not to be able to read the value configured in flake8 config either, so I was forced to repeat configuring the line length alongside black profile. There is an open change at https://github.com/ansible/ansible-lint/pull/887/files -- note that the project does not use black but using the black profile should have not mattered, my expectation was to default to the magic 88 value :D |
It should, shouldn't it? |
I'm going to close this issue now, as there as been some misunderstanding that it means that isort isn't compatible with black. If in the future anyone notices an incompatibility please raise it as a new issue and it will have the new |
Hey, Timothy! Thanks for isort, it's a very useful project.
I made an opinionated formatter, Black. Quite a few of my users are also isort users. That's great, I don't want to have to perform import sorting in Black. However, there's a small issue.
None of isort's multiline modes fits what Black is doing. Black wraps lines like this:
The second step in Black's algorithm is like your mode 5, and the third is like mode 3. I'd like to create a pull request for isort to introduce mode 8 (5+3) that does what Black does in this scenario. This would enable Black and isort to co-exist and keep consistent import styling.
Would you accept such pull request?
(I initially wrote this on Twitter but this belongs here better.)
The text was updated successfully, but these errors were encountered: