Skip to content

Commit

Permalink
Use uv for package installation, include example content
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed May 27, 2024
1 parent 24b906c commit 367e131
Show file tree
Hide file tree
Showing 33 changed files with 914 additions and 41 deletions.
2 changes: 1 addition & 1 deletion backend_addon/{{ cookiecutter.__folder_name }}/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var/
/sources/
/venv/
.installed.txt

.lock

##
# Add extra configuration options in .meta.toml:
Expand Down
5 changes: 5 additions & 0 deletions backend_addon/{{ cookiecutter.__folder_name }}/.meta.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ dependencies_mappings = [
]
dependencies_ignores = "['plone.app.iterate', 'plone.app.upgrade', 'plone.volto', 'zestreleaser.towncrier', 'zest.releaser', 'pytest-cov']"

[gitignore]
extra_lines = """
.lock
"""

[tox]
test_runner = "pytest"
test_path = "/tests"
Expand Down
10 changes: 5 additions & 5 deletions backend_addon/{{ cookiecutter.__folder_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ all: build
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}'

$(BIN_FOLDER)/pip $(BIN_FOLDER)/tox $(BIN_FOLDER)/mxdev:
$(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" "wheel" "cookiecutter" "mxdev" "tox" "pre-commit"
$(BIN_FOLDER)/pip install -U "pip" "uv" "wheel" "pipx" "mxdev" "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
@echo "$(GREEN)==> Create instance configuration$(RESET)"
$(BIN_FOLDER)/cookiecutter -f --no-input --config-file instance.yaml gh:plone/cookiecutter-zope-instance
$(BIN_FOLDER)/pipx run cookiecutter -f --no-input --config-file instance.yaml gh:plone/cookiecutter-zope-instance

.PHONY: config
config: instance/etc/zope.ini
Expand All @@ -64,7 +64,7 @@ config: instance/etc/zope.ini
build-dev: config ## pip install Plone packages
@echo "$(GREEN)==> Setup Build$(RESET)"
$(BIN_FOLDER)/mxdev -c mx.ini
$(BIN_FOLDER)/pip install -r requirements-mxdev.txt
$(BIN_FOLDER)/uv pip install -r requirements-mxdev.txt

.PHONY: install
install: build-dev ## Install Plone 6.0
Expand Down Expand Up @@ -101,7 +101,7 @@ lint: ## check code style
# i18n
$(BIN_FOLDER)/i18ndude: $(BIN_FOLDER)/pip
@echo "$(GREEN)==> Install translation tools$(RESET)"
$(BIN_FOLDER)/pip install i18ndude
$(BIN_FOLDER)/uv pip install i18ndude

.PHONY: i18n
i18n: $(BIN_FOLDER)/i18ndude ## Update locales
Expand Down
1 change: 1 addition & 0 deletions backend_addon/{{ cookiecutter.__folder_name }}/mx.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
; to learn more about mxdev visit https://pypi.org/project/mxdev/

[settings]
main-package = -e .[test]
; example how to override a package version
; version-overrides =
; example.package==2.1.0a2
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
-c constraints.txt
-e ".[test]"
3 changes: 3 additions & 0 deletions project/tests/test_project_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def test_backend_top_level_files(cutter_result, filename: str):
"src/plonegov/ploneorgbr/dependencies.zcml",
"src/plonegov/ploneorgbr/permissions.zcml",
"src/plonegov/ploneorgbr/profiles.zcml",
"src/plonegov/ploneorgbr/profiles/initial/metadata.xml",
"src/plonegov/ploneorgbr/setuphandlers/initial.py",
"src/plonegov/ploneorgbr/setuphandlers/examplecontent/.gitkeep",
"src/plonegov/ploneorgbr/testing.py",
"tests/conftest.py",
"tests/setup/test_setup_install.py",
Expand Down
11 changes: 10 additions & 1 deletion project/{{ cookiecutter.__folder_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ GIT_FOLDER=$(CURRENT_DIR)/.git
PROJECT_NAME={{ cookiecutter.project_slug }}
STACK_NAME={{ cookiecutter.__devops_stack_name }}

VOLTO_VERSION = $(shell cat frontend/mrs.developer.json | python -c "import sys, json; print(json.load(sys.stdin)['core']['tag'])")
PLONE_VERSION=$(shell cat backend/version.txt)

PRE_COMMIT=pipx run --spec 'pre-commit=={{ cookiecutter.__pre_commit_version }}' pre-commit

# We like colors
Expand All @@ -23,6 +26,8 @@ GREEN=`tput setaf 2`
RESET=`tput sgr0`
YELLOW=`tput setaf 3`

VOLTO_VERSION=$(VOLTO_VERSION) PLONE_VERSION=$(PLONE_VERSION)

.PHONY: all
all: install

Expand Down Expand Up @@ -68,6 +73,10 @@ backend-build: ## Build Backend
backend-create-site: ## Create a Plone site with default content
$(MAKE) -C "./backend/" create-site

.PHONY: backend-update-example-content
backend-update-example-content: ## Export example content inside package
$(MAKE) -C "./backend/" update-example-content

.PHONY: backend-start
backend-start: ## Start Plone Backend
$(MAKE) -C "./backend/" start
Expand Down Expand Up @@ -120,7 +129,7 @@ build-images: ## Build docker images
.PHONY: stack-start
stack-start: ## Local Stack: Start Services
@echo "Start local Docker stack"
@docker compose -f docker-compose.yml up -d --build
VOLTO_VERSION=$(VOLTO_VERSION) PLONE_VERSION=$(PLONE_VERSION) docker compose -f docker-compose.yml up -d --build
@echo "Now visit: http://{{ cookiecutter.project_slug }}.localhost"

.PHONY: start-stack
Expand Down
6 changes: 5 additions & 1 deletion project/{{ cookiecutter.__folder_name }}/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
version: '3.8'
name: {{ cookiecutter.__devops_compose_name }}

services:
Expand Down Expand Up @@ -55,10 +54,13 @@ services:
- traefik.http.services.svc-varnish.loadbalancer.server.port=80
depends_on:
- backend

{%- endif %}
frontend:
build:
context: ./frontend
args:
- VOLTO_VERSION=${VOLTO_VERSION}
environment:
RAZZLE_INTERNAL_API_PATH: http://backend:8080/Plone
depends_on:
Expand Down Expand Up @@ -91,6 +93,8 @@ services:
backend:
build:
context: ./backend
args:
- PLONE_VERSION=${PLONE_VERSION}
environment:
RELSTORAGE_DSN: "dbname='${DB_NAME:-plone}' user='${DB_NAME:-plone}' host='${DB_HOST:-db}' password='${DB_PASSWORD:-{{ cookiecutter.__devops_db_password }}}' port='${DB_PORT:-5432}'"
depends_on:
Expand Down
2 changes: 2 additions & 0 deletions sub/project_settings/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"python_package_name": "{{ cookiecutter.project_slug|replace(' ', '')|replace('-', '.') }}",
"frontend_addon_name": "volto-{{ cookiecutter.python_package_name|replace('_', '-')|replace('.', '-') }}",
"language_code": "en",
"plone_version": "{{ 'No' | latest_plone }}",
"volto_version": "{{ 'Yes' | latest_volto }}",
"github_organization": "collective",
"container_registry": ["github", "docker_hub", "gitlab"],
"__version_package": "1.0.0a0",
"__npm_package_name": "{{ cookiecutter.frontend_addon_name }}",
"__container_registry_prefix": "{{ cookiecutter.container_registry | image_prefix }}",
"__container_image_prefix": "{{ cookiecutter.__container_registry_prefix }}{{ cookiecutter.github_organization }}/{{ cookiecutter.project_slug }}",
Expand Down
65 changes: 48 additions & 17 deletions sub/project_settings/tests/test_cutter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Test cookiecutter generation with all features enabled."""

from pathlib import Path
import json

import pytest

Expand All @@ -24,23 +24,54 @@ def test_variable_substitution(build_files_list, variable_pattern, cutter_result
assert match is None, msg


@pytest.mark.parametrize(
"file_path",
[
"backend/src/project/title/locales/__init__.py",
"backend/src/project/title/locales/en/LC_MESSAGES/project.title.po",
"backend/src/project/title/locales/project.title.pot",
"backend/src/project/title/locales/update.py",
"backend/src/project/title/profiles/default/registry/plone.base.interfaces.controlpanel.IMailSchema.xml", # noQA
"backend/src/project/title/profiles/default/registry/plone.base.interfaces.controlpanel.ISiteSchema.xml", # noQA
"backend/src/project/title/profiles/default/registry/plone.i18n.interfaces.ILanguageSchema.xml",
"frontend/.dockerignore",
"frontend/Dockerfile",
"frontend/Makefile",
"frontend/packages/volto-project-title/src/index.js",
],
)
GENERATED_FILES = [
"backend/.dockerignore",
"backend/constraints.txt",
"backend/Dockerfile.acceptance",
"backend/Dockerfile",
"backend/Makefile",
"backend/requirements-docker.txt",
"backend/scripts/create_site.py",
"backend/setup.py",
"backend/src/project/title/locales/__init__.py",
"backend/src/project/title/locales/en/LC_MESSAGES/project.title.po",
"backend/src/project/title/locales/project.title.pot",
"backend/src/project/title/locales/update.py",
"backend/src/project/title/profiles/default/registry/plone.base.interfaces.controlpanel.IMailSchema.xml", # noQA
"backend/src/project/title/profiles/default/registry/plone.base.interfaces.controlpanel.ISiteSchema.xml", # noQA
"backend/src/project/title/profiles/default/registry/plone.i18n.interfaces.ILanguageSchema.xml",
"backend/src/project/title/profiles/initial/metadata.xml",
"backend/src/project/title/setuphandlers/examplecontent/.gitkeep",
"backend/src/project/title/setuphandlers/examplecontent/content/__metadata__.json",
"backend/src/project/title/setuphandlers/examplecontent/content/a58ccead718140c1baa98d43595fc3e6/data.json",
"backend/src/project/title/setuphandlers/examplecontent/content/a58ccead718140c1baa98d43595fc3e6/image/plone-foundation.png",
"backend/src/project/title/setuphandlers/examplecontent/content/a720393b3c0240e5bd27c43fcd2cfd1e/data.json",
"backend/src/project/title/setuphandlers/examplecontent/content/plone_site_root/data.json",
"backend/src/project/title/setuphandlers/examplecontent/discussions.json",
"backend/src/project/title/setuphandlers/examplecontent/portlets.json",
"backend/src/project/title/setuphandlers/examplecontent/principals.json",
"backend/src/project/title/setuphandlers/examplecontent/redirects.json",
"backend/src/project/title/setuphandlers/examplecontent/relations.json",
"backend/src/project/title/setuphandlers/examplecontent/translations.json",
"backend/src/project/title/setuphandlers/initial.py",
"frontend/.dockerignore",
"frontend/Dockerfile",
"frontend/Makefile",
"frontend/packages/volto-project-title/src/index.js",
]


@pytest.mark.parametrize("file_path", GENERATED_FILES)
def test_created_files(cutter_result, file_path: str):
path = (cutter_result.project_path / file_path).resolve()
assert path.exists()
assert path.is_file()


@pytest.mark.parametrize(
"file_path", [f for f in GENERATED_FILES if f.endswith(".json")]
)
def test_json_files_are_valid(cutter_result, file_path: str):
path = (cutter_result.project_path / file_path).resolve()
result = json.loads(path.read_text())
assert isinstance(result, (dict, list))
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ FROM plone/server-builder:${PLONE_VERSION} as builder

WORKDIR /app


# Add local code
COPY . .
COPY scripts/ scripts/
COPY . src

# Install local requirements and pre-compile mo files
RUN <<EOT
set -e
bin/pip install mxdev
mv requirements-docker.txt requirements.txt
sed -i 's/-e .\[test\]/src\/./g' mx.ini
bin/mxdev -c mx.ini
bin/pip install -r requirements-mxdev.txt
bin/python /compile_mo.py
bin/pip install mxdev uv
mv src/requirements-docker.txt src/requirements.txt
sed -i 's/-e .\[test\]/./g' src/mx.ini
cd /app/src
../bin/mxdev -c mx.ini
../bin/uv pip install -r requirements-mxdev.txt
../bin/python /compile_mo.py
cd /app
rm -Rf src/
EOT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@ FROM plone/server-builder:${PLONE_VERSION} as builder

WORKDIR /app


# Add local code
COPY . .
COPY scripts/ scripts/
COPY . src

# Install local requirements and pre-compile mo files
RUN <<EOT
set -e
bin/pip install mxdev
mv requirements-docker.txt requirements.txt
sed -i 's/-e .\[test\]/src\/./g' mx.ini
bin/mxdev -c mx.ini
bin/pip install -r requirements-mxdev.txt
bin/pip install plone.app.robotframework>=2.0.0
bin/python /compile_mo.py
bin/pip install mxdev uv
mv src/requirements-docker.txt src/requirements.txt
sed -i 's/-e .\[test\]/./g' src/mx.ini
cd /app/src
../bin/mxdev -c mx.ini
../bin/uv pip install -r requirements-mxdev.txt
../bin/python /compile_mo.py
cd /app
rm -Rf src/
EOT

Expand Down
Loading

0 comments on commit 367e131

Please sign in to comment.