From 219d7681de7c7040292f8ab761ad75c83b107926 Mon Sep 17 00:00:00 2001 From: Mikel Larreategi Date: Sat, 15 Oct 2022 19:38:31 +0200 Subject: [PATCH] create addon package using bobtemplates.plone --- hooks/post_gen_project.py | 43 +++++++++++++++---- requirements.txt | 1 + .../backend/src/.mrbob.ini | 13 ++++++ 3 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 {{ cookiecutter.project_slug }}/backend/src/.mrbob.ini diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 5487e1b..7475dc3 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -88,9 +88,15 @@ def prepare_frontend(volto_version: str, description: str): "frontend", ], [ - f"Generate frontend application with @plone/volto {_info(volto_version)}", - f"yo @plone/volto frontend --description '{description}' {addons} " - f"--skip-install --no-interactive --volto={volto_version}{canary}", + ( + "Generate frontend application with @plone/volto" + f" {_info(volto_version)}" + ), + ( + f"yo @plone/volto frontend --description '{description}'" + f" {addons} --skip-install --no-interactive" + f" --volto={volto_version}{canary}" + ), True, "frontend", ], @@ -113,15 +119,35 @@ def prepare_frontend(volto_version: str, description: str): with open(cfg, "r") as fh: data = fh.read() with open(cfg, "w") as fh: - new_data = re.sub("\n \/\/ Add here your project.*\n", VOLTO_CONFIG, data) + new_data = re.sub( + "\n \/\/ Add here your project.*\n", VOLTO_CONFIG, data + ) fh.write(new_data) -def prepare_backend(): - """Apply black and isort to the generated codebase.""" +def prepare_backend(python_package_name: str): + """Run plonecli/bobtemplates to create the package. + Apply black and isort to the generated codebase.""" print("Backend codebase") steps = [ - ["Format generated code in the backend", ["make", "format"], False, "backend"] + [ + "Create python package using bobtemplates/plonecli", + [ + ( + "mrbob --config src/.mrbob.ini -O" + f" src/{python_package_name}.addon" + " bobtemplates.plone:addon" + ), + ], + True, + "backend", + ], + [ + "Format generated code in the backend", + ["make", "format"], + False, + "backend", + ], ] for step in steps: msg, command, shell, cwd = step @@ -133,13 +159,14 @@ def prepare_backend(): volto_version = "{{ cookiecutter.volto_version }}" description = "{{ cookiecutter.description }}" +python_package_name = "{{ cookiecutter.python_package_name }}" def main(): """Final fixes.""" prepare_frontend(volto_version=volto_version, description=description) print("") - prepare_backend() + prepare_backend(python_package_name=python_package_name) print(f"{MSG_DELIMITER}") msg = dedent( f""" diff --git a/requirements.txt b/requirements.txt index 1454163..345bd69 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,3 +4,4 @@ isort pytest pytest-cookies wheel +bobtemplates.plone>=6.0b1 diff --git a/{{ cookiecutter.project_slug }}/backend/src/.mrbob.ini b/{{ cookiecutter.project_slug }}/backend/src/.mrbob.ini new file mode 100644 index 0000000..5a2220a --- /dev/null +++ b/{{ cookiecutter.project_slug }}/backend/src/.mrbob.ini @@ -0,0 +1,13 @@ +[mr.bob] +verbose = True + +[variables] +author.name = {{ cookiecutter.author }} +author.email = {{ cookiecutter.email }} +author.github.user = {{ cookiecutter.github_organization }} +package.description = {{ cookiecutter.description }} +package.git.init = n + +plone.version = {{ cookiecutter.plone_version }} +python.version = 3.10 +vscode_support = n