Having trouble getting black config file to take e...
# general
l
Having trouble getting black config file to take effect when using Pants. Running black directly using the config file correctly excludes paths, but using Pants doesn't.
1
1
My pyproject.toml file (located at repo root) is as follows:
Copy code
[tool.black]
line-length = 100
target-version = ['py37']
# exclude autogenerated Protocol Buffer files anywhere in the project
extend-exclude = '.*' # exclude all for debugging

[tool.isort]
extend_skip_glob = [
    # exclude autogenerated Protocol Buffer files anywhere in the project
    "**/*_pb2.py",
    "**/*_pb2.pyi",
    "**/*_pb2_grpc.py",
    "**/*_pb2_grpc.pyi"
]
And for pants.toml (relevantly)
Copy code
[source]
root_patterns = [
  "/e2e_testing"
]

[tailor]
build_file_name = "BUILD.pants"

[python]
enable_resolves = true
default_resolve = "default_resolve"
interpreter_constraints = ["==3.11.*"]

[python.resolves]
default_resolve = "pants/pythondeps.lock"

[pytest]
install_from_resolve = "default_resolve"

[black]
config = "pyproject.toml"

[isort]
config = ["pyproject.toml"]
Oh I see, this is actually just due to this nuance of how black's excludes work.
This has fixed black, but somehow isort has this issue.
Copy code
❯ isort --settings-path=pants/pyproject.toml  e2e_testing/**
Skipped 180 files
❯ pants fmt --only=isort e2e_testing::
// many files
+ isort made changes.
pants.toml
Copy code
[source]
root_patterns = [
  "/e2e_testing"
]

[tailor]
build_file_name = "BUILD.pants"

[python]
enable_resolves = true
default_resolve = "default_resolve"
interpreter_constraints = ["==3.11.*"]

[python.resolves]
default_resolve = "pants/pythondeps.lock"

[pytest]
install_from_resolve = "default_resolve"

[black]
install_from_resolve = "default_resolve"
config = "pants/pyproject.toml"

[isort]
install_from_resolve = "default_resolve"
config = ["pants/pyproject.toml"]
pyproject.toml
Copy code
[tool.black]
line-length = 100
target-version = ['py37']
# exclude autogenerated Protocol Buffer files anywhere in the project
force-exclude = '''
^(
  .*_pb2(_grpc)?\.py(i)?  # exclude autogenerated Protocol Buffer files anywhere in the project
)$
'''

[tool.isort]
profile = "black"
line_length = 100
extend_skip_glob = [
    # exclude autogenerated Protocol Buffer files anywhere in the project
    "**/*_pb2.py",
    "**/*_pb2.pyi",
    "**/*_pb2_grpc.py",
    "**/*_pb2_grpc.pyi"
]
System isort version is 5.12.0
And so is pants isort version
l
It doesn't seem related. It's a question of whether isort should target a file at all, not how it sorts the imports on modified files. We don't have a common org name to use for sorting imports anyway.
Even after adding those lines pants isort does modify those files, whereas system isort doesn't
Ah but this seems to have fixed it.
filter_files = true
as well as
skip_glob
vs
extend_skip_glob
makes the difference here
Might be worth documenting this somewhere in the Pants docs. I imagine this is a common use case for dealing with generated files.
h
The docs are generated from sources in the repo, so feel free to send a PR!
⛹️ 1
l