99
1010from check_manifest_features import *
1111import os
12- from os .path import basename , dirname , join , normpath , relpath , splitext
12+ from os .path import basename , dirname , join , normpath , relpath , splitext , isfile
1313from pathlib import PureWindowsPath
1414import glob
1515import tla_utils
@@ -104,17 +104,14 @@ def generate_new_manifest(examples_root, spec_path, spec_name, parser, queries):
104104
105105# Integrate human-written info from existing manifest.json
106106
107- def find_corresponding_spec (old_manifest , new_spec ):
108- specs = [
109- spec for spec in old_manifest ['specifications' ]
110- if spec ['path' ] == new_spec ['path' ]
111- ]
112- return specs [0 ] if any (specs ) else None
107+ def get_old_manifest (spec_path ):
108+ old_manifest_path = join (spec_path , 'manifest.json' )
109+ return tla_utils .load_json (old_manifest_path ) if isfile (old_manifest_path ) else None
113110
114- def integrate_spec_info (old_spec , new_spec ):
111+ def integrate_spec_info (old_manifest , new_spec ):
115112 fields = ['title' , 'description' , 'authors' , 'sources' , 'tags' ]
116113 for field in fields :
117- new_spec [field ] = old_spec [field ]
114+ new_spec [field ] = old_manifest [field ]
118115
119116def find_corresponding_module (old_module , new_spec ):
120117 modules = [
@@ -142,9 +139,10 @@ def integrate_model_info(old_model, new_model):
142139 new_model [field ] = old_model [field ]
143140
144141def integrate_old_manifest_into_new (old_manifest , new_spec ):
145- old_spec = find_corresponding_spec (old_manifest , new_spec )
146- integrate_spec_info (old_spec , new_spec )
147- for old_module in old_spec ['modules' ]:
142+ if old_manifest is None :
143+ return
144+ integrate_spec_info (old_manifest , new_spec )
145+ for old_module in old_manifest ['modules' ]:
148146 new_module = find_corresponding_module (old_module , new_spec )
149147 if new_module is None :
150148 continue
@@ -156,22 +154,20 @@ def integrate_old_manifest_into_new(old_manifest, new_spec):
156154 integrate_model_info (old_model , new_model )
157155
158156if __name__ == '__main__' :
159- parser = ArgumentParser (description = 'Generates a new manifest.json derived from files in the repo.' )
160- parser .add_argument ('--manifest_path' , help = 'Path to the current tlaplus/examples manifest.json file' , default = 'manifest.json' )
157+ parser = ArgumentParser (description = 'Generates new manifest.json files derived from files in the repo.' )
161158 parser .add_argument ('--ci_ignore_path' , help = 'Path to the CI ignore file' , default = '.ciignore' )
162159 args = parser .parse_args ()
163160
164- manifest_path = normpath (args .manifest_path )
165- examples_root = dirname (manifest_path )
166161 ci_ignore_path = normpath (args .ci_ignore_path )
162+ examples_root = dirname (ci_ignore_path )
167163 ignored_dirs = tla_utils .get_ignored_dirs (ci_ignore_path )
168164
169165 TLAPLUS_LANGUAGE = Language (tree_sitter_tlaplus .language ())
170166 parser = Parser (TLAPLUS_LANGUAGE )
171167 queries = build_queries (TLAPLUS_LANGUAGE )
172168
173- old_manifest = tla_utils .load_json (manifest_path )
174169 for (spec_path , spec_name ) in get_spec_dirs (examples_root , ignored_dirs ):
170+ old_manifest = get_old_manifest (spec_path )
175171 new_manifest = generate_new_manifest (examples_root , spec_path , spec_name , parser , queries )
176172 integrate_old_manifest_into_new (old_manifest , new_manifest )
177173 tla_utils .write_json (new_manifest , join (spec_path , 'manifest.json' ))
0 commit comments