Skip to content

Share the option spelling, the argparse index and the preset application of the CLI, the recommender, the prompt and generate() - #5566

Merged
Koudai Aono (koxudaxi) merged 1 commit into
dry-r49from
dry-r33
Oct 29, 2026
Merged

Koudai Aono (koxudaxi) merged 1 commit into
dry-r49from
dry-r33

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Improvements
    • Preset selection now applies configuration updates consistently across the command-line and programmatic workflows.
    • Option names and configuration output use consistent formatting.
    • Negative boolean options are shown only when supported by the selected option.
    • External-reference mappings receive consistent validation, with clearer handling of malformed values.

…the external-ref-mapping split between the CLI, the recommender and generate()
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between dc5126f and b953c81.

Files selected for processing: 14
  • scripts/recommender_calibrate.py
  • src/datamodel_code_generator/__init__.py
  • src/datamodel_code_generator/__main__.py
  • src/datamodel_code_generator/_api_generation.py
  • src/datamodel_code_generator/_cli_config.py
  • src/datamodel_code_generator/_option_names.py
  • src/datamodel_code_generator/_recommend/__init__.py
  • src/datamodel_code_generator/_recommend/_report.py
  • src/datamodel_code_generator/_recommend/_rules.py
  • src/datamodel_code_generator/arguments.py
  • src/datamodel_code_generator/base_config.py
  • src/datamodel_code_generator/cli_options.py
  • src/datamodel_code_generator/preset.py
  • src/datamodel_code_generator/prompt.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.

Walkthrough

The change centralizes option-name, TOML-value, external-reference mapping, and preset-resolution logic. CLI, configuration, recommendation, and API paths now use shared helpers; false boolean options are emitted only when the parser exposes the corresponding negative flag.

Changes: Shared configuration handling

