Skip to content

Commit a68e58a

Browse files
authored
fix: include overriden template file paths in codegen'd file header. (#135)
1 parent c54a8da commit a68e58a

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ help: ## display help for this makefile
2222

2323
.PHONY: codegen
2424
codegen: build-docker-base ## Run codegen to convert the LinkML schema to a GQL API
25-
$(docker_compose_run) $(BUILD_CONTAINER) api generate --template-override-paths ./template_overrides --schemafile ./schema/schema.yaml --output-prefix .
25+
$(docker_compose_run) $(BUILD_CONTAINER) api generate --template-override-paths ./template_overrides --schemafile ./schema/schema.yaml --output-prefix .
2626
$(docker_compose_run) $(CONTAINER) black .
2727
#$(docker_compose_run) $(CONTAINER) ruff check --fix .
2828

platformics/codegen/generator.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -72,31 +72,28 @@ def generate_entity_subclass_files(
7272
dest_filename = str(template_filename).replace("class_name", entity.snake_name)
7373
print(f"writing {dest_filename}", end="")
7474

75+
entity_template = template
7576
if f"{dest_filename}.j2" in environment.list_templates():
76-
override_template = environment.get_template(f"{dest_filename}.j2")
77-
content = override_template.render(
78-
cls=entity,
79-
view=view,
80-
)
81-
else:
82-
content = template.render(
83-
cls=entity,
84-
view=view,
85-
)
77+
entity_template = environment.get_template(f"{dest_filename}.j2")
78+
content = entity_template.render(
79+
cls=entity,
80+
view=view,
81+
)
8682
with open(os.path.join(output_prefix, dest_filename), mode="w", encoding="utf-8") as outfile:
87-
outfile.write(prepend_warning(dest_filename, template, content))
83+
outfile.write(prepend_warning(dest_filename, entity_template, content))
8884
print("... done")
8985

9086

9187
def prepend_warning(dest_filename: str, template: Template, content: str) -> str:
88+
formatted_filename = template.filename
89+
if "platformics/codegen" in formatted_filename:
90+
formatted_filename = formatted_filename[formatted_filename.find("platformics/codegen") :]
9291
if dest_filename.endswith(".yaml"):
93-
formatted_filename = template.filename[template.filename.find("platformics/codegen") :]
9492
content = (
9593
"# Auto-generated by running `make codegen`. Do not edit!\n"
9694
f"# Make changes to the template {formatted_filename} instead.\n"
9795
) + str(content)
9896
if dest_filename.endswith(".py"):
99-
formatted_filename = template.filename[template.filename.find("platformics/codegen") :]
10097
lines = content.splitlines()
10198
opens_with_comment = False
10299
if lines[0] == '"""':

test_app/template_overrides/graphql_api/types/uncaught_exception.py.j2

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
"""
2-
Auto-generated by running `make codegen`. Do not edit!
3-
Make changes to the template platformics/codegen/templates/graphql_api/types/class_name.py.j2 instead.
4-
52
GraphQL type for UncaughtException
63
"""
74

0 commit comments

Comments
 (0)