Skip to content

Commit

Permalink
Implement cookiecutter-plone-starter templates in cookieplone-templates
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed May 16, 2024
1 parent 612a912 commit be891b8
Show file tree
Hide file tree
Showing 117 changed files with 4,972 additions and 25 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
/backend_addon/ @ericof
/frontend_addon/ @sneridagh
/project/ @ericof
/sub/cache/ @ericof
/sub/frontend_project/ @sneridagh
/sub/project_settings/ @sneridagh
40 changes: 40 additions & 0 deletions .github/workflows/all_templates.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: cookieplone-templates CI
on:
push:
workflow_dispatch:

jobs:

generation:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"

steps:
# git checkout
- name: Checkout codebase
uses: actions/checkout@v4

# python setup
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

# python install
- name: Install dependencies
run: |
pip install -r requirements.txt
# Test
- name: Run tests
run: |
python -m pytest tests
44 changes: 44 additions & 0 deletions .github/workflows/project.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Plone Project CI
on:
push:
paths:
- "project/**"
- ".github/workflows/project.yml"
workflow_dispatch:

jobs:

generation:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"

steps:
# git checkout
- name: Checkout codebase
uses: actions/checkout@v4

# python setup
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

# python install
- name: Install dependencies
run: |
pip install -r requirements.txt
# Test
- name: Run tests
run: |
cd plone_addon
python -m pytest tests
47 changes: 47 additions & 0 deletions .github/workflows/sub_cache.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Plone Cache Settings CI
on:
push:
paths:
- "sub/cache_settings/**"
- ".github/workflows/sub_cache_settings.yml"
workflow_dispatch:

env:
PYTHON_VERSION: "3.10"

jobs:

generation:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"

steps:
# git checkout
- name: Checkout codebase
uses: actions/checkout@v4

# python setup
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

# python install
- name: Install dependencies
run: |
pip install -r requirements.txt
# Test
- name: Run tests
run: |
cd sub/cache_settings
python -m pytest tests
47 changes: 47 additions & 0 deletions .github/workflows/sub_project_settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Plone Project Settings CI
on:
push:
paths:
- "sub/project_settings/**"
- ".github/workflows/sub_project_settings.yml"
workflow_dispatch:

env:
PYTHON_VERSION: "3.10"

jobs:

generation:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"

steps:
# git checkout
- name: Checkout codebase
uses: actions/checkout@v4

# python setup
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'

# python install
- name: Install dependencies
run: |
pip install -r requirements.txt
# Test
- name: Run tests
run: |
cd sub/project_settings
python -m pytest tests
9 changes: 8 additions & 1 deletion .scripts/report_keys_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@

report_filename = f"{date.today()}-{last_commit.hexsha[:7]}-usage.json"

folders = ["backend_addon", "frontend_addon"]
folders = [
"backend_addon",
"frontend_addon",
"project",
"sub/cache",
"sub/frontend_project",
"sub/project_settings",
]
ignore = [
"__prompts__",
]
Expand Down
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

TOP_LEVEL_TEMPLATES = backend_addon frontend_addon project
SUB_TEMPLATES = cache frontend_project project_settings

.PHONY: all
all: bin/cookieplone

Expand All @@ -31,18 +34,17 @@ bin/cookieplone: ## Create virtualenv and install dependencies
.PHONY: format
format: bin/cookieplone ## Format code
@echo "$(GREEN)==> Formatting codebase $(RESET)"
bin/black hooks .scripts
bin/isort hooks .scripts
$(MAKE) -C "./backend_addon/" format
$(MAKE) -C "./frontend_addon/" format
$(MAKE) -C "./sub/frontend_project/" format
bin/black hooks .scripts tests
bin/isort hooks .scripts tests
$(foreach project,$(TOP_LEVEL_TEMPLATES),$(MAKE) -C "./$(project)/" format ;)
$(foreach project,$(SUB_TEMPLATES),$(MAKE) -C "./sub/$(project)/" format ;)

.PHONY: test
test: bin/cookieplone ## Test all cookiecutters
@echo "$(GREEN)==> Test all cookiecutters$(RESET)"
$(MAKE) -C "./backend_addon/" test
$(MAKE) -C "./frontend_addon/" test
$(MAKE) -C "./sub/frontend_project/" test
bin/python3 -m pytest tests
$(foreach project,$(TOP_LEVEL_TEMPLATES),$(MAKE) -C "./$(project)/" test ;)
$(foreach project,$(SUB_TEMPLATES),$(MAKE) -C "./sub/$(project)/" test ;)

