Skip to content

Add extension_or_* parser modes that load config files based on their extension - #1021

Merged
mauvilsa merged 2 commits into
mainfrom
extension-or-parser-modes
Oct 20, 2026
Merged

mauvilsa merged 2 commits into
mainfrom
extension-or-parser-modes

Conversation

@mauvilsa

Copy link
Copy Markdown
Owner

What does this PR do?

Adds extension_or_* parser modes, e.g. parser_mode="extension_or_yaml", so that a single parser can load config files of different formats. Each config file is loaded in the format given by its extension (.json, .yaml/.yml, .toml, .jsonnet/.libsonnet), while files with unknown extensions, values given on the command line or via environment variables, and dumping use the mode after the prefix. If the base mode can already load the detected format, it is kept, e.g. extension_or_omegaconf still uses omegaconf for YAML files and extension_or_yaml for JSON files.

This applies to all ways config files are loaded: --config arguments, default config files, __include__ (so a JSON config can include a TOML one) and sub-config paths for typed arguments. Provenance line numbers are shown according to each file's detected format.

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 20, 2026
@mauvilsa
mauvilsa deployed to sonarcloud October 20, 2026 05:13 — with GitHub Actions Active
@codecov

codecov Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1021   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         9857      9886   +29     
=========================================
+ Hits          9857      9886   +29     

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

@greptile-apps

greptile-apps Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The new behavior reaches config parsing across the parser's supported file-loading paths.

The PR appears safe to merge, with a non-blocking fix needed for format detection on URLs with query strings.

Findings

  1. P2 URL queries hide file extensions ▶

Summary

Adds extension_or_* modes that choose a config loader from each file's extension.

  • Config files can use the format named by their file extension.
  • Source notes show line numbers using each config file's format.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Config file] --> B{Extension-based mode?}
  B -->|No| C[Use configured mode]
  B -->|Yes| D{Recognized extension?}
  D -->|No| E[Use base mode]
  D -->|Yes| F{Base mode supports format?}
  F -->|Yes| E
  F -->|No| G[Use detected mode]
  C --> H[Load content]
  E --> H
  G --> H
  H --> I[Resolve includes]
  I --> A
Loading

Reviews (1) · Last reviewed commit: "Add extension_or_* parser modes that loa..." · Reviewed by Greptile

Comment thread jsonargparse/_loaders_dumpers.py Resolved
@mauvilsa
mauvilsa deployed to sonarcloud October 20, 2026 05:40 — with GitHub Actions Active
@sonarqubecloud

Copy link
Copy Markdown

@mauvilsa
mauvilsa merged commit cdea83a into main Oct 20, 2026
35 checks passed
@mauvilsa
mauvilsa deleted the extension-or-parser-modes branch October 20, 2026 05:42

This branch was successfully deployed

1 active deployment
sonarcloud — 47f358a9 Deployed Oct 20, 2026 by mauvilsa via sonarcloud #992
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