From d9c61b310e4e84113d6194ef2912cba4e615e5b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89rico=20Andrei?= Date: Fri, 17 May 2024 16:46:41 +0200 Subject: [PATCH] Pre-format codebase during generation --- backend_addon/cookiecutter.json | 1 + backend_addon/hooks/post_gen_project.py | 7 ++++++- project/cookiecutter.json | 1 + project/hooks/post_gen_project.py | 8 +++++++- requirements.txt | 2 +- 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/backend_addon/cookiecutter.json b/backend_addon/cookiecutter.json index 42ee090..78213c4 100644 --- a/backend_addon/cookiecutter.json +++ b/backend_addon/cookiecutter.json @@ -21,6 +21,7 @@ "__generator_date_long": "{% now 'utc', '%Y-%m-%d %H:%M:%S' %}", "__generator_signature": "This was generated by [cookiecutter-plone](https://github.com/plone/cookieplone-templates/backend_addon) on {{ cookiecutter.__generator_date_long }}", "__backend_addon_git_initialize": "1", + "__backend_addon_format": "1", "__prompts__": { "title": "Addon Title", "description": "A short description of your addon", diff --git a/backend_addon/hooks/post_gen_project.py b/backend_addon/hooks/post_gen_project.py index 2dc1a67..3ae6377 100644 --- a/backend_addon/hooks/post_gen_project.py +++ b/backend_addon/hooks/post_gen_project.py @@ -4,7 +4,7 @@ from copy import deepcopy from pathlib import Path -from cookieplone.utils import console, files, git +from cookieplone.utils import console, files, git, plone context: OrderedDict = {{cookiecutter}} @@ -34,6 +34,7 @@ def main(): output_dir = Path().cwd() remove_headless = not int(context.get("feature_headless")) initialize_git = bool(int(context.get("__backend_addon_git_initialize"))) + backend_format = bool(int(context.get("__backend_addon_format"))) # Cleanup / Git actions = [ [ @@ -54,6 +55,10 @@ def main(): console.print(f" -> {title}") func(new_context, output_dir) + # Run format + if backend_format: + plone.format_python_codebase(output_dir) + msg = """ [bold blue]{{ cookiecutter.title }}[/bold blue] diff --git a/project/cookiecutter.json b/project/cookiecutter.json index 03af39f..9a031c0 100644 --- a/project/cookiecutter.json +++ b/project/cookiecutter.json @@ -69,6 +69,7 @@ "__devops_varnish_version": "7.4", "__devops_db_version": "14", "__devops_db_password": "{{ random_ascii_string(12) }}", + "__backend_addon_format": "1", "__backend_addon_git_initialize": "0", "__frontend_addon_git_initialize": "0", "__project_git_initialize": "1", diff --git a/project/hooks/post_gen_project.py b/project/hooks/post_gen_project.py index 3192794..6655d4e 100644 --- a/project/hooks/post_gen_project.py +++ b/project/hooks/post_gen_project.py @@ -5,7 +5,7 @@ from pathlib import Path from cookieplone import generator -from cookieplone.utils import console, files, git +from cookieplone.utils import console, files, git, plone context: OrderedDict = {{cookiecutter}} @@ -96,6 +96,7 @@ def main(): output_dir = Path().cwd() initialize_git = bool(int(context.get("__project_git_initialize"))) + backend_format = bool(int(context.get("__backend_addon_format"))) # Cleanup / Git actions = [ [ @@ -136,6 +137,11 @@ def main(): console.print(f" -> {title}") func(new_context, output_dir) + # Run format + if backend_format: + backend_folder = output_dir / "backend" + plone.format_python_codebase(backend_folder) + # Do a second run add newly created files if initialize_git: repo = git.repo_from_path(output_dir) diff --git a/requirements.txt b/requirements.txt index 31b9499..e284e8f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,6 +4,6 @@ isort pytest pytest-cookies pytest-jsonschema >= 1.0.0a2 -cookieplone>=0.6.1 +cookieplone>=0.6.3 GitPython wheel