From 20944295c4e662602593952ed0b546edc86202d8 Mon Sep 17 00:00:00 2001 From: Jianquan Ye Date: Fri, 5 Jul 2024 19:30:08 +1000 Subject: [PATCH] [pre-commit]Refine the output of conditional mark order check (#13544) Description of PR Summary: Refine the output of conditional_mark order check. Print more detailed information so that contributors know where to modify. Before enhance, only tell there's mis-order, but not how to modify. check conditional mark sort..............................................Failed - hook id: check-conditional-mark-sort - exit code: 1 The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml are not sorted in alphabetic order. After enhance: check conditional mark sort..............................................Failed - hook id: check-conditional-mark-sort - exit code: 1 The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml are not sorted in alphabetic order. The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml are not sorted in alphabetic order, please adjust the order before commit =========================================================================== File: tests\common\plugins\conditional_mark\tests_mark_conditions_skip_traffic_test.yaml =========================================================================== Conditional marks before sort: ['acl/custom_acl_table/test_custom_acl_table.py', 'acl/null_route/test_null_route_helper.py', 'acl/test_acl.py', 'acl/test_acl_outer_vlan.py', 'acl/test_stress_acl.py', 'arp/test_stress_arp.py', 'arp/test_unknown_mac.py', 'arp/test_wr_arp.py', 'decap/test_decap.py', 'ecmp/inner_hashing/test_inner_hashing.py', 'ecmp/inner_hashing/test_inner_hashing_lag.py', 'ecmp/inner_hashing/test_inner_hashing.py:1', 'ecmp/inner_hashing/test_wr_inner_hashing.py', 'ecmp/inner_hashing/test_wr_inner_hashing_lag.py', 'everflow/test_everflow_ipv6.py', 'everflow/test_everflow_per_interface.py', 'everflow/test_everflow_testbed.py'] Conditional marks after sort: ['acl/custom_acl_table/test_custom_acl_table.py', 'acl/null_route/test_null_route_helper.py', 'acl/test_acl.py', 'acl/test_acl_outer_vlan.py', 'acl/test_stress_acl.py', 'arp/test_stress_arp.py', 'arp/test_unknown_mac.py', 'arp/test_wr_arp.py', 'decap/test_decap.py', 'ecmp/inner_hashing/test_inner_hashing.py', 'ecmp/inner_hashing/test_inner_hashing.py:1', 'ecmp/inner_hashing/test_inner_hashing_lag.py', 'ecmp/inner_hashing/test_wr_inner_hashing.py', 'ecmp/inner_hashing/test_wr_inner_hashing_lag.py', 'everflow/test_everflow_ipv6.py', 'everflow/test_everflow_per_interface.py', 'everflow/test_everflow_testbed.py'] =========================================================================== Mismatch item, before sort: ecmp/inner_hashing/test_inner_hashing_lag.py, after sort: ecmp/inner_hashing/test_inner_hashing.py:1 =========================================================================== Process finished with exit code 1 Approach What is the motivation for this PR? Refine the output of conditional_mark order check. Print more detailed information so that contributors know where to modify. How did you do it? Print detailed mis-order item How did you verify/test it? Local test co-authorized by: jianquanye@microsoft.com --- .../check_conditional_mark_sort.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.hooks/pre_commit_hooks/check_conditional_mark_sort.py b/.hooks/pre_commit_hooks/check_conditional_mark_sort.py index fac50d255f1..2c1f480b726 100755 --- a/.hooks/pre_commit_hooks/check_conditional_mark_sort.py +++ b/.hooks/pre_commit_hooks/check_conditional_mark_sort.py @@ -4,7 +4,6 @@ def main(): stage_files = sys.argv[1:] - retval = 0 for stage_file in stage_files: if "tests_mark_conditions" in stage_file: conditions = [] @@ -17,11 +16,21 @@ def main(): conditions.append(line.strip().rstrip(":")) sorted_conditions = conditions[:] sorted_conditions.sort() - if conditions != sorted_conditions: - print("The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml " - "are not sorted in alphabetic order.") - retval = 1 - return retval + for i in range(len(conditions)): + if conditions[i] != sorted_conditions[i]: + print("The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml " + "are not sorted in alphabetic order, please adjust the order before commit") + print("===========================================================================") + print("File: {}".format(stage_file)) + print("===========================================================================") + print("Conditional marks before sort: {}".format(conditions)) + print("Conditional marks after sort: {}".format(sorted_conditions)) + print("===========================================================================") + print("Mismatch item, before sort: {}, after sort: {}".format(conditions[i], + sorted_conditions[i])) + print("===========================================================================") + return 1 + return 0 if __name__ == "__main__":