Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
proper path usage in export_parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
iopapamanoglou committed Sep 13, 2024
1 parent 1fd3bef commit 47bf8b2
Showing 1 changed file with 28 additions and 33 deletions.
61 changes: 28 additions & 33 deletions src/faebryk/exporters/parameters/parameters_to_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,37 @@ def export_parameters_to_file(module: Module, path: Path):
]

logger.info(f"Writing parameters to {path}")
if not path.exists() or not path.is_file():
path.touch()

out = ""
if path.suffix == ".txt":
with open(path, "w") as f:
for module_name, paras in sorted(parameters.items()):
if paras:
f.write(f"{module_name}\n")
f.writelines(
[
f" {par_name}: {par_value}\n"
for par_dict in paras
for par_name, par_value in par_dict.items()
]
)
f.write("\n")
f.close()
for module_name, paras in sorted(parameters.items()):
if paras:
out += f"{module_name}\n"
out += "\n".join(
[
f" {par_name}: {par_value}\n"
for par_dict in paras
for par_name, par_value in par_dict.items()
]
)
out += "\n"
elif path.suffix == ".md":
with open(path, "w") as f:
f.write("# Module Parameters\n")
for module_name, paras in sorted(parameters.items()):
if paras:
f.write(f"**{module_name.replace("|","|")}**\n")
f.write("| Parameter Name | Parameter Value |\n")
f.write("| --- | --- |\n")
f.writelines(
[
f"| {par_name.replace("|","|")} | {str(par_value).replace("|","|")} |\n" # noqa E501
for par_dict in paras
for par_name, par_value in par_dict.items()
]
)
f.write("\n")
f.write("\n")
f.close()
out += "# Module Parameters\n"
for module_name, paras in sorted(parameters.items()):
if paras:
out += f"**{module_name.replace("|","|")}**\n"
out += "| Parameter Name | Parameter Value |\n"
out += "| --- | --- |\n"
out += "\n".join(
[
f"| {par_name.replace("|","|")} | {str(par_value).replace("|","|")} |\n" # noqa E501
for par_dict in paras
for par_name, par_value in par_dict.items()
]
)
out += "\n"
else:
AssertionError(
f"Export to file extension [{path.suffix}] not supported in {path}"
)

path.write_text(out)

0 comments on commit 47bf8b2

Please sign in to comment.