Skip to content

Add #key.path selector to config file paths, e.g. pyproject.toml#tool.myapp - #1022

Merged
mauvilsa merged 2 commits into
mainfrom
config-path-key-selector
Oct 21, 2026
Merged

mauvilsa merged 2 commits into
mainfrom
config-path-key-selector

Conversation

@mauvilsa

Copy link
Copy Markdown
Owner

What does this PR do?

Config file paths can now end in # followed by a dot separated key, e.g. pyproject.toml#tool.myapp or package.json#myapp, so that only that part of the file gets parsed. This is useful for config files shared with other tools. The selector works in default_config_files, with the config argument (--config) and with ArgumentParser.parse_path.

  • If a default config file doesn't have the selected key, it is skipped, and a debug log says why. For an explicitly given path a missing key is an error. A key whose value is not a mapping is also an error.
  • The path is split only at the last #, and only when the full value is not a path to an existing file but the part before the # is. Files with # in their name keep working as before.
  • The selector is kept wherever the config path is shown: the paths stored in the config argument value and in __default_config__, error messages and value provenance. Line numbers in provenance are still found for values inside the selected key.

Combined with the extension_or_* parser modes from #1021, an app can read both pyproject.toml and its own YAML file, e.g. default_config_files=['pyproject.toml#tool.myapp', '.myapp.yaml'].

Before submitting

  • Did you read the contributing guideline?
  • If you used a coding agent, did you fully understand and validate all generated code and ensure it follows the contributing guidelines?
  • Did you update the documentation? (readme and public docstrings)
  • Did you write unit tests such that there is 100% coverage on related code? (required for bug fixes and new features)
  • Did you verify that new and existing tests pass locally?
  • [n/a] If this is a bug fix, did you verify that the tests fail without the code fix?
  • Did you make sure that all changes preserve backward compatibility?
  • Did you update the CHANGELOG including a pull request link? (not for typos, docs, test updates, or minor internal changes/refactors)

@mauvilsa mauvilsa added the enhancement New feature or request label Oct 21, 2026
@mauvilsa
mauvilsa deployed to sonarcloud October 21, 2026 04:16 — with GitHub Actions Active
@codecov

codecov Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (cdea83a) to head (dae97c2).
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1022   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         9886      9926   +40     
=========================================
+ Hits          9886      9926   +40     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

@greptile-apps

greptile-apps Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects config loading across the library's explicit and default config workflows.

Fix the false loop error for different sections of the same file before merging.

Findings

  1. P1 Different sections trigger a loop ▶

Summary

Adds #key.path selectors to default config files, config arguments, and parse_path.

  • Config paths can load one named section from a shared file.
  • Default config files can select a section and skip files that lack it.
  • Value sources keep the selected section and its line numbers.

The author, mauvilsa, explicitly preserves existing hash-containing filenames ahead of selector parsing.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["parse_path: shared.json#app"] --> B["Mark shared.json as loading"]
    B --> C["Select app"]
    C --> D["config: shared.json#base"]
    D --> E["parse_path: shared.json#base"]
    E --> F["Check shared.json again"]
    F --> G["Reject as a loop despite different selectors"]
Loading

Reviews (1) · Last reviewed commit: "Add #key.path selector to config file pa..." · Reviewed by Greptile

Comment thread jsonargparse/_core.py
@mauvilsa
mauvilsa deployed to sonarcloud October 21, 2026 05:16 — with GitHub Actions Active
@sonarqubecloud

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit 54186cc into main Oct 21, 2026
35 checks passed
@mauvilsa
mauvilsa deleted the config-path-key-selector branch October 21, 2026 05:30

This branch was successfully deployed

1 active deployment
sonarcloud — dae97c2f Deployed Oct 21, 2026 by mauvilsa via sonarcloud #995
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant