Skip to content

Commit

Permalink
Merge branch 'issue-2-project-template' into sneridagh-misc-fixes
Browse files Browse the repository at this point in the history
* issue-2-project-template:
  Remove trove classifier of distribution from project_settings
  Flag to add distribution trove classifier
  Backend: Update .dockerignore
  Apply suggestions from code review
  Fix Makefile and README
  Improve template testing with newer cookieplone version (0.7.0)
  Add dependabot.yml
  • Loading branch information
sneridagh committed May 29, 2024
2 parents f5470ce + e6f1ab7 commit daed5a6
Show file tree
Hide file tree
Showing 45 changed files with 261 additions and 171 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ pipx run cookieplone

```text
[1/1] Select a template
1 - Backend Add-on for Plone
2 - Frontend Add-on
1 - A Plone Project
2 - Backend Add-on for Plone
3 - Frontend Add-on
```

| Template | Description | |
| --------- | --------- | --------- |
| `A Plone Project` | Create a new Plone project with backend and frontend components. | [Read More](./project/README.md) |
| `Backend Add-on for Plone` | Create a new Python package to be used with Plone. | [Read More](./backend_addon/README.md) |
| `Frontend Add-on for Plone` | Create a new Node package to be used with Volto. | [Read More](./frontend_addon/README.md) |

