From 5fc13c0e65d3feca6a02642b88356f7d549986d9 Mon Sep 17 00:00:00 2001 From: nx10 Date: Mon, 3 Jun 2024 15:59:49 +0000 Subject: [PATCH] =?UTF-8?q?Deploying=20to=20gh-pages=20from=20@=20childmin?= =?UTF-8?q?dresearch/styx@cd8c33527907c7f38a3f61f57c80301028be45d2=20?= =?UTF-8?q?=F0=9F=9A=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- styx/main.html | 218 ++++++++++++++++++++++++++----------------------- 1 file changed, 115 insertions(+), 103 deletions(-) diff --git a/styx/main.html b/styx/main.html index dd4aa3f..02a83e0 100644 --- a/styx/main.html +++ b/styx/main.html @@ -176,61 +176,67 @@

114 subtree["__items__"] = [] 115 subtree["__items__"].append(output_module_name) 116 -117 with open(json_path, "r", encoding="utf-8") as json_file: -118 try: -119 json_data = json.load(json_file) -120 except json.JSONDecodeError: -121 print(f"Skipped: {json_path} (invalid JSON)") -122 fail_counter += 1 -123 continue -124 try: -125 code = compile_boutiques_dict(json_data, settings) -126 -127 if settings.output_path: -128 output_path = settings.output_path / pathlib.Path(*output_module_path) -129 output_path.mkdir(parents=True, exist_ok=True) -130 output_path = output_path / output_file_name -131 with open(output_path, "w") as py_file: -132 py_file.write(code) -133 print(f"Compiled {json_path} to {output_path}") -134 else: -135 print(f"Compiled {json_path} -> {pathlib.Path(*output_module_path) / output_file_name}: {'---' * 10}") -136 print(code) -137 print("---" * 10) -138 except Exception as e: -139 print(f"Skipped: {json_path}") -140 if settings.debug_mode: -141 raise e -142 fail_counter += 1 -143 import traceback -144 -145 print(traceback.format_exc()) -146 -147 # Re-export __init__.py files -148 # TODO: make optional -149 if settings.output_path is not None: +117 # check if source is newer than target +118 if settings.output_path: +119 output_path = settings.output_path / pathlib.Path(*output_module_path) / output_file_name +120 if output_path.exists() and json_path.stat().st_mtime < output_path.stat().st_mtime: +121 continue +122 +123 with open(json_path, "r", encoding="utf-8") as json_file: +124 try: +125 json_data = json.load(json_file) +126 except json.JSONDecodeError: +127 print(f"Skipped: {json_path} (invalid JSON)") +128 fail_counter += 1 +129 continue +130 try: +131 code = compile_boutiques_dict(json_data, settings) +132 +133 if settings.output_path: +134 output_path = settings.output_path / pathlib.Path(*output_module_path) +135 output_path.mkdir(parents=True, exist_ok=True) +136 output_path = output_path / output_file_name +137 with open(output_path, "w") as py_file: +138 py_file.write(code) +139 print(f"Compiled {json_path} to {output_path}") +140 else: +141 print(f"Compiled {json_path} -> {pathlib.Path(*output_module_path) / output_file_name}: {'---' * 10}") +142 print(code) +143 print("---" * 10) +144 except Exception as e: +145 print(f"Skipped: {json_path}") +146 if settings.debug_mode: +147 raise e +148 fail_counter += 1 +149 import traceback 150 -151 def _walk_tree(tree: dict, path: str) -> None: -152 for key, value in tree.items(): -153 if key == "__items__": -154 assert settings.output_path is not None -155 out_path = settings.output_path / path / "__init__.py" -156 with open(out_path, "w") as init_file: -157 init_file.write(generate_reexport_module(value)) -158 print(f"Generated {out_path}") -159 else: -160 _walk_tree(value, f"{path}/{key}" if path else key) -161 -162 _walk_tree(module_tree, "") -163 -164 if fail_counter > 0: -165 print(f"Failed to compile {fail_counter}/{total_counter} descriptors.") -166 else: -167 print(f"Successfully compiled {total_counter} descriptors.") -168 +151 print(traceback.format_exc()) +152 +153 # Re-export __init__.py files +154 # TODO: make optional +155 if settings.output_path is not None: +156 +157 def _walk_tree(tree: dict, path: str) -> None: +158 for key, value in tree.items(): +159 if key == "__items__": +160 assert settings.output_path is not None +161 out_path = settings.output_path / path / "__init__.py" +162 with open(out_path, "w") as init_file: +163 init_file.write(generate_reexport_module(value)) +164 print(f"Generated {out_path}") +165 else: +166 _walk_tree(value, f"{path}/{key}" if path else key) +167 +168 _walk_tree(module_tree, "") 169 -170if __name__ == "__main__": -171 main() +170 if fail_counter > 0: +171 print(f"Failed to compile {fail_counter}/{total_counter} descriptors.") +172 else: +173 print(f"Successfully compiled {total_counter} descriptors.") +174 +175 +176if __name__ == "__main__": +177 main() @@ -384,57 +390,63 @@

