Skip to content

Read the import edges of the written modules, the exports a package reaches and the module dependency graph with its failing cycles in one place each - #6155

Merged
Koudai Aono (koxudaxi) merged 3 commits into
fix7-7from
fix7-8
Nov 3, 2026
Merged

Koudai Aono (koxudaxi) merged 3 commits into
fix7-7from
fix7-8

Conversation

@koxudaxi

@koxudaxi Koudai Aono (koxudaxi) commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Improvements
    • Generated module imports now account for package initialization, re-exports, and merged modules when analyzing dependencies and circular imports.
    • Export selection now considers how far exports reach through the module hierarchy, including different handling for child scopes.
    • These changes affect how generated modules are organized and how their imports are resolved.

@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The change adds shared helpers for import targets, module dependency graphs, and failing-cycle analysis. Import discovery and module merging use these helpers. Export reach logic and architecture-boundary documentation are also updated.

Changes: Import Analysis

Layer / File(s) Summary
Export reach and import-edge derivation
src/datamodel_code_generator/parser/_init_exports.py, src/datamodel_code_generator/parser/_passes/_import_edges.py, src/datamodel_code_generator/parser/_passes/imports.py, scripts/check_architecture_boundaries.py, docs/architecture.md
exports_reach defines which depths are reached for an export scope, and collect_exports_for_init uses it. New helpers derive relative import targets, module import edges, and module dependency graphs. Import discovery uses the shared helpers. The boundary check and architecture inventory are updated.
Failing-cycle analysis and module merging
src/datamodel_code_generator/parser/_passes/_import_edges.py, src/datamodel_code_generator/parser/_passes/structure.py, docs/architecture.md
Cycle analysis accounts for package initialization and re-exports. Module merging uses the shared dependency graph and failing-cycle helper. The architecture inventory describes these helpers and their use.

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

Change: Refactor

Merge Risk: Minimal · up to 24ed6

The shared import and cycle-analysis helpers preserve the inspected behavior. No actionable merge-blocking issue remains; 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 three changes: reading import edges of written modules, naming the exports a package reaches, and building the module dependency graph with its failing cycles. The raw summary confirms…
Docstring Coverage Passed Docstring coverage is 100.00% 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. Documentat…
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 three changes: reading import edges of written modules, naming the exports a package reaches, and building the module dependency graph with its failing cycles. The raw summary confirms each: imports.py now derives loaded modules from module_import_edges, _init_exports.py adds exports_reach, and structure.py uses module_dependency_graph and _failing_import_cycles from the new _import_edges.py. The title is long (149 characters, 26 words) and lists several changes rather than one main point, but it is related to the changeset and is not vague. It is judged as a pass with a note on length.

Full details: Docstring Coverage

Explanation

Docstring coverage is 100.00% 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 12 functions across 5 files. (1 skipped: 1 unsupported.)

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

Warning

Some tools did not complete. Review the errors below.

LanguageTool
docs/architecture.md

LanguageTool checks are incomplete because the per-file request limit of 5 was reached. Remaining text was skipped; findings from completed checks are retained.

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

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 0c62ca2 and 24ed66a.

Files ignored due to path filters: 1
  • docs/llms-full.txt is excluded by none and included by none
Files selected for processing: 6
  • docs/architecture.md
  • scripts/check_architecture_boundaries.py
  • src/datamodel_code_generator/parser/_init_exports.py
  • src/datamodel_code_generator/parser/_passes/_import_edges.py
  • src/datamodel_code_generator/parser/_passes/imports.py
  • src/datamodel_code_generator/parser/_passes/structure.py

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

@koxudaxi
Koudai Aono (koxudaxi) marked this pull request as ready for review November 3, 2026 21:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 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-11-03T21:33:05.824491Z 24ed66a Draft marked ready
ℹ️ 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

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

@codspeed

codspeed Bot commented Nov 3, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 37.16%

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