Expand Down
4 changes: 2 additions & 2 deletions backend_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"1",
"0"
],
"__feature_headless": "{{ cookiecutter.feature_headless }}",
"__feature_distribution": "0",
"__package_name": "{{ cookiecutter.python_package_name | package_name }}",
"__package_namespace": "{{ cookiecutter.python_package_name | package_namespace }}",
"__folder_name": "{{ cookiecutter.python_package_name }}",
"__python_package_name_upper": "{{ cookiecutter.python_package_name | pascal_case }}",
"__profile_language": "en",
"__version_package": "1.0.0a0",
"__profile_version": "1000",
"__gha_enable": true,
"__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/cookieplone-templates/backend_addon) on {{ cookiecutter.__generator_date_long }}",
"__backend_addon_git_initialize": "1",
Expand Down
12 changes: 9 additions & 3 deletions backend_addon/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ def handle_git_initialization(context: OrderedDict, output_dir: Path):
def main():
"""Final fixes."""
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")))
remove_headless = not int(
context.get("feature_headless")
) # {{ cookiecutter.__feature_headless }}
initialize_git = bool(
int(context.get("__backend_addon_git_initialize"))
) # {{ cookiecutter.__backend_addon_git_initialize }}
backend_format = bool(
int(context.get("__backend_addon_format"))
) # {{ cookiecutter.__backend_addon_format }}
# Cleanup / Git
actions = [
[
Expand Down
15 changes: 9 additions & 6 deletions backend_addon/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Pytest configuration."""

import re
from copy import deepcopy
from pathlib import Path
from typing import List
Expand Down Expand Up @@ -73,11 +72,6 @@ def cookieplone_root() -> dict:
return parent


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


@pytest.fixture(scope="session")
def context(cookieplone_root) -> dict:
"""Cookiecutter context."""
Expand All @@ -103,6 +97,15 @@ def context_no_headless(context) -> dict:
return new_context


@pytest.fixture(scope="session")
def context_distribution(context) -> dict:
"""Cookiecutter context with distribution enabled."""
new_context = deepcopy(context)
new_context["python_package_name"] = "plonedistribution.myplone"
new_context["__feature_distribution"] = "1"
return new_context


@pytest.fixture(scope="session")
def context_no_git(context) -> dict:
"""Cookiecutter context without Git repository."""
Expand Down
35 changes: 35 additions & 0 deletions backend_addon/tests/test_cutter_distribution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Test cookiecutter generation with distribution feature enabled."""

import pytest


@pytest.fixture(scope="session")
def cutter_result(cookies_session, context_distribution):
"""Cookiecutter result."""
return cookies_session.bake(extra_context=context_distribution)


def test_creation(cookies, context_distribution: dict):
"""Generated project should match provided value."""
result = cookies.bake(extra_context=context_distribution)
assert result.exception is None
assert result.exit_code == 0
assert result.project_path.name == context_distribution["python_package_name"]
assert result.project_path.is_dir()


def test_variable_substitution(build_files_list, variable_pattern, cutter_result):
"""Check if no file was unprocessed."""
paths = build_files_list(cutter_result.project_path)
for path in paths:
for line in open(path):
match = variable_pattern.search(line)
msg = f"cookiecutter variable not replaced in {path}"
assert match is None, msg


def test_trove_classifier_set(cutter_result):
"""Check feature-specific files were not generated."""
trove_classifier = "Framework :: Plone :: Distribution"
setup_py = cutter_result.project_path / "setup.py"
assert trove_classifier in setup_py.read_text()
2 changes: 1 addition & 1 deletion backend_addon/tests/test_cutter_no_headless.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Test cookiecutter generation with features enabled."""
"""Test cookiecutter generation withoyt headeless feature."""

import pytest

Expand Down
14 changes: 14 additions & 0 deletions backend_addon/tests/test_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALLOWED_MISSING = []
ALLOWED_NOT_USED = []


def test_no_missing_variables(variables_missing):
"""Test no variable is missing from cookiecutter.json"""
assert len(variables_missing) == len(ALLOWED_MISSING)
assert variables_missing == ALLOWED_MISSING


def test_not_used_variables(variables_not_used):
"""Test variables are used."""
assert len(variables_not_used) == len(ALLOWED_NOT_USED)
assert variables_not_used == ALLOWED_NOT_USED
26 changes: 10 additions & 16 deletions backend_addon/{{ cookiecutter.__folder_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

PLONE6=6.0-latest

# Python checks
PYTHON?=python3

Expand Down Expand Up @@ -50,7 +48,7 @@ help: ## This help message
$(BIN_FOLDER)/pip $(BIN_FOLDER)/tox $(BIN_FOLDER)/pipx $(BIN_FOLDER)/uv $(BIN_FOLDER)/mxdev:
@echo "$(GREEN)==> Setup Virtual Env$(RESET)"
$(PYTHON) -m venv $(VENV_FOLDER)
$(BIN_FOLDER)/pip install -U "pip" "uv" "wheel" "pipx" "mxdev" "tox" "pre-commit"
$(BIN_FOLDER)/pip install -U "pip" "uv" "wheel" "pipx" "tox" "pre-commit"
if [ -d $(GIT_FOLDER) ]; then $(BIN_FOLDER)/pre-commit install; else echo "$(RED) Not installing pre-commit$(RESET)";fi

instance/etc/zope.ini: $(BIN_FOLDER)/pip ## Create instance configuration
Expand All @@ -61,41 +59,37 @@ instance/etc/zope.ini: $(BIN_FOLDER)/pip ## Create instance configuration
config: instance/etc/zope.ini

.PHONY: build-dev
build-dev: config ## pip install Plone packages
build-dev: config ## Install Plone packages
@echo "$(GREEN)==> Setup Build$(RESET)"
$(BIN_FOLDER)/mxdev -c mx.ini
$(BIN_FOLDER)/pipx run mxdev -c mx.ini
$(BIN_FOLDER)/uv pip install -r requirements-mxdev.txt

.PHONY: install
install: build-dev ## Install Plone 6.0
install: build-dev ## Install Plone

.PHONY: build
build: build-dev ## Install Plone 6.0
build: build-dev ## Install Plone

.PHONY: clean
clean: ## Remove old virtualenv and creates a new one
clean: ## Clean environment
@echo "$(RED)==> Cleaning environment and build$(RESET)"
rm -rf $(VENV_FOLDER) pyvenv.cfg .installed.cfg instance .tox .pytest_cache
rm -rf $(VENV_FOLDER) pyvenv.cfg .installed.cfg instance .tox .venv .pytest_cache

.PHONY: start
start: ## Start a Plone instance on localhost:8080
PYTHONWARNINGS=ignore $(BIN_FOLDER)/runwsgi instance/etc/zope.ini

.PHONY: console
console: instance/etc/zope.ini ## Start a zope console
console: instance/etc/zope.ini ## Start a console into a Plone instance
PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole debug instance/etc/zope.conf

.PHONY: create-site
create-site: instance/etc/zope.ini ## Create a new site from scratch
PYTHONWARNINGS=ignore $(BIN_FOLDER)/zconsole run instance/etc/zope.conf ./scripts/create_site.py

.PHONY: format
format: $(BIN_FOLDER)/tox ## Format the codebase according to our standards
.PHONY: check
check: $(BIN_FOLDER)/tox ## Check and fix code base according to Plone standards
@echo "$(GREEN)==> Format codebase$(RESET)"
$(BIN_FOLDER)/tox -e format

.PHONY: lint
lint: ## check code style
$(BIN_FOLDER)/tox -e lint

# i18n
Expand Down
12 changes: 5 additions & 7 deletions backend_addon/{{ cookiecutter.__folder_name }}/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@

## Features

### Content Types

- TBD

### Initial content

This package contains a simple volto configuration.
TODO: List our awesome features

## Installation

Expand All @@ -33,3 +27,7 @@ make create_site
## License

The project is licensed under GPLv2.

## Credits and Acknowledgements 🙏

Crafted with care by **{{ cookiecutter.__generator_signature }}**. A special thanks to all contributors and supporters!
6 changes: 4 additions & 2 deletions backend_addon/{{ cookiecutter.__folder_name }}/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"Environment :: Web Environment",
"Framework :: Plone",
"Framework :: Plone :: Addon",
{%- if cookiecutter.__feature_distribution == '1' %}
"Framework :: Plone :: Distribution",
{%- endif %}
"Framework :: Plone :: 6.0",
"Programming Language :: Python",
"Programming Language :: Python :: 3.8",
Expand Down Expand Up @@ -50,9 +52,9 @@
python_requires=">=3.8",
install_requires=[
"setuptools",
"Plone",
"Products.CMFPlone",
"plone.api",
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
"plone.restapi",
"plone.volto",
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<include package=".controlpanel" />
<include package=".indexers" />
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
<include package=".serializers" />
{%- endif %}
<include package=".vocabularies" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<configure xmlns="http://namespaces.zope.org/zope">

<!-- List all packages you depend here -->
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
<include package="plone.volto" />
<include package="plone.restapi" />
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<metadata>
<version>{{ cookiecutter.__profile_version }}</version>
<dependencies>
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
<dependency>profile-plone.restapi:default</dependency>
<dependency>profile-plone.volto:default</dependency>
{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUpZope(self, app, configurationContext):
# Load any other ZCML that is required for your tests.
# The z3c.autoinclude feature is disabled in the Plone fixture base
# layer.
{%- if cookiecutter.feature_headless == '1' %}
{%- if cookiecutter.__feature_headless == '1' %}
import plone.restapi

self.loadZCML(package=plone.restapi)
Expand Down
4 changes: 1 addition & 3 deletions frontend_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"npm_package_name": "{{ cookiecutter.frontend_addon_name }}",
"volto_version": "{{ 'Yes' | latest_volto }}",
"__folder_name": "{{ cookiecutter.frontend_addon_name }}",
"__gha_enable": true,
"__npm_package_name": "{{ cookiecutter.npm_package_name }}",
"__version_package": "1.0.0-alpha.0",
"__version_plone_volto": "{{ cookiecutter.volto_version }}",
"__version_plone_components": "1.7.0",
"__version_plone_scripts": "^3.6.1",
"__version_mrs_developer": "^2.2.0",
"__version_pnpm": "9.1.1",
"__version_pnpm_major": "9",
"__version_release_it": "^17.1.1",
"__gha_version_node": "20.x",
"__gha_version_checkout": "v4",
Expand All @@ -24,7 +23,6 @@
"__gha_version_background_action": "v1",
"__gha_version_upload_artifact": "v4",
"__gha_version_pages_deploy": "v4",
"__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-volto](https://github.com/plone/cookiecutter-volto/frontend_addon) on {{ cookiecutter.__generator_date_long }}",
"__prompts__": {
Expand Down
2 changes: 1 addition & 1 deletion frontend_addon/hooks/pre_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"author": "{{ cookiecutter.author }}",
"email": "{{ cookiecutter.email }}",
"github_organization": "{{ cookiecutter.github_organization }}",
"npm_package_name": "{{ cookiecutter.npm_package_name }}",
"npm_package_name": "{{ cookiecutter.__npm_package_name }}",
}


Expand Down
6 changes: 0 additions & 6 deletions frontend_addon/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
"""Pytest configuration."""

import re
from copy import deepcopy
from pathlib import Path
from typing import List

import pytest


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


@pytest.fixture(scope="session")
def cookieplone_root() -> dict:
"""Cookieplone root dir."""
Expand Down
14 changes: 14 additions & 0 deletions frontend_addon/tests/test_variables.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALLOWED_MISSING = []
ALLOWED_NOT_USED = []


def test_no_missing_variables(variables_missing):
"""Test no variable is missing from cookiecutter.json"""
assert len(variables_missing) == len(ALLOWED_MISSING)
assert variables_missing == ALLOWED_MISSING


def test_not_used_variables(variables_not_used):
"""Test variables are used."""
assert len(variables_not_used) == len(ALLOWED_NOT_USED)
assert variables_not_used == ALLOWED_NOT_USED
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
],
['@plone/registry', `${coreLocation}/packages/registry/src`],
[
'{{ cookiecutter.npm_package_name }}',
'{{ cookiecutter.__npm_package_name }}',
'./packages/{{ cookiecutter.frontend_addon_name }}/src',
],
],
Expand Down
2 changes: 1 addition & 1 deletion frontend_addon/{{ cookiecutter.__folder_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ PLONE_VERSION=6
DOCKER_IMAGE=plone/server-dev:${PLONE_VERSION}
DOCKER_IMAGE_ACCEPTANCE=plone/server-acceptance:${PLONE_VERSION}

ADDON_NAME='{{ cookiecutter.npm_package_name }}'
ADDON_NAME='{{ cookiecutter.__npm_package_name }}'

.PHONY: help
help: ## Show this help
Expand Down
Loading

0 comments on commit daed5a6

Please sign in to comment.