From 7e89953f2ce9d0a3364b47cc7cea62156afb1637 Mon Sep 17 00:00:00 2001 From: Malte Hilpert Date: Fri, 12 Dec 2025 00:13:42 +0100 Subject: [PATCH] feat(versioning): @public macro function Finds all macros in @public functions and adds a passthrough for them in the version_check function --- smithed_libraries/plugins/versioning/api.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/smithed_libraries/plugins/versioning/api.py b/smithed_libraries/plugins/versioning/api.py index 46b0214..e1bdc97 100644 --- a/smithed_libraries/plugins/versioning/api.py +++ b/smithed_libraries/plugins/versioning/api.py @@ -12,11 +12,16 @@ PUBLIC_PAT = re.compile("^#>? @public") -def generate_call(ctx: Context, opts: VersioningOptions, path: str): +def generate_call(ctx: Context, opts: VersioningOptions, path: str, macros: list[str]): """Generates the actual call function that checks the version""" base_path = path.replace(opts.api.implementation_prefix, "") + function = call_if_version_match(opts.scoreholder, opts.version, path) + if len(macros) > 0: + macro = " {" + ",".join(f"{x}:$({x})" for x in macros) + "}" # `stringify` macros + function = f"${function.rstrip("\n")} {macro}\n" + version_check = ctx.generate[opts.api.version_check_path]( base_path, Function(call_if_version_match(opts.scoreholder, opts.version, path)) ) @@ -43,4 +48,6 @@ def generate_api(ctx: Context): return for (path, func) in query[Function].keys(): if func.lines and path is not None and PUBLIC_PAT.match(func.lines[0]): - generate_call(ctx, opts, path) + macros = re.findall(r"\$\(([A-Za-z0-9_]+)\)", "\n".join(func.lines)) # fild all macros (including in comment? maybe need fixing) + macros = list(dict.fromkeys(macros)) # filter out duplicates + generate_call(ctx, opts, path, macros)