Hey pants people, I have some issues with isort. ...
# general
r
Hey pants people, I have some issues with isort. When calling
pants fmt ::
it says the following:
Copy code
14:12:16.85 [INFO] Completed: Format with Black - black made no changes.
14:12:16.85 [INFO] Completed: Format with isort - isort made no changes.
14:12:16.85 [INFO] Completed: Format with Black - black made no changes.
14:12:16.85 [INFO] Completed: Format with Black - black made no changes.
14:12:16.85 [INFO] Completed: Format with isort - isort made no changes.

✓ black made no changes.
✓ isort made no changes.
However when I then run
pants lint ::
, isort gives me an error message (or a warning):
Copy code
14:12:22.84 [INFO] Completed: Format with Black - black made no changes.
14:12:22.85 [INFO] Completed: Format with Black - black made no changes.
14:12:22.86 [WARN] Completed: Format with isort - isort made changes.
 paths/to/files.py
 paths/to/files2.py
 paths/to/files3.py
 …
  
14:12:22.86 [INFO] Completed: Lint with Flake8 - flake8 succeeded.
Partition: ['CPython==3.10.*']


14:12:22.86 [INFO] Completed: Lint with Flake8 - flake8 succeeded.
Partition: ['CPython==3.10.*']



✓ black succeeded.
✓ flake8 succeeded.
✕ isort failed.
My `mypy.ini`:
Copy code
[mypy]
warn_return_any = False
warn_unused_configs = False
packages=package1, package2

# Sentence splitter is untyped, ignore imports
[mypy-sentence_splitter.*]
ignore_missing_imports = True

[mypy-scipy.*]
ignore_missing_imports = True
Does anyone know where this discrepancy could come from? I’d like to include
pants lint
in CI but this stops me from using it. Any help is greatly appreciated!
b
Sorry for the trouble! What version of pants? Finally, if you use,
--keep-sandboxes=on_failure
and jump into the sandbox then run the
__run.sh
, and compare the changes files, you should be able to determine exactly what the changes are, which would be helpful.
h
Ugh, this is a known issue with isort, and is very annoying, sorry. Have you seen https://www.pantsbuild.org/docs/python-linters-and-formatters#isort-possible-issues-with-its-import-classifier-algorithm ? That has some advice on how to work around this.
The issue has to do with how isort auto-classifies first-party code, which fails in some cases due to how pants creates the sandbox. I do want to fix this properly, although it's not trivial, but the workaround does seem to work for most
🫡 1
BTW you posted your mypy config but I think it's the isort config that we're talking about?