Skip to content

Commit 45b5b72

Browse files
committed
Update update_license_headers.py
1 parent 414e9e8 commit 45b5b72

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎tools/update_license_headers.py‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,31 @@
1818
import glob
1919
import subprocess
2020
import tempfile
21+
from collections.abc import Iterable, Iterator
2122

2223
import yaml
2324

2425

25-
def load_config(filename):
26+
def load_config(filename: str) -> list[dict]:
27+
"""Load the list of header entries from a NOTICE.yml file."""
2628
with open(filename) as fh:
2729
return yaml.safe_load(fh)
2830

2931

30-
def walk_directory(entry):
31-
"""Walk the directory"""
32+
def walk_directory(entry: dict) -> list[str]:
33+
"""List the files an entry includes, minus those it excludes."""
3234

3335
if "header" not in entry:
3436
raise ValueError("Current entry does not have a header.")
3537
if "include" not in entry:
3638
raise ValueError("Current entry does not have an include list.")
3739

38-
def _list_include():
40+
def _list_include() -> Iterator[str]:
3941
"""List all files specified in the include list."""
4042
for include_pattern in entry["include"]:
4143
yield from glob.iglob(include_pattern, recursive=True)
4244

43-
def _filter_exclude(iterable):
45+
def _filter_exclude(iterable: Iterable[str]) -> Iterator[str]:
4446
"""Filter filenames from an iterator by the exclude patterns."""
4547
for filename in iterable:
4648
for exclude_pattern in entry.get("exclude", []):
@@ -53,7 +55,8 @@ def _filter_exclude(iterable):
5355
return list(files)
5456

5557

56-
def main(input_file="NOTICE.yml"):
58+
def main(input_file: str = "NOTICE.yml") -> None:
59+
"""Write each entry's header into the files it covers, with licenseheaders."""
5760
config = load_config(input_file)
5861
for entry in config:
5962
filelist = list(walk_directory(entry))

0 commit comments

Comments
 (0)