Having a weird issue today where pants appears to ...
# general
d
Having a weird issue today where pants appears to be not respecting certain
isort
options set in
pyproject.toml
or
.isort.cfg
I’ve got an
__init__.py
where I don’t want imports to be sorted
Copy code
➜  example-python git:(main) cat example/__init__.py
from .c import thing  # t = 3
from .b import thing  # t = 2
from .a import thing  # t = 1
I have
extend_skip_glob
set in my
.isort.cfg
Copy code
➜  example-python git:(main) ✗ cat .isort.cfg
[settings]
# This is to make isort compatible with Black. See
# <https://black.readthedocs.io/en/stable/the_black_code_style.html#how-black-wraps-lines>.
line_length=88
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
extend_skip_glob=**/__init__.py
The isort binary I have on my path respects this
Copy code
➜  example-python git:(main) isort example
Skipped 1 files
➜  example-python git:(main) cat example/__init__.py
from .c import thing  # t = 3
from .b import thing  # t = 2
from .a import thing  # t = 1
Copy code
➜  example-python git:(main) ✗ isort --show-config | jq .extend_skip_glob
[
  "**/__init__.py"
]
But running
isort
via pants doesn’t
Copy code
➜  example-python git:(main) ./pants fmt --only=isort example::
17:38:04.58 [WARN] Completed: Format with isort - isort made changes.
  example/__init__.py

+ isort made changes.
➜  example-python git:(main) ✗ cat example/__init__.py
from .a import thing  # t = 1
from .b import thing  # t = 2
from .c import thing  # t = 3
Also isn’t respected
Copy code
./pants fmt --only=isort --isort-args="['--extend-skip-glob=**/__init__.py']"
Any ideas how I can get this to work?
1
r
Where are these config files stored? I have a pyproject.toml right next to pants script
d
these are in the repository root, next to the
pants.toml
. I’ve tried the equivalent in
pyproject.toml
and ran into the same issues.
r
d
When I run the
isort
binary, it’s skipping the
__init__.py
(as intended), which is different behaviour from invoking
pants fmt ::
Copy code
➜  example-python git:(main) isort example
Skipped 1 files
➜  example-python git:(main) cat example/__init__.py
from .c import thing  # t = 3
from .b import thing  # t = 2
from .a import thing  # t = 1
(imports remain untouched / same order)
😞 1
r
This works based on what I read here https://github.com/PyCQA/isort/issues/1632
Copy code
# pyproject.toml
[tool.isort]
extend_skip = ["__init__.py"]

# pants.toml
[isort]
args = ["--filter-files"]
d
Aha, it’s the
--filter-files
here that I was missing, probably because pants was explicitly passing every file to
isort
. Thank you
👍 1