Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Update templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed Apr 17, 2024
1 parent 0813a21 commit ae38ec0
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 196 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/volto_addon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ jobs:
- name: Checkout codebase
uses: actions/checkout@v4

- name: Set up Python 3.8
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: 3.8
python-version: 3.10
cache: 'pip'

- name: Install dependencies
Expand Down
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RESET=`tput sgr0`
YELLOW=`tput setaf 3`

.PHONY: all
all: bin/cookiecutter
all: bin/cookieplone

# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
Expand All @@ -22,20 +22,22 @@ help: ## This help message
clean: ## Clean
rm -rf bin include lib lib64 pyvenv.cfg .Python

bin/cookiecutter: ## Create virtualenv and install dependencies
bin/cookieplone: ## Create virtualenv and install dependencies
@echo "$(GREEN)==> Setup Virtual Env$(RESET)"
python3 -m venv .
bin/pip install pip --upgrade
bin/pip install -r requirements.txt --upgrade

.PHONY: format
format: bin/cookiecutter ## Format code
format: bin/cookieplone ## Format code
@echo "$(GREEN)==> Formatting codebase $(RESET)"
bin/black hooks
bin/isort hooks
$(MAKE) -C "./plone_addon/" format
$(MAKE) -C "./volto_addon/" format

.PHONY: test
test: bin/cookiecutter ## Test all cookiecutters
test: bin/cookieplone ## Test all cookiecutters
@echo "$(GREEN)==> Test all cookiecutters$(RESET)"
$(MAKE) -C "./plone_addon/" test
$(MAKE) -C "./volto_addon/" test
16 changes: 8 additions & 8 deletions plone_addon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ help: ## This help message
clean: ## Clean
rm -rf collective.addon

../bin/cookiecutter: ## Cookiecutter installation
$(MAKE) -C ".." bin/cookiecutter
../bin/cookieplone: ## cookieplone installation
$(MAKE) -C ".." bin/cookieplone

.PHONY: format
format: ../bin/cookiecutter ## Format code
format: ../bin/cookieplone ## Format code
@echo "$(GREEN)==> Formatting codebase $(RESET)"
../bin/black hooks local_extensions tests
../bin/isort hooks local_extensions tests
../bin/black hooks tests
../bin/isort hooks tests

.PHONY: generate
generate: ../bin/cookiecutter ## Create a sample package
generate: ../bin/cookieplone ## Create a sample package
@echo "$(GREEN)==> Creating new test package$(RESET)"
rm -rf collective.addon
../bin/cookiecutter . --no-input
../bin/cookieplone . --no-input

