Open lucaslie opened 2 years ago
This is not isort's behavior intended behavior, and would represent a bug. isort is coded and tested to behave in this way the same as all other linting / formatting tools you mention. Can you provide some more information about what you are seeing?
In particular, if you could demonstrate in a repo or docker machine exactly the behavior you are seeing in a reproducible way. The only way isort wouldn't pick up a config file, in the given examples by design, is if the settings file lives outside of either a repository that the source file is in, or does not live in a parent directory of the file (unlike the given example) which is the same behavior exhibited by these other tools.
Is there any chance you are using an older version of isort?
In my tests isort ignores pyproject.toml regardless the files being passed.
Example pyproject.toml:
[tool.poetry]
name = "isort_test"
version = "0.1.0"
description = ""
authors = ["Python Developer <developer@example.com>"]
[tool.poetry.dependencies]
python = "^3.8"
[tool.poetry.dev-dependencies]
isort = "^5.10.1"
[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
[tool.isort]
line_length = 120
profile = "black"
reverse_relative = 1
src_paths = ["."]
bash
poetry install
poetry run isort . --show-config | less # search for line_length and you will find 79
This also causes false positives, when using pre-commit:
.pre-commit-config.yaml
exclude: 'docs|node_modules|.git|.tox'
default_stages: [commit]
fail_fast: true
repos:
- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
hooks:
- id: isort
bash
pre-commit run --all-files
Hey @timothycrosley, I recently ran into this same issue. So I created this repository to reproduce the issue: https://github.com/zeshuaro/isort-exclude-demo
In the repository, file2.py
contains unsorted imports. But in pyproject.toml
, we explicitly set it for isort to ignore file2.py
. And so isort should ignore it.
If you try to run pre-commit run --all-files
(which has been configured to run isort), isort will report an error in file2.py
. This is most likely due to pre-commit directly passing the file to isort, and isort doesn't ignore the file in this case.
Black had the exact same issue, and the workarounds are listed in this comment: https://github.com/psf/black/issues/1584#issuecomment-672124752. At the end, they added a --force-exclude
argument to address the issue.
Would it be possible for isort to add the same function?
We are experiencing same issue in pre-commit
hook. Maybe this could be helpful - I believe the issue occurs just when using python>3.8
.
I get the following error when isort is run from windows commandline.
isort .
UserWarning: Failed to pull configuration information
When I add a print statement in the code \lib\site-packages\isort\settings.py it shows that it reads the info from the pyproject.toml file.
running python=3.9.12 and isort=5.10.1
my pyproject.toml file.
#
# SOME COMMENT
#
[tool.isort]
reverse_relative = 1
src_paths = ["."]
verbose = true
multi_line_output = 3
include_trailing_comma = true
force_grid_wrap = 0
use_parentheses = true
ensure_newline_before_comments = true
lines_after_imports = 2
git_ignore = true
comment_prefix = '# isort|'
force_single_line = true
[tool.black]
[tool.interrogate]
# https://interrogate.readthedocs.io/en/latest/#configuration
verbose = 2
exclude = ['docs','build','history']
I have the same issue. So I tried to create a .isort.cfg file to see whether it would use its own format. And It sure did.
I experienced the same error while dealing with pre-commit
and isort configuration in pyproject.toml
I am running into the same issue :(
Some one from the maintainers should remove the https://github.com/PyCQA/isort/labels/repo_needed label. @zeshuaro provided a reproducer.
I noticed that
isort
ignores config files as soon as any arguments are passed in on the command line.Is this really the desired behavior? Especially when
isort
is called on a specific file only it is very counterintuitive that config files likepyproject.toml
are ignored, i.e.,will ignore my toml file at
./pyproject.toml
whilewill load the configuration from the toml file.
I have noticed this discrepancy while using
isort
with thepre-commit
framework. Depending on howpre-commit
is called it might actually call the tools individually on each file, e.g., when called viapre-commit run --from-ref main --to-ref HEAD
. In this caseisort
won't load the configuration.This is unlike most other linting/quality check tools like
flake8
,black
, orpylint
that will still load the configuration files.And while I can still explicitly pass in the config file via
it's still quite unintuitive and should at least be documented.