-
Notifications
You must be signed in to change notification settings - Fork 4
feat(sanity): add --fix option #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
83593cc to
ca5df65
Compare
2c9efa0 to
3f28a79
Compare
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
3f28a79 to
1d633a7
Compare
| severity: Severity | ||
|
|
||
| def __call__(self, context: SanityContext) -> Report: | ||
| def __call__(self, context: SanityContext, fix: bool = False) -> Report: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) It would be nice to have a short doc comment that stresses that if the check succeeded (has no reasons), no fixes will be applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch, I added docstring for the behavior in 6e3b1ec.
t4_devkit/sanity/result.py
Outdated
| if not self.is_passed(strict=strict): | ||
| parts.append(f"\033[31m {self.id}:\033[0m\n") | ||
| # print failure reasons | ||
| color = self.PALETTE["RED"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) Rename color, color1 etc. to their color, e.g. ansi_red or color_red or red
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified color code by using colorama in 8c77fb5.
t4_devkit/sanity/result.py
Outdated
| # print failure or warning but fixed reasons | ||
| color1 = self.PALETTE["YELLOW"] if self.severity.is_warning() else self.PALETTE["RED"] | ||
| color2 = self.PALETTE["GREEN"] | ||
| parts.append(f"{color1} {self.id}:\033[0m {color2}--> FIXED🎉\033[0m\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
Tested with a few corrupted |
SamratThapa120
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks.
shekharhimanshu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 💯
Thank you
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>


What
This pull request introduces a new
--fixoption to thet4sanityCLI tool, enabling automatic fixing of issues detected by sanity checks. It updates the CLI, core checker logic, reporting, and documentation to support and clearly present this new feature. Additionally, it improves the exclusion and reporting of checks.The following diagram shows the logic of checkers:
flowchart LR Start --> A{Can skip?} A --> |Yes| B[Skip check and <br/>returns skipped report] A --> |No| C[Perform check] C --> D{Failed and --fix=True?} D --> |Yes| E[Fix issues] E --> F[Return report] D --> |No| FMajor new feature: Automatic fixing of issues
--fixoption to the CLI, allowing users to attempt to automatically fix issues found during sanity checks. [1] [2] [3]Checkerinterface and all checker calls to support afixparameter, and adds afix()method for implementing fix logic in each checker. [1] [2]Reportdataclass and summary output to include a "Fixed" column. [1] [2] [3] [4] [5]Documentation improvements
--fixoption and provide usage examples.--excludeoption with clearer examples for excluding rules or groups.Tests
I checked this feature with sample data
tests/sample/t4datasetby edittingcategory.json.Before running
t4sanity tests/sample/t4dataset --fix:[ { "token": "1c22a023c1a214447d0bc497088c9a3d", "name": "car", "description": "Vehicle designed primarily for passenger transportation", "index": null }, { "token": "4db2cce0862dbdf1385186fd604d477a", "name": "pedestrian", "description": "Person walking or standing", "index": 1 }, { "token": "0531921ca79d7ca8c3815a77122de529", "name": "bicycle", "description": "Two-wheeled vehicle propelled by pedaling", "index": 2 }, { "token": "bdb3ce20fb731507f2ecf9387071335f", "name": "traffic_cone", "description": "Cone-shaped marker used to redirect traffic", "index": 3 } ]After running:
[ { "token": "1c22a023c1a214447d0bc497088c9a3d", "name": "car", "description": "Vehicle designed primarily for passenger transportation", "index": 0 }, { "token": "4db2cce0862dbdf1385186fd604d477a", "name": "pedestrian", "description": "Person walking or standing", "index": 1 }, { "token": "0531921ca79d7ca8c3815a77122de529", "name": "bicycle", "description": "Two-wheeled vehicle propelled by pedaling", "index": 2 }, { "token": "bdb3ce20fb731507f2ecf9387071335f", "name": "traffic_cone", "description": "Cone-shaped marker used to redirect traffic", "index": 3 } ]The dumped report would be like:
[ { "id": "REC007", "name": "category-indices-consistent", "severity": "ERROR", "description": "All categories must either have a unique 'index' or all have a 'null' index.", "status": "FAILED", "reasons": [ "All categories either must have an 'index' set or all have a 'null' index." ], "fixed": true } ]