diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 87836315..81461816 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -59,3 +59,8 @@ repos: entry: resources/lesson-check.py language: system files: lessons/.*\.toml + - id: author-check + name: author-check + entry: resources/author-check.py + language: system + files: authors/*.toml diff --git a/resources/author-check.py b/resources/author-check.py new file mode 100644 index 00000000..9b9d88cb --- /dev/null +++ b/resources/author-check.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 +import os +import sys +import tomllib + +def error(msg): + print('ERROR:', msg, file=sys.stderr) + sys.exit(1) + +def check_author(author_path): + print(f"Checking {author_path}...") + + with open(author_path, 'rb') as f: + meta = tomllib.load(f) + + if 'name' not in meta: + error(f'No `name` in `meta` section of {author_path}') + + if 'description' not in meta: + error(f'No `description` in `meta` section of {author_path}') + + # Logo is optional, but if defined a corresponding image must exist + if 'logo' in meta: + logo_filename = f"{meta['logo']}.png" + logo_path = os.path.join("common/images/author-images", logo_filename) + if not os.path.isfile(logo_path): + error(f'Logo image does not exist at {logo_path} for {author_path}') + +if __name__ == '__main__': + for f in sys.argv[1:]: + check_author(f) diff --git a/resources/toml-check.py b/resources/toml-check.py index 749b5e08..0f3d5754 100755 --- a/resources/toml-check.py +++ b/resources/toml-check.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +import os import re import sys import tomllib @@ -26,6 +27,9 @@ def error(msg): if 'description' not in meta: error(f'No `description` in `meta` section of {f}') + if 'authors' not in meta or not meta['authors']: + error(f'No `authors` in `meta` section of {f}') + if 'icon' not in meta: error(f'No `icon` in `meta` section of {f}') @@ -58,3 +62,10 @@ def error(msg): if destinations and [x for x in destinations if x != 'spaces']: error(f'Only "spaces" is allowed in `destinations` in {f}') + + # Authors must have a corresponding author entry + author_meta_files = os.listdir("authors") + for author in meta['authors']: + author_filename = f"{author}.toml" + if author_filename not in author_meta_files: + error(f'Author {author} does not have a corresponding author entry in {f}')