Skip to content

Commit

Permalink
add toml checks
Browse files Browse the repository at this point in the history
  • Loading branch information
fcmsilva committed Jun 14, 2024
1 parent 25877fe commit 67fefea
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
31 changes: 31 additions & 0 deletions resources/author-check.py
Original file line number Diff line number Diff line change
@@ -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)
11 changes: 11 additions & 0 deletions resources/toml-check.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3
import os
import re
import sys
import tomllib
Expand Down Expand Up @@ -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}')

Expand Down Expand Up @@ -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}')

0 comments on commit 67fefea

Please sign in to comment.