From 429422715c74822e33ea2a77858191e39aece747 Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Mon, 21 Sep 2026 20:49:41 +0800 Subject: [PATCH] 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. --- src/metaglot/cmds/render/inno.py | 2 -- src/metaglot/cmds/render/msix.py | 2 -- src/metaglot/cmds/render/plist.py | 2 -- src/metaglot/render.py | 4 +++- 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/metaglot/cmds/render/inno.py b/src/metaglot/cmds/render/inno.py index ac94a51..09f31c5 100644 --- a/src/metaglot/cmds/render/inno.py +++ b/src/metaglot/cmds/render/inno.py @@ -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, diff --git a/src/metaglot/cmds/render/msix.py b/src/metaglot/cmds/render/msix.py index c3d8246..11d82d4 100644 --- a/src/metaglot/cmds/render/msix.py +++ b/src/metaglot/cmds/render/msix.py @@ -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, diff --git a/src/metaglot/cmds/render/plist.py b/src/metaglot/cmds/render/plist.py index 5d9e552..82c9805 100644 --- a/src/metaglot/cmds/render/plist.py +++ b/src/metaglot/cmds/render/plist.py @@ -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, diff --git a/src/metaglot/render.py b/src/metaglot/render.py index 5ecd21f..d8e55d7 100644 --- a/src/metaglot/render.py +++ b/src/metaglot/render.py @@ -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)