fix: liquid render function now create parent dir if possible

liquid render function now create the parent directory of its target if possible to fix the issue that user need manually create directory hierarchy for multiple output render command.
This commit is contained in:
2026-09-21 20:49:41 +08:00
parent 835e3437c7
commit 429422715c
4 changed files with 3 additions and 7 deletions
-2
View File
@@ -276,7 +276,6 @@ def run(opts: InnoRenderOpts) -> None:
iss_out = opts.out_dir / render_path(
iss_path_env, opts.in_iss_path, _InnoIssPathContext()
)
iss_out.parent.mkdir(parents=True, exist_ok=True)
render(
iss_template_env,
opts.in_iss_template,
@@ -288,7 +287,6 @@ def run(opts: InnoRenderOpts) -> None:
isl_out = opts.out_dir / render_path(
isl_path_env, opts.in_isl_path, _InnoIslPathContext(lang)
)
isl_out.parent.mkdir(parents=True, exist_ok=True)
render(
isl_template_env,
opts.in_isl_template,
-2
View File
@@ -278,7 +278,6 @@ def run(opts: MsixRenderOpts) -> None:
manifest_out = opts.out_dir / render_path(
manifest_path_env, opts.in_manifest_path, _MsixManifestPathContext()
)
manifest_out.parent.mkdir(parents=True, exist_ok=True)
render(
manifest_template_env,
opts.in_manifest_template,
@@ -292,7 +291,6 @@ def run(opts: MsixRenderOpts) -> None:
opts.in_resources_path,
_MsixResourcesPathContext(lang),
)
resources_out.parent.mkdir(parents=True, exist_ok=True)
render(
resources_template_env,
opts.in_resources_template,
-2
View File
@@ -302,7 +302,6 @@ def run(opts: PlistRenderOpts) -> None:
plist_out = opts.out_dir / render_path(
plist_path_env, opts.in_plist_path, _PlistInfoPathContext()
)
plist_out.parent.mkdir(parents=True, exist_ok=True)
render(
plist_template_env,
opts.in_plist_template,
@@ -316,7 +315,6 @@ def run(opts: PlistRenderOpts) -> None:
opts.in_strings_path,
_PlistStringsPathContext(lang),
)
strings_out.parent.mkdir(parents=True, exist_ok=True)
render(
strings_template_env,
opts.in_strings_template,
+3 -1
View File
@@ -46,7 +46,8 @@ def render(
"""Render a Liquid template and write the result to a file.
The template is read as UTF-8. The rendered output is written as UTF-8
using the system's native line endings.
using the system's native line endings. The parent folder of the output
file is created when it does not exist.
:param env: The environment to render with.
:param template_path: The path of the template file.
@@ -72,6 +73,7 @@ def render(
f"failed to render template '{template_path}': {exc}"
) from exc
output_path.parent.mkdir(parents=True, exist_ok=True)
output_path.write_text(content, encoding="utf-8")
logging.info("Wrote rendered output to %s", output_path)