From d693817def7ce0d9df4c8c2a9b1f891713912d26 Mon Sep 17 00:00:00 2001 From: Ali Mosallaei Date: Wed, 10 Jul 2024 15:05:59 -0700 Subject: [PATCH] Remove duplicate variables from config fillables --- src/fppm/cli/commands/config.py | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/fppm/cli/commands/config.py b/src/fppm/cli/commands/config.py index f79c641..2734b05 100644 --- a/src/fppm/cli/commands/config.py +++ b/src/fppm/cli/commands/config.py @@ -59,12 +59,43 @@ def pull_cookiecutter_variables(configObject, packagePath): # append the variable name variable = line.split("{{")[1].split("}}")[0].strip().split(".")[1] lineNumber = configObjectContent.split("\n").index(line) + + doNotAdd = False + + for vars in cookiecutterVariables: + if vars["variable"] in variable: + doNotAdd = True + + if doNotAdd: + continue + cookiecutterVariables.append({ "context": line.strip(), "variable": variable, "line": lineNumber + 1 }) + # append other variables in the line + for var in line.split("{{")[1:]: + variable = var.split("}}")[0].strip().split(".")[1] + lineNumber = configObjectContent.split("\n").index(line) + + doNotAdd = False + + for vars in cookiecutterVariables: + print(vars["variable"], variable) + if vars["variable"] in variable: + doNotAdd = True + + if doNotAdd: + continue + + cookiecutterVariables.append({ + "context": line.strip(), + "variable": variable, + "line": lineNumber + 1 + }) + return (cookiecutterVariables, configDescription) def create_fillable(variables, description, configObject, packagePath, fillablesPath): @@ -253,8 +284,7 @@ def apply_config_fillables(args, context): try: os.mkdir(f"{packageFolder}.fillables/out") except FileExistsError: - shutil.rmtree(f"{packageFolder}.fillables/out", ignore_errors=True) - os.mkdir(f"{packageFolder}.fillables/out") + pass # move all files in the generated directory to the out directory