Skip to content

Commit

Permalink
Pre-format codebase during generation
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed May 17, 2024
1 parent 72d37a7 commit d9c61b3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions backend_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 6 additions & 1 deletion backend_addon/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down Expand Up @@ -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 = [
[
Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions project/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion project/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}}

Expand Down Expand Up @@ -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 = [
[
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ isort
pytest
pytest-cookies
pytest-jsonschema >= 1.0.0a2
cookieplone>=0.6.1
cookieplone>=0.6.3
GitPython
wheel

0 comments on commit d9c61b3

Please sign in to comment.