From 6e30f0ac111547de3d161a1e45ed915525498b92 Mon Sep 17 00:00:00 2001 From: Olga Lyashevska Date: Thu, 4 Jul 2024 16:23:07 +0200 Subject: [PATCH] Update hooks --- copier.yml | 2 ++ hooks/pre_gen_project.py | 32 +++++++++++++++++++++----------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/copier.yml b/copier.yml index 2401b65..715e352 100644 --- a/copier.yml +++ b/copier.yml @@ -46,5 +46,7 @@ code_of_conduct_email: default: "{{ email }}" _subdirectory: template +_tasks: + - python pre_gen_project.py # Optional questions diff --git a/hooks/pre_gen_project.py b/hooks/pre_gen_project.py index 665cbe5..81ac759 100644 --- a/hooks/pre_gen_project.py +++ b/hooks/pre_gen_project.py @@ -1,11 +1,21 @@ -# Note: cookiecutter first makes the main level directory using -# directory_name from cookiecutter.json before running this hook - -{{ cookiecutter.update({ - "package_name": cookiecutter.package_name.lower().replace(" ", "_").replace("-", "_"), - "directory_name": cookiecutter.directory_name.lower().replace(" ", "-"), - "full_name": cookiecutter.full_name.replace('\"', '\\\"'), - "repository": "git@github.com:" + cookiecutter.github_organization + "/" + cookiecutter.directory_name.lower().replace(" ", "-"), - "repository_url": "https://github.com/" + cookiecutter.github_organization + "/" + cookiecutter.directory_name.lower().replace(" ", "-"), - "package_short_description": cookiecutter.package_short_description.replace('\"', '\\\"') -}) }} +import os +import yaml + +def update_config(): + with open("copier.yml") as f: + config = yaml.safe_load(f) + + config.update({ + "package_name": config["package_name"].lower().replace(" ", "_").replace("-", "_"), + "directory_name": config["directory_name"].lower().replace(" ", "-"), + "full_name": config["full_name"].replace('\"', '\\\"'), + "repository": "git@github.com:" + config["github_organization"] + "/" + config["directory_name"].lower().replace(" ", "-"), + "repository_url": "https://github.com/" + config["github_organization"] + "/" + config["directory_name"].lower().replace(" ", "-"), + "package_short_description": config["package_short_description"].replace('\"', '\\\"') + }) + + with open("copier.yml", "w") as f: + yaml.safe_dump(config, f) + +if __name__ == "__main__": + update_config()