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

Not compatible with Black #1963

Closed
zheyuanWang opened this issue Aug 17, 2022 · 9 comments
Closed

Not compatible with Black #1963

zheyuanWang opened this issue Aug 17, 2022 · 9 comments

Comments

@zheyuanWang
Copy link

According to official link,
I am using the following pre-commit-config:

repos:
  - repo: https://github.com/PyCQA/isort
    rev: 5.10.1
    hooks:
      - id: isort
        args: ["--profile", "black", "--filter-files"]
  - repo: https://github.com/psf/black
    rev: 22.6.0
    hooks:
    -   id: black

However, for this file, isort's output is

from ..builder import (DETECTORS, build_backbone, build_head, build_map_to_bev,
                       build_neck, build_segmentor, build_voxel_encoder,)

while Black's output is:

from ..builder import (
    DETECTORS,
    build_backbone,
    build_head,
    build_map_to_bev,
    build_neck,
    build_segmentor,
    build_voxel_encoder,
)

Different output, so the pre-commit check would never pass.

@RickLucassen
Copy link

Hey, would like to point out that the following fixes this for me: #1876
Adding the "split_on_trailing_comma" configuration solves this, since this has not been released yet it means you would have to install isort from github.

@asears
Copy link

asears commented Sep 27, 2022

Another option, can use the isort skip, off/on action comments, if you prefer black. Or # fmt: off / # fmt: on if you prefer isort.

https://pycqa.github.io/isort/docs/configuration/action_comments.html

image

@andersk
Copy link
Contributor

andersk commented Dec 12, 2022

You must not be invoking isort correctly. With your .pre-commit-config.yaml I get

$ cat test.py
from ..builder import (DETECTORS, build_backbone, build_head, build_map_to_bev,
                       build_neck, build_segmentor, build_voxel_encoder,)

$ pre-commit run --all
isort....................................................................Failed
- hook id: isort
- files were modified by this hook

Fixing /tmp/test/test.py

black....................................................................Passed

$ cat test.py
from ..builder import (
    DETECTORS,
    build_backbone,
    build_head,
    build_map_to_bev,
    build_neck,
    build_segmentor,
    build_voxel_encoder,
)

as expected.

If you’d also like to be able to invoke isort test.py directly (not via pre-commit), then you need to configure it in .isort.cfg or pyproject.toml (documentation) rather than .pre-commit-config.yaml.

@staticdev
Copy link
Collaborator

@zheyuanWang should be fixed in 5.11.0, can you check?

@zheyuanWang
Copy link
Author

@zheyuanWang should be fixed in 5.11.0, can you check?

Yes it worked!

changing the version of isort solved conflicts.

repos:
  - repo: https://github.com/PyCQA/isort
    rev: 5.11.0
    hooks:
      - id: isort
        args: ["--profile", "black", "--filter-files"]
  - repo: https://github.com/psf/black
    rev: 22.6.0
    hooks:
    -   id: black

@zheyuanWang
Copy link
Author

well, same problem reoccured for isort 5.12.0

@zheyuanWang zheyuanWang reopened this Jan 29, 2023
@zheyuanWang
Copy link
Author

zheyuanWang commented Jan 29, 2023

well, same problem reoccured for isort 5.12.0

args: ['--profile=black'] alone does not work, you need to use both args:

args: ['--profile=black', '--filter-files']

@timothycrosley
Copy link
Member

@zheyuanWang, what's the problem exactly? The first looks like a line length mismatch, the second (needing both args) is not an incompatibility with black just a specific to how pre-commit works

@zheyuanWang
Copy link
Author

sorry, false alarm;

5.12.0 is still compatible with Black.

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

No branches or pull requests

6 participants