Layer / File(s) Summary
Shared option and value helpers
src/datamodel_code_generator/_option_names.py, src/datamodel_code_generator/cli_options.py, src/datamodel_code_generator/_recommend/_rules.py, src/datamodel_code_generator/prompt.py, scripts/recommender_calibrate.py
Added helpers for option names, hyphenated configuration keys, TOML-style values, and external-reference mappings. Added parser-action lookup for negative boolean options. Recommendation rules and prompt formatting now use shared helpers.
Centralized preset resolution
src/datamodel_code_generator/preset.py, src/datamodel_code_generator/__init__.py, src/datamodel_code_generator/__main__.py, src/datamodel_code_generator/_api_generation.py, src/datamodel_code_generator/_recommend/*
Added a resolver that builds preset context from configuration and returns ordered updates. Configuration, API, CLI, and recommendation paths now apply those updates.
CLI and configuration integration
src/datamodel_code_generator/__main__.py, src/datamodel_code_generator/_recommend/_report.py, src/datamodel_code_generator/base_config.py, src/datamodel_code_generator/_cli_config.py, src/datamodel_code_generator/arguments.py, src/datamodel_code_generator/preset.py, src/datamodel_code_generator/_recommend/__init__.py
CLI and reporting paths now use shared option names and configuration-key conversion. External-reference mapping validators use the shared parser and preserve their existing error types.

Priority: Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: Minimal · up to b953c

The change centralizes option formatting, validation, and preset handling. No actionable merge-blocking issue was identified; merge after normal checks pass.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the shared pieces this PR centralizes: option spelling, the argparse action index, and preset application across the CLI, recommender, prompt, and generate(). The raw summary confirms …
Docstring Coverage Passed Docstring coverage is 93.55% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the shared pieces this PR centralizes: option spelling, the argparse action index, and preset application across the CLI, recommender, prompt, and generate(). The raw summary confirms these changes. New _option_names.py helpers (option_flag, hyphenated, toml_value, split_external_ref_mapping) cover option spelling. _actions_by_dest and _negative_option cover the argparse index. _resolve_config_preset covers preset application. The title is long and uses internal jargon, but it describes the main change. It does not mention the external-reference-mapping split from the commit messages, which is a secondary point.

Full details: Docstring Coverage

Explanation

Docstring coverage is 93.55% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 31 functions across 14 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T14:00:43.709500Z b953c81 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Oct 29, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 47.27%

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ Base and head ran on different runner types

Some benchmarks with significant performance changes were compared across different runner types, so the changes might not come from the code. Run base and head on the same runner type, or use CodSpeed Macro Runners for more stable results.

Learn more about Macro Runners

Open the report in CodSpeed to investigate

❌ 52 regressed benchmarks
⏩ 98 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_perf_client_calls[async] 20.3 ms 47.1 ms -56.8%
❌ test_perf_client_calls[sync] 18.6 ms 42.1 ms -55.92%
❌ test_perf_load_pyproject_config[config-multiple] 175.1 µs 388.1 µs -54.88%
❌ test_perf_graphql_style_pydantic_v2 400.2 ms 878.5 ms -54.45%
❌ test_perf_load_pyproject_config[mapping-multiple] 177.1 µs 386.9 µs -54.22%
❌ test_perf_load_pyproject_config[config-None] 170 µs 369 µs -53.92%
❌ test_perf_extreme_large_schema 8 s 16.8 s -52.55%
❌ test_perf_simple_msgspec_unset_field_rendering 253.6 ms 533.1 ms -52.42%
❌ test_perf_aws_style_openapi_pydantic_v2 1.1 s 2.2 s -52.21%
❌ test_perf_load_pyproject_config[mapping-None] 178.4 µs 373.1 µs -52.17%
❌ test_perf_unique_items_nested_model_validation 1.6 ms 3.2 ms -51.04%
❌ test_perf_inherited_required_fields[required-base-first] 300.3 ms 611.6 ms -50.91%
❌ test_perf_stripe_style_pydantic_v2 1.1 s 2.2 s -50.82%
❌ test_perf_complex_refs 1.1 s 2.2 s -50.57%
❌ test_perf_all_options_enabled 3.1 s 6.2 s -50.49%
❌ test_perf_pydantic_field_name_resolution 979.9 µs 1,978.3 µs -50.47%
❌ test_perf_kubernetes_style_pydantic_v2 1.4 s 2.8 s -50.15%
❌ test_perf_inherited_required_fields[partial-base-first] 521.4 ms 1,036.3 ms -49.69%
❌ test_perf_duplicate_names 552.8 ms 1,098.7 ms -49.69%
❌ test_perf_openapi_large 1.7 s 3.4 s -49.05%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing dry-r33 (b953c81) with dry-r49 (dc5126f)

Open in CodSpeed

Footnotes

  1. 98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@koxudaxi
Koudai Aono (koxudaxi) merged commit db5277e into main Oct 29, 2026
164 of 165 checks passed
@koxudaxi
Koudai Aono (koxudaxi) deleted the dry-r33 branch October 29, 2026 16:18
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor with no breaking changes. It adds a private helper module, _option_names, with option_flag, hyphenated, toml_value and split_external_ref_mapping. It also adds a private preset helper, _resolve_config_preset, and a ResolvedPresetConfig.updates method, then switches the duplicated call sites over to them. The only removed symbols are private or internal: _flag in base_config and in the recommend report module, toml_value and _option_strings in the private _recommend._rules module, and _negative_boolean_options in main. The prompt module's _actions_by_dest moved to cli_options and is still imported into prompt. The public resolve_preset_config_updates function, PresetContext and PresetError are unchanged. Preset application still applies the same values: the target Python version first, then preset items, then forced field constraints. The CLI and pyproject handling of --external-ref-mapping keeps the same messages and exception types (Error and ArgumentTypeError). Option spelling, including the --no- forms of boolean flags, is computed the same way. The PresetConfigItem pyproject_value result is the same for enum tuples. No CLI options, defaults, templates or supported Python versions change. The behaviour diff gate does list accepted cells, but their notes describe allOf schemas whose parts admit no object now generating root models or aliases instead of empty object models, and they point to a different PR. This diff does not touch any parser or model-generation code, so those output changes cannot come from it; the remaining cells are both-fail or crash-fix, which do not change default output.


This analysis was produced by the release draft workflow

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

🎉 Released in 0.88.0

This PR is now available in the latest release. See the release notes for details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant