From ceba9fbb31bd1b561d40aefe2b02ec6f3f109b7d Mon Sep 17 00:00:00 2001 From: Victor Mattos <5757883+vicmattos@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:52:14 -0300 Subject: [PATCH 1/2] refactor(templates): Simplify target template file names with post_gen_project.py hook --- .../target-template/hooks/post_gen_project.py | 16 ++++++++++++++++ ... %}dependabot.yml{%endif%} => dependabot.yml} | 0 ... == 'GitHub' %}test.yml{%endif%} => test.yml} | 0 ...cutter.license %}LICENSE{%endif%} => LICENSE} | 0 4 files changed, 16 insertions(+) create mode 100644 cookiecutter/target-template/hooks/post_gen_project.py rename cookiecutter/target-template/{{cookiecutter.target_id}}/.github/{{% if cookiecutter.include_ci_files == 'GitHub' %}dependabot.yml{%endif%} => dependabot.yml} (100%) rename cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/{{% if cookiecutter.include_ci_files == 'GitHub' %}test.yml{%endif%} => test.yml} (100%) rename cookiecutter/target-template/{{cookiecutter.target_id}}/{{%if 'Apache-2.0' == cookiecutter.license %}LICENSE{%endif%} => LICENSE} (100%) diff --git a/cookiecutter/target-template/hooks/post_gen_project.py b/cookiecutter/target-template/hooks/post_gen_project.py new file mode 100644 index 000000000..c80aa2806 --- /dev/null +++ b/cookiecutter/target-template/hooks/post_gen_project.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python +from pathlib import Path +import shutil + + +BASE_PATH = Path('{{cookiecutter.library_name}}') + + +if __name__ == '__main__': + + if '{{ cookiecutter.license }}' != 'Apache-2.0': + Path('LICENSE').unlink() + + if '{{ cookiecutter.include_ci_files }}' != 'GitHub': + shutil.rmtree(Path('.github')) + diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/{% if cookiecutter.include_ci_files == 'GitHub' %}dependabot.yml{%endif%} b/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/dependabot.yml similarity index 100% rename from cookiecutter/target-template/{{cookiecutter.target_id}}/.github/{% if cookiecutter.include_ci_files == 'GitHub' %}dependabot.yml{%endif%} rename to cookiecutter/target-template/{{cookiecutter.target_id}}/.github/dependabot.yml diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/{% if cookiecutter.include_ci_files == 'GitHub' %}test.yml{%endif%} b/cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/test.yml similarity index 100% rename from cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/{% if cookiecutter.include_ci_files == 'GitHub' %}test.yml{%endif%} rename to cookiecutter/target-template/{{cookiecutter.target_id}}/.github/workflows/test.yml diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/{%if 'Apache-2.0' == cookiecutter.license %}LICENSE{%endif%} b/cookiecutter/target-template/{{cookiecutter.target_id}}/LICENSE similarity index 100% rename from cookiecutter/target-template/{{cookiecutter.target_id}}/{%if 'Apache-2.0' == cookiecutter.license %}LICENSE{%endif%} rename to cookiecutter/target-template/{{cookiecutter.target_id}}/LICENSE From 243b399a9a331277fdd45dbdc28ad3350497b033 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= <16805946+edgarrmondragon@users.noreply.github.com> Date: Tue, 21 Nov 2023 13:07:59 -0600 Subject: [PATCH 2/2] Update cookiecutter/target-template/hooks/post_gen_project.py --- .../target-template/hooks/post_gen_project.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cookiecutter/target-template/hooks/post_gen_project.py b/cookiecutter/target-template/hooks/post_gen_project.py index c80aa2806..44edd337b 100644 --- a/cookiecutter/target-template/hooks/post_gen_project.py +++ b/cookiecutter/target-template/hooks/post_gen_project.py @@ -3,14 +3,12 @@ import shutil -BASE_PATH = Path('{{cookiecutter.library_name}}') +BASE_PATH = Path("{{cookiecutter.library_name}}") -if __name__ == '__main__': - - if '{{ cookiecutter.license }}' != 'Apache-2.0': - Path('LICENSE').unlink() - - if '{{ cookiecutter.include_ci_files }}' != 'GitHub': - shutil.rmtree(Path('.github')) +if __name__ == "__main__": + if "{{ cookiecutter.license }}" != "Apache-2.0": + Path("LICENSE").unlink() + if "{{ cookiecutter.include_ci_files }}" != "GitHub": + shutil.rmtree(Path(".github"))