mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-07 12:26:52 +00:00
added license header - test.
This commit is contained in:
parent
582b9c66e0
commit
d4d3c8d787
2 changed files with 67 additions and 0 deletions
66
pre_commit_hooks/add_license_header.py
Normal file
66
pre_commit_hooks/add_license_header.py
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from collections.abc import Generator
|
||||||
|
from collections.abc import Sequence
|
||||||
|
from typing import Any
|
||||||
|
from typing import NamedTuple
|
||||||
|
|
||||||
|
import ruamel.yaml
|
||||||
|
|
||||||
|
yaml = ruamel.yaml.YAML(typ='safe')
|
||||||
|
|
||||||
|
|
||||||
|
def _exhaust(gen: Generator[str]) -> None:
|
||||||
|
for _ in gen:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_unsafe(*args: Any, **kwargs: Any) -> None:
|
||||||
|
_exhaust(yaml.parse(*args, **kwargs))
|
||||||
|
|
||||||
|
|
||||||
|
def _load_all(*args: Any, **kwargs: Any) -> None:
|
||||||
|
_exhaust(yaml.load_all(*args, **kwargs))
|
||||||
|
|
||||||
|
|
||||||
|
class Key(NamedTuple):
|
||||||
|
multi: bool
|
||||||
|
unsafe: bool
|
||||||
|
|
||||||
|
|
||||||
|
LOAD_FNS = {
|
||||||
|
Key(multi=False, unsafe=False): yaml.load,
|
||||||
|
Key(multi=False, unsafe=True): _parse_unsafe,
|
||||||
|
Key(multi=True, unsafe=False): _load_all,
|
||||||
|
Key(multi=True, unsafe=True): _parse_unsafe,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv: Sequence[str] | None = None) -> int:
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
'-m', '--multi', '--allow-multiple-documents', action='store_true',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--unsafe', action='store_true',
|
||||||
|
help=(
|
||||||
|
'Instead of loading the files, simply parse them for syntax. '
|
||||||
|
'A syntax-only check enables extensions and unsafe constructs '
|
||||||
|
'which would otherwise be forbidden. Using this option removes '
|
||||||
|
'all guarantees of portability to other yaml implementations. '
|
||||||
|
'Implies --allow-multiple-documents'
|
||||||
|
),
|
||||||
|
)
|
||||||
|
parser.add_argument('filenames', nargs='*', help='Filenames to check.')
|
||||||
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
|
load_fn = LOAD_FNS[Key(multi=args.multi, unsafe=args.unsafe)]
|
||||||
|
|
||||||
|
retval = 0
|
||||||
|
println("add_license_header.py")
|
||||||
|
return retval
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
raise SystemExit(main())
|
||||||
|
|
@ -60,6 +60,7 @@ console_scripts =
|
||||||
requirements-txt-fixer = pre_commit_hooks.requirements_txt_fixer:main
|
requirements-txt-fixer = pre_commit_hooks.requirements_txt_fixer:main
|
||||||
sort-simple-yaml = pre_commit_hooks.sort_simple_yaml:main
|
sort-simple-yaml = pre_commit_hooks.sort_simple_yaml:main
|
||||||
trailing-whitespace-fixer = pre_commit_hooks.trailing_whitespace_fixer:main
|
trailing-whitespace-fixer = pre_commit_hooks.trailing_whitespace_fixer:main
|
||||||
|
add_license_header = pre_commit_hooks.add_license_header:main
|
||||||
|
|
||||||
[bdist_wheel]
|
[bdist_wheel]
|
||||||
universal = True
|
universal = True
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue