forked from saiilla/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conditional mark sort check to pre-commit hook
What is the motivation for this PR? In conditional mark, testcases should be sorted from A to Z, and there is no support to check it in PR test. How did you do it? Add conditional mark sort check to pre-commit hook, if testcases are not sorted, pre-commit will fail, need to fix it before PR get merged.
- Loading branch information
1 parent
502afe7
commit c219273
Showing
10 changed files
with
95 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import re | ||
import sys | ||
|
||
|
||
def main(): | ||
stage_files = sys.argv[1:] | ||
retval = 0 | ||
for stage_file in stage_files: | ||
if "tests_mark_conditions" in stage_file: | ||
conditions = [] | ||
with open(stage_file, 'r') as f: | ||
file_contents = f.readlines() | ||
if not file_contents: | ||
continue | ||
for line in file_contents: | ||
if re.match('^[a-zA-Z]', line): | ||
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 | ||
|
||
|
||
if __name__ == "__main__": | ||
raise SystemExit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- id: check-conditional-mark-sort | ||
name: check conditional mark sort | ||
description: check conditional mark yaml file sort from A to Z. | ||
entry: check-conditional-mark-sort | ||
language: python | ||
types: [yaml] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
[metadata] | ||
name = Some pre commit hooks | ||
version = 1.0.0+pre_commit | ||
description = Some hooks for pre-commit. | ||
long_description = file: README.md | ||
long_description_content_type = text/markdown | ||
url = https://github.com/sonic-net/sonic-mgmt | ||
classifiers = | ||
License :: OSI Approved :: MIT License | ||
Programming Language :: Python :: 3 | ||
Programming Language :: Python :: 3 :: Only | ||
Programming Language :: Python :: Implementation :: CPython | ||
Programming Language :: Python :: Implementation :: PyPy | ||
|
||
[options] | ||
packages = find: | ||
package_dir = | ||
=.hooks | ||
install_requires = | ||
ruamel.yaml>=0.15 | ||
tomli>=1.1.0;python_version<"3.11" | ||
python_requires = >=3.7 | ||
|
||
[options.packages.find] | ||
where = .hooks | ||
exclude = | ||
spytest* | ||
|
||
[options.entry_points] | ||
console_scripts = | ||
check-conditional-mark-sort = pre_commit_hooks.check_conditional_mark_sort:main | ||
|
||
[bdist_wheel] | ||
universal = True | ||
|
||
[coverage:run] | ||
plugins = covdefaults | ||
|
||
[mypy] | ||
check_untyped_defs = true | ||
disallow_any_generics = true | ||
disallow_incomplete_defs = true | ||
disallow_untyped_defs = true | ||
warn_redundant_casts = true | ||
warn_unused_ignores = true | ||
|
||
[mypy-testing.*] | ||
disallow_untyped_defs = false | ||
|
||
[mypy-tests.*] | ||
disallow_untyped_defs = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Local pre-commit hook setup | ||
from __future__ import annotations | ||
|
||
from setuptools import setup | ||
setup() |