Skip to content

Commit 67a2044

Browse files
committed
organizers: merge build and build_organizers to remove dependences
1 parent d467e1a commit 67a2044

File tree

4 files changed

+43
-78
lines changed

4 files changed

+43
-78
lines changed

.github/workflows/build_json.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ jobs:
2727
pip install -r requirements.txt
2828
2929
- name: Build
30-
run: |
31-
python build_organizers.py
32-
python build.py
30+
run: python build.py
3331

3432
- name: Deploy 🚀
3533
uses: JamesIves/[email protected]

.github/workflows/pr_check.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ jobs:
2323
pip install -r requirements.txt
2424
2525
- name: Run check
26-
run: |
27-
python build_organizers.py --dry
28-
python build.py --dry
26+
run: python build.py --dry

build.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import os
44
import sys
5+
import shutil
56
from collections import defaultdict, namedtuple
67
from datetime import date, datetime
78

@@ -19,10 +20,11 @@ def years_from_school_year(school_year):
1920
start_year = int(school_year.split("_")[0])
2021
return (start_year, start_year + 1)
2122

22-
23+
logos = ["icon", "icon-darkmode", "small-icon", "small-icon-darkmode"]
2324
ErrorData = namedtuple("ErrorData", ["file", "message"])
2425
ERRORS = []
2526
OUTPUT = defaultdict(lambda: [])
27+
OUTPUT_ORGANIZERS = {}
2628
ROOT = os.path.dirname(os.path.abspath(__file__))
2729

2830
parser = argparse.ArgumentParser()
@@ -35,8 +37,32 @@ def years_from_school_year(school_year):
3537
with open(os.path.join(ROOT, "schemas", "event.schema.json")) as f:
3638
validate_event = fastjsonschema.compile(json.load(f))
3739

38-
with open(os.path.join(ROOT, "build", "organizers.json")) as f:
39-
organizers = json.load(f)
40+
with open(os.path.join(ROOT, "schemas", "organizer.schema.json")) as f:
41+
validate_organizer = fastjsonschema.compile(json.load(f))
42+
43+
print("validating orgnanizers")
44+
45+
for directory in os.walk(os.path.join(ROOT, "organizers")):
46+
for file in directory[2]:
47+
name, ext = os.path.splitext(file)
48+
if ext.lower() not in [".yaml", ".yml"]:
49+
continue
50+
path = os.path.join(directory[0], file)
51+
52+
with open(path) as f:
53+
organizer_data = yaml.safe_load(f)
54+
try:
55+
organizer_data = validate_organizer(organizer_data)
56+
for logo in logos:
57+
if logo in organizer_data and not os.path.exists(os.path.join(ROOT, "organizers", organizer_data[logo])):
58+
raise JsonSchemaValueException("Invalid path to %s, %s" % (logo, organizer_data[logo]))
59+
OUTPUT_ORGANIZERS[name] = organizer_data
60+
print(".", end="", flush=True)
61+
except JsonSchemaException as e:
62+
ERRORS.append(ErrorData(path, e.message))
63+
print("F", end="", flush=True)
64+
65+
print("\nValidating events")
4066

4167
for directory in os.walk(os.path.join(ROOT, "data")):
4268
for file in directory[2]:
@@ -50,7 +76,7 @@ def years_from_school_year(school_year):
5076
try:
5177
event_data = validate_event(event_data)
5278
for organizer in event_data["organizers"]:
53-
if organizer not in organizers:
79+
if organizer not in OUTPUT_ORGANIZERS:
5480
raise JsonSchemaValueException("Organizer %s is not in organizers." % (organizer))
5581
if not args.dry:
5682
event_date = datetime.strptime(
@@ -71,6 +97,17 @@ def years_from_school_year(school_year):
7197

7298
if not args.dry:
7399
os.makedirs(os.path.join(ROOT, "build"), exist_ok=True)
100+
print("Writing output for organizers.")
101+
102+
for reference, organizer in OUTPUT.items():
103+
for logo in logos:
104+
if logo in organizer_data:
105+
os.makedirs(os.path.dirname(os.path.join(ROOT, "build", organizer_data[logo])), exist_ok=True)
106+
shutil.copy(os.path.join(ROOT, "organizers", organizer_data[logo]), os.path.join(ROOT, "build", organizer_data[logo]))
107+
108+
with open(os.path.join(ROOT, "build/organizers.json"), "w") as f:
109+
json.dump(OUTPUT, f)
110+
74111
for year, events in OUTPUT.items():
75112
print("Writing output for year %s." % (year))
76113

build_organizers.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)