⚠️ 52 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 52 improved benchmarks
⏩ 98 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
⚡ test_perf_load_pyproject_config[mapping-None] 227.6 µs 130.4 µs +74.59%
⚡ test_perf_load_pyproject_config[config-multiple] 245.3 µs 143 µs +71.5%
⚡ test_perf_load_pyproject_config[mapping-multiple] 242.2 µs 141.4 µs +71.3%
⚡ test_perf_load_pyproject_config[config-None] 226.1 µs 132.4 µs +70.74%
⚡ test_perf_pattern_properties_adapter_reuse 4.1 ms 2.6 ms +56.77%
⚡ test_perf_empty_pydantic_v2_field_render_plans 38.1 ms 26.1 ms +45.85%
⚡ test_perf_false_reference_validation 309.7 ms 214.5 ms +44.42%
⚡ test_perf_client_calls[sync] 44.4 ms 30.8 ms +44.06%
⚡ test_perf_local_reference_file_resolution 150.9 ms 104.9 ms +43.84%
⚡ test_perf_pydantic_field_name_resolution 2.7 ms 1.9 ms +41.83%
⚡ test_perf_recommend_options_full_kubernetes_style 20.5 s 14.5 s +41.62%
⚡ test_perf_large_models_pydantic_v2 4.1 s 2.9 s +40.38%
⚡ test_perf_scalar_root_collapsed_builtin 228.1 ms 163.7 ms +39.38%
⚡ test_perf_client_calls[async] 48.5 ms 35.3 ms +37.31%
⚡ test_perf_inherited_required_fields[required-derived-first] 818.9 ms 601.8 ms +36.08%
⚡ test_perf_large_models_pydantic_v2_builtin 1.5 s 1.1 s +35.74%
⚡ test_perf_all_options_enabled 6.6 s 4.8 s +35.68%
⚡ test_perf_deep_nested 6.1 s 4.5 s +35.57%
⚡ test_perf_load_yaml_openapi_large 39.9 ms 29.5 ms +35.18%
⚡ test_perf_ordinary_array_constraint_generation 2.3 s 1.7 s +35.15%
... ... ... ... ...

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

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing fix7-8 (24ed66a) with fix7-7 (0c62ca2)

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. ↩

@koxudaxi
Koudai Aono (koxudaxi) merged commit 9044a80 into main Nov 3, 2026
42 of 144 checks passed
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: No breaking changes detected

Reasoning: This PR is an internal refactor with the same behaviour as before. It moves the import-edge and import-cycle helpers (_written_package, relative_import_targets, _failing_cycles, _exported_imports, _failing_import_cycles and the module dependency graph construction) out of parser/_passes/imports.py and parser/_passes/structure.py into a new private module, parser/_passes/_import_edges.py. It also adds a private helper, exports_reach, to parser/_init_exports.py, and updates the architecture docs and the boundary-check script. I checked each moved or rewritten piece against the old code and found the logic unchanged. The new exports_reach check in collect_exports_for_init skips the same modules as the old Children-scope depth test. The rewritten _exported_imports loop picks the same package prefixes for the children and recursive scopes. The exporting set built with exported_names matches the old short_name check. _loaded_modules still gathers the same targets and adds the same written modules under all-exports-scope. _failing_import_cycles now receives the internal module paths from its caller, which computes them with the same compute_internal_module_path call. The relocated functions are private or live in underscore-prefixed modules, and relative_import_targets is still imported into imports.py, so no public Python API or CLI option is removed or changed. Nothing touches templates, defaults, error reporting or supported Python versions. The behaviour diff gate compares against the last release, so it covers more than this PR. Its accepted cells involve discriminator mappings, constraint handling, numeric precision and JSON pointers, none of which this diff touches, and none involve the opt-in all-exports-scope or the cycle merging this PR refactors. So those cells do not come from this PR.


This analysis was produced by the release draft workflow

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