From 758fea75af39ceb2d6aac433e71c9f2b2ebfb2b3 Mon Sep 17 00:00:00 2001 From: bruno-f-cruz <7049351+bruno-f-cruz@users.noreply.github.com> Date: Wed, 4 Dec 2024 01:15:23 -0800 Subject: [PATCH] Refactor demos to honor casing conventions --- .../src/python/_utils.py | 2 +- .../src/python/demo1.py | 21 +++++++++++++------ .../src/python/demo2.py | 21 +++++++++++++------ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/_topics/08-reproducible-research-practices/src/python/_utils.py b/_topics/08-reproducible-research-practices/src/python/_utils.py index b939036..cf05ec3 100644 --- a/_topics/08-reproducible-research-practices/src/python/_utils.py +++ b/_topics/08-reproducible-research-practices/src/python/_utils.py @@ -254,4 +254,4 @@ def pascal_to_snake_case(value: str) -> str: result += char.lower() else: result += char - return result \ No newline at end of file + return result diff --git a/_topics/08-reproducible-research-practices/src/python/demo1.py b/_topics/08-reproducible-research-practices/src/python/demo1.py index f84178b..9e20ad3 100644 --- a/_topics/08-reproducible-research-practices/src/python/demo1.py +++ b/_topics/08-reproducible-research-practices/src/python/demo1.py @@ -1,6 +1,11 @@ from pydantic import BaseModel, Field from typing import List, Optional -from _utils import export_schema, bonsai_sgen, BonsaiSgenSerializers +from _utils import ( + export_schema, + bonsai_sgen, + BonsaiSgenSerializers, + pascal_to_snake_case, +) from pathlib import Path @@ -23,15 +28,15 @@ class Experiment(BaseModel): if __name__ == "__main__": json_schema = export_schema(Experiment) - name = (Experiment.__name__).lower() - schema_path = Path(rf"src/json/{name}-schema.json") + schema_name = Experiment.__name__ + schema_path = Path(rf"src/json/{pascal_to_snake_case(schema_name)}-schema.json") with open(schema_path, "w", encoding="utf-8") as f: f.write(json_schema) bonsai_sgen( schema_path=schema_path, - output_path=Path(rf"src/bonsai/Extensions/{name.capitalize()}.cs"), - namespace=name.capitalize(), + output_path=Path(rf"src/bonsai/Extensions/{schema_name.capitalize()}.cs"), + namespace=schema_name.capitalize(), serializer=[BonsaiSgenSerializers.JSON, BonsaiSgenSerializers.YAML], ) @@ -43,5 +48,9 @@ class Experiment(BaseModel): ], ) - with open(rf"src/json/{name}-example.json", "w", encoding="utf-8") as f: + with open( + rf"src/json/{pascal_to_snake_case(schema_name)}-example.json", + "w", + encoding="utf-8", + ) as f: f.write(experiment_example.model_dump_json(indent=2)) diff --git a/_topics/08-reproducible-research-practices/src/python/demo2.py b/_topics/08-reproducible-research-practices/src/python/demo2.py index 905fc35..298a128 100644 --- a/_topics/08-reproducible-research-practices/src/python/demo2.py +++ b/_topics/08-reproducible-research-practices/src/python/demo2.py @@ -1,6 +1,11 @@ from pydantic import BaseModel, Field from typing import List, Optional, Annotated, Union, Literal -from _utils import export_schema, bonsai_sgen, BonsaiSgenSerializers +from _utils import ( + export_schema, + bonsai_sgen, + BonsaiSgenSerializers, + pascal_to_snake_case, +) from pathlib import Path from typing_extensions import TypeAliasType @@ -41,15 +46,15 @@ class ExperimentGoNoGo(BaseModel): if __name__ == "__main__": json_schema = export_schema(ExperimentGoNoGo) - name = (ExperimentGoNoGo.__name__).lower() - schema_path = Path(rf"src/json/{name}-schema.json") + schema_name = ExperimentGoNoGo.__name__ + schema_path = Path(rf"src/json/{pascal_to_snake_case(schema_name)}-schema.json") with open(schema_path, "w", encoding="utf-8") as f: f.write(json_schema) bonsai_sgen( schema_path=schema_path, - output_path=Path(rf"src/bonsai/Extensions/{name.capitalize()}.cs"), - namespace=name.capitalize(), + output_path=Path(rf"src/bonsai/Extensions/{schema_name.capitalize()}.cs"), + namespace=schema_name.capitalize(), serializer=[BonsaiSgenSerializers.JSON, BonsaiSgenSerializers.YAML], ) @@ -61,5 +66,9 @@ class ExperimentGoNoGo(BaseModel): ], ) - with open(rf"src/json/{name}-example.json", "w", encoding="utf-8") as f: + with open( + rf"src/json/{pascal_to_snake_case(schema_name)}-example.json", + "w", + encoding="utf-8", + ) as f: f.write(experiment_example.model_dump_json(indent=2))