Skip to content

Apply command line options with --resolve-all-configs - #2769

Open
nk-batman21 wants to merge 2 commits into
PyCQA:mainfrom
nk-batman21:resolve-all-configs-cli-options
Open

nk-batman21 wants to merge 2 commits into
PyCQA:mainfrom
nk-batman21:resolve-all-configs-cli-options

Conversation

@nk-batman21

Copy link
Copy Markdown
Contributor

With --resolve-all-configs, each file's config is built only from its nearest config file, so options given on the command line are dropped (--check and --diff still work because main() handles them itself). Files without a config file get plain defaults. This is easy to hit in a monorepo with per-project config files and shared pre-commit args such as ["--resolve-all-configs", "--profile=black"]: the profile is silently ignored.

For example, with pkg/pyproject.toml containing [tool.isort] / line_length = 100 and pkg/a.py containing from os import path, sep, isort --force-single-line-imports pkg/a.py splits the import, but isort --force-single-line-imports --resolve-all-configs pkg/a.py leaves it on one line. --profile, --line-length and --verbose are ignored the same way (the missing verbose output is the first question in #2045).

This passes the command line options to find_all_configs, which applies them on top of every config file it finds and on the default used for files without one. It follows #2119 by hotpxl and adds the test that was asked for there. Unlike #2119, settings_path and settings_file are not passed on: settings_path defaults to the first file's directory, so passing it would load that project's config for files in every other project. The new test covers that case too.

Refs #2045 (the src_paths part of that issue is separate).

Ran: coverage run -m pytest tests/unit/ (the new test fails without the change) and the tox -e lint commands.

@codecov

codecov Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.39%. Comparing base (03f632c) to head (b4acb02).
⚠️ Report is 42 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2769   +/-   ##
=======================================
  Coverage   99.38%   99.39%           
=======================================
  Files          40       40           
  Lines        3275     3319   +44     
  Branches      707      716    +9     
=======================================
+ Hits         3255     3299   +44     
  Misses         12       12           
  Partials        8        8           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread isort/main.py Outdated
Comment on lines +1072 to +1076
config_overrides = {
key: value
for key, value in config_dict.items()
if key not in ("settings_path", "settings_file")
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do this exclusion in find_all_configs itself. We can add a small sentence in the docstring that says these will be ignored.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @DanielNoord, done in b4acb02. find_all_configs now drops settings_path and settings_file from the overrides itself, and the docstring says they are ignored. main passes the CLI options through unchanged, and a new test in test_settings.py calls find_all_configs with both keys.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approved

No active review issues are reported for the changes propagating command-line overrides across project configurations.

No open issues 🎉

What changed in this PR

Fixes command-line option handling with --resolve-all-configs, so overrides apply across per-project configurations and to files without a configuration file.

Changes:

  • Pass command-line overrides into configuration discovery and merge them with each discovered configuration.
  • Exclude settings_path and settings_file overrides to preserve per-project configuration selection.
  • Add regression tests for override propagation, default behavior, and configuration isolation.
File Description
tests/​unit/​test_settings.py Tests override merging and exclusion of configuration-location options.
tests/​unit/​test_main.py Tests command-line options across multiple projects and an unconfigured file.
isort/​settings.py Applies overrides to discovered configurations and fallback defaults.
isort/​main.py Passes command-line options to find_all_configs.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants