feat: Add --enable-command-header option to include command-line in file headers#2684
feat: Add --enable-command-header option to include command-line in file headers#2684
Conversation
…tails in file headers for reproducibility and testing
|
Warning Rate limit exceeded@koxudaxi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 47 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
WalkthroughThis PR introduces a new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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. Comment |
🤖 Generated by GitHub Actions
CodSpeed Performance ReportMerging #2684 will not alter performanceComparing Summary
Footnotes
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2684 +/- ##
=======================================
Coverage 99.53% 99.53%
=======================================
Files 81 81
Lines 11322 11334 +12
Branches 1353 1354 +1
=======================================
+ Hits 11269 11281 +12
Misses 32 32
Partials 21 21
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
docs/cli-reference/template-customization.md (1)
1290-1296: Consider adding a security note about sensitive data.The documentation clearly explains the feature's purpose for reproducibility. However, consider adding a brief note warning users that command-line arguments may contain sensitive information (API keys, passwords, file paths with usernames, etc.) that will be embedded in generated files.
📝 Suggested addition
Add a note or warning box after line 1296:
!!! warning "Sensitive Data" Be cautious when using this option if your command-line includes sensitive information such as API keys, passwords, or personal file paths. This data will be embedded in the generated file headers.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (9)
docs/cli-reference/index.md(2 hunks)docs/cli-reference/quick-reference.md(2 hunks)docs/cli-reference/template-customization.md(2 hunks)src/datamodel_code_generator/__init__.py(2 hunks)src/datamodel_code_generator/__main__.py(5 hunks)src/datamodel_code_generator/arguments.py(1 hunks)src/datamodel_code_generator/cli_options.py(1 hunks)tests/data/expected/main/openapi/enable_command_header.py(1 hunks)tests/main/openapi/test_main_openapi.py(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/data/expected/main/openapi/enable_command_header.py (3)
tests/data/expected/parser/openapi/openapi_parser_parse_modular/bar.py (1)
Field(6-7)src/datamodel_code_generator/model/base.py (1)
name(599-601)src/datamodel_code_generator/__init__.py (1)
Error(303-312)
tests/main/openapi/test_main_openapi.py (1)
tests/main/conftest.py (2)
output_file(94-96)run_main_and_assert(196-352)
🪛 LanguageTool
docs/cli-reference/quick-reference.md
[grammar] ~191-~191: Ensure spelling is correct
Context: ...command-line options in file header for reproducibil... - [--enable-faux-immutability](mod...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: 3.10 on Windows
- GitHub Check: py312-isort5 on Ubuntu
- GitHub Check: py312-pydantic1 on Ubuntu
- GitHub Check: 3.11 on Windows
- GitHub Check: 3.9 on Windows
- GitHub Check: 3.11 on Ubuntu
- GitHub Check: 3.13 on Windows
- GitHub Check: 3.13 on macOS
- GitHub Check: 3.12 on Windows
- GitHub Check: 3.14 on Windows
- GitHub Check: benchmarks
- GitHub Check: Analyze (python)
🔇 Additional comments (15)
tests/data/expected/main/openapi/enable_command_header.py (1)
1-70: LGTM! Test fixture follows expected pattern.The test fixture correctly demonstrates the new command header format at line 4. The
[COMMAND]placeholder indicates that tests normalize the actual command-line for reproducibility, which is a good practice.docs/cli-reference/index.md (2)
15-15: LGTM! Option count updated correctly.The Template Customization category now correctly shows 16 options after adding
--enable-command-header.
63-63: LGTM! New option added to alphabetical index.The new
--enable-command-headeroption is correctly placed in alphabetical order with proper linking.docs/cli-reference/template-customization.md (1)
1290-1563: LGTM! Comprehensive documentation added.The documentation section follows the established pattern with clear usage examples, input schema, and output demonstration. The feature's purpose for reproducibility is well-explained.
docs/cli-reference/quick-reference.md (1)
114-114: LGTM! Quick reference updated consistently.The new option is correctly added to both the categorized table and alphabetical index with consistent descriptions.
Note: The static analysis grammar hint at line 191 is a false positive—the description is intentionally truncated with "..." to fit the table format.
Also applies to: 191-191
src/datamodel_code_generator/cli_options.py (1)
175-175: LGTM! CLI option metadata correctly defined.The metadata entry is properly configured with the appropriate category and follows the established pattern.
src/datamodel_code_generator/__init__.py (1)
392-393: LGTM! New parameters follow existing patterns.The new
enable_command_headerandcommand_lineparameters are correctly typed and positioned alongside related header configuration options likeenable_version_header.src/datamodel_code_generator/arguments.py (1)
201-206: LGTM! CLI argument correctly defined.The new argument follows the established pattern used by similar header-related options (
--enable-version-header,--disable-timestamp) with appropriate action, default, and help text.tests/main/openapi/test_main_openapi.py (2)
8-8: LGTM: Import added to support test normalization.The
remodule import is correctly placed and necessary for the regex pattern matching in the newtest_enable_command_headertest function.
917-943: LGTM: Well-structured test with appropriate normalization.The test properly validates the
--enable-command-headerfeature:
- Follows the established testing pattern in this file
- Uses a
normalize_commandtransform to mask the actual command line with a placeholder, ensuring stable test outputs despite dynamic file paths- The regex substitution approach is cleaner than attempting to mock the command construction
- Includes proper
@pytest.mark.cli_docmetadata for documentation generationsrc/datamodel_code_generator/__main__.py (5)
7-7: LGTM: Appropriate import for command-line construction.The
shlexmodule import is correctly added to supportshlex.join()on line 954, which properly quotes command-line arguments containing spaces or special characters.
389-389: LGTM: Config field properly added.The new
enable_command_headerboolean field is appropriately positioned in the Config class and defaults toFalse, ensuring backward compatibility as an opt-in feature.
667-667: LGTM: Function signature appropriately extended.The addition of the
command_line: str | Noneparameter properly threads the command-line string through the call chain. The nullable type is appropriate for when the feature is disabled.
689-690: LGTM: Parameters correctly forwarded to generate().The
enable_command_headerandcommand_lineparameters are properly passed through to thegenerate()function call, completing the threading of this feature through the call chain.
954-954: LGTM: Command-line construction correctly implemented.The conditional construction of
command_lineusingshlex.join()is appropriate:
- Only builds the command string when
enable_command_headeris True- Uses
shlex.join()to properly quote arguments containing spaces or special characters- Correctly reconstructs the full command by prefixing "datamodel-codegen"
- The
argsvariable is guaranteed to be a sequence of strings at this point
Summary by CodeRabbit
Release Notes
New Features
--enable-command-headerCLI option to include command-line options in generated file headers for reproducibility.Documentation
--enable-command-headeroption and usage examples.✏️ Tip: You can customize this high-level summary in your review settings.