Skip to content

Commit 1551d06

Browse files
committed
fix: standardize schema filenames to lowercase convention
- Rename all activity schema files to lowercase (e.g., activity2_schema) - Update post_gen_project.py to use lowercase filenames consistently - Normalize prefLabel to always use object notation with language tags - Fix path references to match actual filenames This ensures consistency with ReproSchema naming conventions and prevents path mismatch errors when loading activities.
1 parent f49420f commit 1551d06

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

hooks/post_gen_project.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,19 @@ def get_pref_label(activity_path):
2222
with open(activity_path, "r") as file:
2323
activity_schema = json.load(file)
2424
pref_label = activity_schema.get("prefLabel", "Unknown Activity")
25-
logger.debug(f"Got prefLabel '{pref_label}' from {activity_path}")
26-
return pref_label
25+
26+
# Normalize prefLabel to always return a string
27+
if isinstance(pref_label, dict):
28+
# Try to get English label first, then any available language
29+
normalized = pref_label.get("en", pref_label.get(list(pref_label.keys())[0], "Unknown Activity") if pref_label else "Unknown Activity")
30+
elif isinstance(pref_label, str):
31+
normalized = pref_label
32+
else:
33+
logger.warning(f"Unexpected prefLabel type in {activity_path}: {type(pref_label)}")
34+
normalized = "Unknown Activity"
35+
36+
logger.debug(f"Got prefLabel '{normalized}' from {activity_path}")
37+
return normalized
2738
except FileNotFoundError:
2839
logger.warning(f"Activity file not found: {activity_path}")
2940
return "Unknown Activity"
@@ -47,17 +58,19 @@ def update_json_schema(activities, base_path):
4758
schema["ui"]["order"] = []
4859

4960
for activity in activities:
61+
# Use lowercase schema filename consistently
62+
activity_schema_filename = f"{activity.lower()}_schema"
5063
activity_schema_path = os.path.join(
51-
base_path, f"activities/{activity}/{activity}_schema"
64+
base_path, f"activities/{activity}/{activity_schema_filename}"
5265
)
5366
pref_label = get_pref_label(activity_schema_path)
54-
activity_path = f"../activities/{activity}/{activity}_schema"
67+
activity_path = f"../activities/{activity}/{activity_schema_filename}"
5568

5669
schema["ui"]["addProperties"].append(
5770
{
5871
"isAbout": activity_path,
59-
"variableName": f"{activity}_schema",
60-
"prefLabel": pref_label,
72+
"variableName": activity_schema_filename,
73+
"prefLabel": {"en": pref_label}, # Always use object notation
6174
}
6275
)
6376
schema["ui"]["order"].append(activity_path)

0 commit comments

Comments
 (0)