Skip to content

Commit d4d3c8d

Browse files
author
Sithideth Viengkhou (Riedel)
committed
added license header - test.
1 parent 582b9c6 commit d4d3c8d

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from __future__ import annotations
2+
3+
import argparse
4+
from collections.abc import Generator
5+
from collections.abc import Sequence
6+
from typing import Any
7+
from typing import NamedTuple
8+
9+
import ruamel.yaml
10+
11+
yaml = ruamel.yaml.YAML(typ='safe')
12+
13+
14+
def _exhaust(gen: Generator[str]) -> None:
15+
for _ in gen:
16+
pass
17+
18+
19+
def _parse_unsafe(*args: Any, **kwargs: Any) -> None:
20+
_exhaust(yaml.parse(*args, **kwargs))
21+
22+
23+
def _load_all(*args: Any, **kwargs: Any) -> None:
24+
_exhaust(yaml.load_all(*args, **kwargs))
25+
26+
27+
class Key(NamedTuple):
28+
multi: bool
29+
unsafe: bool
30+
31+
32+
LOAD_FNS = {
33+
Key(multi=False, unsafe=False): yaml.load,
34+
Key(multi=False, unsafe=True): _parse_unsafe,
35+
Key(multi=True, unsafe=False): _load_all,
36+
Key(multi=True, unsafe=True): _parse_unsafe,
37+
}
38+
39+
40+
def main(argv: Sequence[str] | None = None) -> int:
41+
parser = argparse.ArgumentParser()
42+
parser.add_argument(
43+
'-m', '--multi', '--allow-multiple-documents', action='store_true',
44+
)
45+
parser.add_argument(
46+
'--unsafe', action='store_true',
47+
help=(
48+
'Instead of loading the files, simply parse them for syntax. '
49+
'A syntax-only check enables extensions and unsafe constructs '
50+
'which would otherwise be forbidden. Using this option removes '
51+
'all guarantees of portability to other yaml implementations. '
52+
'Implies --allow-multiple-documents'
53+
),
54+
)
55+
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
56+
args = parser.parse_args(argv)
57+
58+
load_fn = LOAD_FNS[Key(multi=args.multi, unsafe=args.unsafe)]
59+
60+
retval = 0
61+
println("add_license_header.py")
62+
return retval
63+
64+
65+
if __name__ == '__main__':
66+
raise SystemExit(main())

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ console_scripts =
6060
requirements-txt-fixer = pre_commit_hooks.requirements_txt_fixer:main
6161
sort-simple-yaml = pre_commit_hooks.sort_simple_yaml:main
6262
trailing-whitespace-fixer = pre_commit_hooks.trailing_whitespace_fixer:main
63+
add_license_header = pre_commit_hooks.add_license_header:main
6364

6465
[bdist_wheel]
6566
universal = True

0 commit comments

Comments
 (0)