1717def validate_json_file (templates_json_path : Path ) -> dict :
1818 """Validate templates.json is valid JSON and return parsed data."""
1919 try :
20- with open (templates_json_path , 'r' , encoding = ' utf-8' ) as f :
20+ with open (templates_json_path , "r" , encoding = " utf-8" ) as f :
2121 data = json .load (f )
2222 print (f"✓ { templates_json_path } is valid JSON" )
2323 return data
@@ -34,35 +34,35 @@ def validate_template_entry(name: str, config: dict, repo_root: Path) -> list[st
3434 errors = []
3535
3636 # Check required fields
37- if ' file' not in config :
37+ if " file" not in config :
3838 errors .append (f"Template '{ name } ' missing required field 'file'" )
39- if ' description' not in config :
39+ if " description" not in config :
4040 errors .append (f"Template '{ name } ' missing required field 'description'" )
4141
42- if ' file' not in config :
42+ if " file" not in config :
4343 return errors # Can't continue without file field
4444
4545 # Check main file exists
46- main_file = repo_root / config [' file' ]
46+ main_file = repo_root / config [" file" ]
4747 if not main_file .exists ():
4848 errors .append (f"Template '{ name } ': main file '{ config ['file' ]} ' does not exist" )
4949
5050 # Validate featured field if present (optional)
51- if ' featured' in config :
52- if not isinstance (config [' featured' ], bool ):
51+ if " featured" in config :
52+ if not isinstance (config [" featured" ], bool ):
5353 errors .append (f"Template '{ name } ': 'featured' field must be a boolean" )
5454
5555 # Validate author field if present (optional)
56- if ' author' in config :
57- author = config [' author' ]
56+ if " author" in config :
57+ author = config [" author" ]
5858 if not isinstance (author , dict ):
5959 errors .append (f"Template '{ name } ': 'author' field must be an object" )
6060 else :
6161 # All author fields are optional, but validate types if present
6262 optional_author_fields = {
63- ' name' : str ,
64- ' github_profile' : str ,
65- ' last_modified_date' : str
63+ " name" : str ,
64+ " github_profile" : str ,
65+ " last_modified_date" : str ,
6666 }
6767 for field , expected_type in optional_author_fields .items ():
6868 if field in author and not isinstance (author [field ], expected_type ):
@@ -71,31 +71,34 @@ def validate_template_entry(name: str, config: dict, repo_root: Path) -> list[st
7171 )
7272
7373 # Check files array if present
74- if ' files' in config :
75- for file_spec in config [' files' ]:
76- if ' source' not in file_spec :
74+ if " files" in config :
75+ for file_spec in config [" files" ]:
76+ if " source" not in file_spec :
7777 errors .append (f"Template '{ name } ': file entry missing 'source' field" )
7878 continue
79- if ' dest' not in file_spec :
79+ if " dest" not in file_spec :
8080 errors .append (f"Template '{ name } ': file entry missing 'dest' field" )
8181 continue
8282
83- source_path = repo_root / file_spec [' source' ]
83+ source_path = repo_root / file_spec [" source" ]
8484 if not source_path .exists ():
85- errors .append (f"Template '{ name } ': source file '{ file_spec ['source' ]} ' does not exist" )
85+ errors .append (
86+ f"Template '{ name } ': source file '{ file_spec ['source' ]} ' does not exist"
87+ )
8688
8789 # For complex templates, check required files exist
88- is_complex = len (config [' files' ]) > 1
90+ is_complex = len (config [" files" ]) > 1
8991 if is_complex :
90- template_dir = Path (config ['file' ]).parent
91- required_files = ['README.md' , 'pyproject.toml.template' , '.env.example.template' ]
92+ template_dir = Path (config ["file" ]).parent
93+ required_files = [
94+ "README.md" ,
95+ "pyproject.toml.template" ,
96+ ".env.example.template" ,
97+ ]
9298
9399 for required in required_files :
94100 # Check if it's in the files array
95- found = any (
96- Path (f ['source' ]).name == required
97- for f in config ['files' ]
98- )
101+ found = any (Path (f ["source" ]).name == required for f in config ["files" ])
99102 if not found :
100103 errors .append (
101104 f"Template '{ name } ': complex template missing '{ required } ' in files array"
@@ -106,7 +109,7 @@ def validate_template_entry(name: str, config: dict, repo_root: Path) -> list[st
106109
107110def main ():
108111 repo_root = Path (__file__ ).parent .parent .parent
109- templates_json = repo_root / ' templates.json'
112+ templates_json = repo_root / " templates.json"
110113
111114 print ("Validating template registry...\n " )
112115
@@ -126,7 +129,7 @@ def main():
126129 print (f"✗ { error } " )
127130
128131 # Summary
129- print (f"\n { '=' * 60 } " )
132+ print (f"\n { '=' * 60 } " )
130133 if all_errors :
131134 print (f"Validation failed with { len (all_errors )} error(s)" )
132135 sys .exit (1 )
@@ -135,5 +138,5 @@ def main():
135138 sys .exit (0 )
136139
137140
138- if __name__ == ' __main__' :
141+ if __name__ == " __main__" :
139142 main ()
0 commit comments