.PHONY: report-context
report-context: bin/cookieplone ## Generate a report of all context options
Expand Down
4 changes: 3 additions & 1 deletion backend_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@
"cookieplone.filters.pascal_case",
"cookieplone.filters.package_name",
"cookieplone.filters.package_namespace"
]
],
"__cookieplone_repository_path": "",
"__cookieplone_template": ""
}
10 changes: 9 additions & 1 deletion backend_addon/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,20 @@
]


@pytest.fixture(scope="session")
def cookieplone_root() -> dict:
"""Cookieplone root dir."""
parent = Path().cwd().resolve().parent
return parent


@pytest.fixture(scope="session")
def variable_pattern():
return re.compile("{{( ?cookiecutter)[.](.*?)}}")


@pytest.fixture(scope="session")
def context() -> dict:
def context(cookieplone_root) -> dict:
"""Cookiecutter context."""
return {
"title": "Addon",
Expand All @@ -81,6 +88,7 @@ def context() -> dict:
"author": "Plone Collective",
"email": "[email protected]",
"feature_headless": "1",
"__cookieplone_repository_path": f"{cookieplone_root}",
}


Expand Down
5 changes: 5 additions & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"templates": {
"project": {
"path": "./project",
"title": "A Plone Project",
"description": "Create a new Plone project with backend and frontend components"
},
"backend_addon": {
"path": "./backend_addon",
"title": "Backend Add-on for Plone",
Expand Down
4 changes: 3 additions & 1 deletion frontend_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
"_copy_without_render": [],
"_extensions": [
"cookieplone.filters.latest_volto"
]
],
"__cookieplone_repository_path": "",
"__cookieplone_template": ""
}
10 changes: 9 additions & 1 deletion frontend_addon/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ def variable_pattern():


@pytest.fixture(scope="session")
def context() -> dict:
def cookieplone_root() -> dict:
"""Cookieplone root dir."""
parent = Path().cwd().resolve().parent
return parent


@pytest.fixture(scope="session")
def context(cookieplone_root) -> dict:
"""Cookiecutter context."""
return {
"frontend_addon_name": "volto-addon",
Expand All @@ -25,6 +32,7 @@ def context() -> dict:
"github_organization": "collective",
"npm_package_name": "@plone-collective/volto-addon",
"volto_version": "18.0.0-alpha.31",
"__cookieplone_repository_path": f"{cookieplone_root}",
}


Expand Down
54 changes: 54 additions & 0 deletions project/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
SHELL := /bin/bash
CURRENT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))


# We like colors
# From: https://coderwall.com/p/izxssa/colored-makefile-for-golang-projects
RED=`tput setaf 1`
GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

.PHONY: all
all: build

TEMPLATE = $(shell basename $(CURRENT_DIR))
PROJECT_FOLDER_NAME = project-title
BASE_FOLDER = ../
BIN_FOLDER = ${BASE_FOLDER}/bin


# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
.PHONY: help
help: ## This help message
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: clean
clean: ## Clean
rm -rf volto-addon

$(BIN_FOLDER)/cookieplone: ## cookieplone installation
$(MAKE) -C $(BASE_FOLDER) bin/cookieplone

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

.PHONY: generate
generate: $(BIN_FOLDER)/cookieplone ## Create a sample package
@echo "$(GREEN)==> Creating new test package$(RESET)"
rm -rf $(PROJECT_FOLDER_NAME)
COOKIEPLONE_REPOSITORY=$(BASE_FOLDER) $(BIN_FOLDER)/cookieplone $(TEMPLATE) --no_input

.PHONY: test
test: $(BIN_FOLDER)/cookieplone ## Create a sample package and tests it
@echo "$(GREEN)==> Test template$(RESET)"
$(BIN_FOLDER)/python -m pytest tests

.PHONY: test-pdb
test-pdb: $(BIN_FOLDER)/cookieplone ## Stop on the first failed test
@echo "$(GREEN)==> Test template, stop on first error$(RESET)"
$(BIN_FOLDER)/python -m pytest tests -x --pdb
Loading

0 comments on commit be891b8

Please sign in to comment.