.PHONY: test
test: ../bin/cookiecutter ## Create a sample package and tests it
test: ../bin/cookieplone ## Create a sample package and tests it
@echo "$(GREEN)==> Creating new test package$(RESET)"
../bin/python -m pytest tests
2 changes: 1 addition & 1 deletion plone_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"__profile_version": "1000",
"__generator_date_short": "{% now 'utc', '%Y-%m-%d' %}",
"__generator_date_long": "{% now 'utc', '%Y-%m-%d %H:%M:%S' %}",
"__generator_signature": "This was generated by [cookiecutter-plone](https://github.com/plone/cookiecutter-plone/addon) on {{ cookiecutter.__generator_date_long }}",
"__generator_signature": "This was generated by [cookiecutter-plone](https://github.com/plone/cookiecutter-plone/plone_addon) on {{ cookiecutter.__generator_date_long }}",
"__prompts__": {
"addon_title": "Addon Title",
"description": "A short description of your addon",
Expand Down
29 changes: 7 additions & 22 deletions plone_addon/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import sys
from pathlib import Path

from cookieplone import utils

from cookieplone.utils import console, rmtree

# PATH OF CONTENT TO BE REMOVED
TO_REMOVE_PATHS = {
Expand All @@ -18,7 +17,7 @@ def run_cmd(command: str, shell: bool, cwd: str) -> bool:
proc = subprocess.run(command, shell=shell, cwd=cwd, capture_output=True)
if proc.returncode:
# Write errors to the main process stderr
utils.console.error(f"Error while running {command}")
console.error(f"Error while running {command}")
return False if proc.returncode else True


Expand All @@ -31,21 +30,21 @@ def remove_files(category: str):
path = base_path / filepath
exists = path.exists()
if exists and path.is_dir():
utils.rmtree(path)
rmtree(path)
elif exists and path.is_file():
path.unlink()


def initialize_git():
"""Apply black and isort to the generated codebase."""
utils.console.info("Git repository")
console.info("Git repository")
steps = [
["Initialize", ["git", "init", "."], False, "."],
["Add files", ["git", "add", "."], False, "."],
]
for step in steps:
msg, command, shell, cwd = step
utils.console.info(f" - {msg}")
console.info(f" - {msg}")
result = run_cmd(command, shell=shell, cwd=cwd)
if not result:
sys.exit(1)
Expand All @@ -69,23 +68,9 @@ def main():
Sorry for the convenience,
The Plone Community.
"""
utils.console.panel(
title="New addon was generated",
subtitle="",
msg=msg,
url="https://plone.org/"
console.panel(
title="New addon was generated", subtitle="", msg=msg, url="https://plone.org/"
)
msg = """
Now, enter the repositorym run the code formatter with:
make format
start coding, and push to your organization.
Sorry for the convenience,
The Plone Community.
"""


if __name__ == "__main__":
Expand Down
21 changes: 12 additions & 9 deletions plone_addon/hooks/pre_prompt.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Pre Prompt hook."""
import subprocess
import sys

try:
from cookieplone import data
from cookieplone import utils
from cookieplone.utils import commands, console, sanity

HAS_COOKIEPLONE = True
except ModuleNotFoundError:
HAS_COOKIEPLONE = False
Expand All @@ -22,10 +22,15 @@
def sanity_check() -> bool:
"""Run sanity checks on the system."""
checks = [
data.SanityCheck("Python", utils.commands.check_python_version, [SUPPORTED_PYTHON_VERSIONS], "error"),
data.SanityCheck("git", utils.commands.check_command_is_available, ["git"], "error"),
data.SanityCheck(
"Python",
commands.check_python_version,
[SUPPORTED_PYTHON_VERSIONS],
"error",
),
data.SanityCheck("git", commands.check_command_is_available, ["git"], "error"),
]
result = utils.sanity.run_sanity_checks(checks)
result = sanity.run_sanity_checks(checks)
return result.status


Expand All @@ -34,10 +39,8 @@ def main():
if not HAS_COOKIEPLONE:
print("This template should be run with cookieplone")
sys.exit(1)
utils.console.panel(
title="Plone Addon",
msg="Creating a new Plone Addon"
)

console.panel(title="Plone Addon", msg="Creating a new Plone Addon")
if not sanity_check():
sys.exit(1)

Expand Down
1 change: 1 addition & 0 deletions plone_addon/tests/test_cutter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test cookiecutter generation with all features enabled."""
import pytest

from .conftest import PKG_SRC_FEATURE_HEADLESS, PKG_SRC_FILES, ROOT_FILES


Expand Down
1 change: 1 addition & 0 deletions plone_addon/tests/test_cutter_no_headless.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Test cookiecutter generation with features enabled."""
import pytest

from .conftest import PKG_SRC_FEATURE_HEADLESS, PKG_SRC_FILES, ROOT_FILES


Expand Down
14 changes: 7 additions & 7 deletions volto_addon/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ help: ## This help message
clean: ## Clean
rm -rf volto-addon

../bin/cookiecutter: ## Cookiecutter installation
$(MAKE) -C ".." bin/cookiecutter
../bin/cookieplone: ## cookieplone installation
$(MAKE) -C ".." bin/cookieplone

.PHONY: format
format: ../bin/cookiecutter ## Format code
format: ../bin/cookieplone ## Format code
@echo "$(GREEN)==> Formatting codebase $(RESET)"
../bin/black hooks local_extensions tests
../bin/isort hooks local_extensions tests
../bin/black hooks tests
../bin/isort hooks tests

.PHONY: generate
generate: ../bin/cookiecutter ## Create a sample package
generate: ../bin/cookieplone ## Create a sample package
@echo "$(GREEN)==> Creating new test package$(RESET)"
rm -rf volto-addon
../bin/cookiecutter . --no-input

.PHONY: test
test: ../bin/cookiecutter ## Create a sample package and tests it
test: ../bin/cookieplone ## Create a sample package and tests it
@echo "$(GREEN)==> Creating new test package$(RESET)"
../bin/python -m pytest tests
54 changes: 9 additions & 45 deletions volto_addon/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,11 @@
"""Post generation hook."""

import subprocess
import sys
from textwrap import dedent

TERMINATOR = "\x1b[0m"
WARNING = "\x1b[1;33m"
INFO = "\x1b[1;34m"
HINT = "\x1b[3;35m"
SUCCESS = "\x1b[1;32m"
ERROR = "\x1b[1;31m"
MSG_DELIMITER = "=" * 80


def _error(msg: str) -> str:
"""Format error message."""
return f"{ERROR}{msg}{TERMINATOR}"


def _success(msg: str) -> str:
"""Format success message."""
return f"{SUCCESS}{msg}{TERMINATOR}"


def _info(msg: str) -> str:
"""Format info message."""
return f"{INFO}{msg}{TERMINATOR}"


def run_cmd(command: str, shell: bool, cwd: str) -> bool:
proc = subprocess.run(command, shell=shell, cwd=cwd, capture_output=True)
if proc.returncode:
# Write errors to the main process stderr
print(_error(f"\nError while running {command}:"), file=sys.stderr)
sys.stderr.buffer.write(proc.stderr)
print("\n", file=sys.stderr)
return False if proc.returncode else True
from cookieplone.utils import console


def main():
"""Final fixes."""
print(f"{MSG_DELIMITER}")
print("")
print(f"{MSG_DELIMITER}")
msg = dedent(
f"""
{_success('New add-on "{{ cookiecutter.addon_name }}" was generated')}
msg = """
[bold blue]{{ cookiecutter.addon_name }}[/bold blue]
Now, enter the generated directory and finish the install:
Expand All @@ -57,9 +17,13 @@ def main():
Sorry for the convenience,
The Plone Community.
"""
console.panel(
title="New addon was generated",
subtitle="",
msg=msg,
url="https://plone.org/"
)
print(msg)
print(f"{MSG_DELIMITER}")



if __name__ == "__main__":
Expand Down
Loading

0 comments on commit ae38ec0

Please sign in to comment.