Skip to content

Commit

Permalink
Refactor demos to honor casing conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-f-cruz committed Dec 4, 2024
1 parent fd71b02 commit 758fea7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,4 @@ def pascal_to_snake_case(value: str) -> str:
result += char.lower()
else:
result += char
return result
return result
21 changes: 15 additions & 6 deletions _topics/08-reproducible-research-practices/src/python/demo1.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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],
)

Expand All @@ -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))
21 changes: 15 additions & 6 deletions _topics/08-reproducible-research-practices/src/python/demo2.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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],
)

Expand All @@ -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))

0 comments on commit 758fea7

Please sign in to comment.