PyCQA / PyCQA/isort

`isort` ignores config files like `pyproject.toml` when explicitly passing files

Open
#1,872 11 comments 9 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question repo_needed
Dominant language
Python
Stars
7k
Forks
687
Avg merge
4h 56m
Merged PRs (30d)
2

Description

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 like pyproject.toml are ignored, i.e.,

isort <some-folder>/some_file.py

will ignore my toml file at ./pyproject.toml while

isort

will load the configuration from the toml file.

I have noticed this discrepancy while using isort with the pre-commit framework. Depending on how pre-commit is called it might actually call the tools individually on each file, e.g., when called via pre-commit run --from-ref main --to-ref HEAD. In this case isort won't load the configuration.

This is unlike most other linting/quality check tools like flake8, black, or pylint that will still load the configuration files.

And while I can still explicitly pass in the config file via

isort --sp pyproject.toml <some-folder>/some_file.py

it's still quite unintuitive and should at least be documented.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the CLI path used by isort <some-folder>/some_file.py and compare it with bare isort, focusing on configuration discovery and the documented --sp pyproject.toml workaround. Add regression coverage for loading pyproject.toml with an explicitly passed file; done means the chosen behavior is consistent and documented if needed.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.