115 subtree["__items__"] = [] 116 subtree["__items__"].append(output_module_name) 117 -118 with open(json_path, "r", encoding="utf-8") as json_file: -119 try: -120 json_data = json.load(json_file) -121 except json.JSONDecodeError: -122 print(f"Skipped: {json_path} (invalid JSON)") -123 fail_counter += 1 -124 continue -125 try: -126 code = compile_boutiques_dict(json_data, settings) -127 -128 if settings.output_path: -129 output_path = settings.output_path / pathlib.Path(*output_module_path) -130 output_path.mkdir(parents=True, exist_ok=True) -131 output_path = output_path / output_file_name -132 with open(output_path, "w") as py_file: -133 py_file.write(code) -134 print(f"Compiled {json_path} to {output_path}") -135 else: -136 print(f"Compiled {json_path} -> {pathlib.Path(*output_module_path) / output_file_name}: {'---' * 10}") -137 print(code) -138 print("---" * 10) -139 except Exception as e: -140 print(f"Skipped: {json_path}") -141 if settings.debug_mode: -142 raise e -143 fail_counter += 1 -144 import traceback -145 -146 print(traceback.format_exc()) -147 -148 # Re-export __init__.py files -149 # TODO: make optional -150 if settings.output_path is not None: +118 # check if source is newer than target +119 if settings.output_path: +120 output_path = settings.output_path / pathlib.Path(*output_module_path) / output_file_name +121 if output_path.exists() and json_path.stat().st_mtime < output_path.stat().st_mtime: +122 continue +123 +124 with open(json_path, "r", encoding="utf-8") as json_file: +125 try: +126 json_data = json.load(json_file) +127 except json.JSONDecodeError: +128 print(f"Skipped: {json_path} (invalid JSON)") +129 fail_counter += 1 +130 continue +131 try: +132 code = compile_boutiques_dict(json_data, settings) +133 +134 if settings.output_path: +135 output_path = settings.output_path / pathlib.Path(*output_module_path) +136 output_path.mkdir(parents=True, exist_ok=True) +137 output_path = output_path / output_file_name +138 with open(output_path, "w") as py_file: +139 py_file.write(code) +140 print(f"Compiled {json_path} to {output_path}") +141 else: +142 print(f"Compiled {json_path} -> {pathlib.Path(*output_module_path) / output_file_name}: {'---' * 10}") +143 print(code) +144 print("---" * 10) +145 except Exception as e: +146 print(f"Skipped: {json_path}") +147 if settings.debug_mode: +148 raise e +149 fail_counter += 1 +150 import traceback 151 -152 def _walk_tree(tree: dict, path: str) -> None: -153 for key, value in tree.items(): -154 if key == "__items__": -155 assert settings.output_path is not None -156 out_path = settings.output_path / path / "__init__.py" -157 with open(out_path, "w") as init_file: -158 init_file.write(generate_reexport_module(value)) -159 print(f"Generated {out_path}") -160 else: -161 _walk_tree(value, f"{path}/{key}" if path else key) -162 -163 _walk_tree(module_tree, "") -164 -165 if fail_counter > 0: -166 print(f"Failed to compile {fail_counter}/{total_counter} descriptors.") -167 else: -168 print(f"Successfully compiled {total_counter} descriptors.") +152 print(traceback.format_exc()) +153 +154 # Re-export __init__.py files +155 # TODO: make optional +156 if settings.output_path is not None: +157 +158 def _walk_tree(tree: dict, path: str) -> None: +159 for key, value in tree.items(): +160 if key == "__items__": +161 assert settings.output_path is not None +162 out_path = settings.output_path / path / "__init__.py" +163 with open(out_path, "w") as init_file: +164 init_file.write(generate_reexport_module(value)) +165 print(f"Generated {out_path}") +166 else: +167 _walk_tree(value, f"{path}/{key}" if path else key) +168 +169 _walk_tree(module_tree, "") +170 +171 if fail_counter > 0: +172 print(f"Failed to compile {fail_counter}/{total_counter} descriptors.") +173 else: +174 print(f"Successfully compiled {total_counter} descriptors.")