Skip to content

Commit 147c2d8

Browse files
ericofstevepiercydavisagli
authored
Cleanup of precommit (#167)
* WIP: Cleanup of precommit * Update zpretty checks * Fix reference to tox * Apply suggestions from code review Co-authored-by: Steve Piercy <[email protected]> Co-authored-by: David Glick <[email protected]> * Use package name for locales * Add make target to clean the frontend folder * Bump Python project version to 3.12 * README fix * Update vscode settings * Set ruff.target-version * Re-use the plone version provided by the user * Enable cache for uv installation * Refactor Makefile * Update Makefile for backend in a project * Fix update-example-content target * Fix BASE_TAG calculation on GHA * Add repository.toml to project * Update repository.toml * Update repository.toml * Project fixes * Reuse variables * add __python_version_identifier to the backend_addon * Update README and add information about the format / lint available on a project * Apply suggestions from code review Co-authored-by: Steve Piercy <[email protected]> * Add check for cookieplone version * Apply suggestions from code review Co-authored-by: Steve Piercy <[email protected]> * Update cookieplone to 0.9.1 * Update volto examples to 18.10.0 * Use plone.autoinclude (Fixes #175) * Fix hatch build options * fix 'duplicate key in table ' * Use cookieplone 0.9.3 * Add uv to requirements.txt * Use tomli (to support Python 3.10) * Fix backend tests * Force ruff to use only alphabetical order for imports * Pin cookiecutter-zope-instance to version 2.1.1 * Pin cookiecutter-zope-instance to version 2.1.1 * Improve error message for min cookieplone version --------- Co-authored-by: Steve Piercy <[email protected]> Co-authored-by: David Glick <[email protected]>
1 parent 2595cfc commit 147c2d8

File tree

97 files changed

+1591
-1509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1591
-1509
lines changed

.github/workflows/backend_addon.yml

+40
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ on:
1212
- ".github/workflows/backend_addon.yml"
1313
workflow_dispatch:
1414

15+
env:
16+
python-version: "3.12"
17+
1518
jobs:
1619
generation:
1720
runs-on: ubuntu-latest
@@ -47,3 +50,40 @@ jobs:
4750
run: |
4851
cd backend_addon
4952
python -m pytest tests
53+
54+
functional:
55+
runs-on: ubuntu-latest
56+
57+
steps:
58+
- name: Checkout codebase
59+
uses: actions/checkout@v4
60+
61+
62+
- name: Install the latest version of uv
63+
uses: astral-sh/setup-uv@v5
64+
with:
65+
python-version: ${{ env.python-version }}
66+
enable-cache: false
67+
68+
- name: Generate
69+
run: |
70+
COOKIEPLONE_REPOSITORY=$(pwd) uvx cookieplone backend_addon --no-input
71+
72+
- name: Restore uv cache
73+
uses: actions/cache@v4
74+
with:
75+
path: ${{ env.UV_CACHE_DIR }}
76+
key: uv-${{ runner.os }}-${{ env.python-version }}-${{ hashFiles('collective.addon/pyproject.toml') }}
77+
restore-keys: |
78+
uv-${{ runner.os }}-${{ env.python-version }}-${{ hashFiles('collective.addon/pyproject.toml') }}
79+
uv-${{ runner.os }}-${{ env.python-version }}
80+
81+
- name: Install generated package
82+
working-directory: collective.addon
83+
run: |
84+
make install
85+
86+
- name: Run unit tests
87+
working-directory: collective.addon
88+
run: |
89+
make test

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<div align="center">
1010

11-
![GitHub](https://img.shields.io/github/license/plone/cookiecutter-plone)
11+
![GitHub](https://img.shields.io/github/license/plone/cookieplone-templates)
1212
[![Black code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
1313

1414
</div>
@@ -34,7 +34,7 @@ pip install pipx
3434
Select a template with the following command:
3535

3636
```shell
37-
pipx run cookieplone
37+
uvx cookieplone
3838
```
3939

4040
```text

backend_addon/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
collective.addon

backend_addon/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ format: $(BIN_FOLDER)/cookieplone ## Format code
4141
generate: $(BIN_FOLDER)/cookieplone ## Create a sample package
4242
@echo "$(GREEN)==> Creating new test package$(RESET)"
4343
rm -rf $(ADDON_FOLDER_NAME)
44-
COOKIEPLONE_REPOSITORY=$(BASE_FOLDER) $(BIN_FOLDER)/cookieplone $(TEMPLATE) --no_input
44+
COOKIEPLONE_REPOSITORY=$(BASE_FOLDER) $(BIN_FOLDER)/cookieplone $(TEMPLATE) --no-input
4545

4646
.PHONY: test
4747
test: $(BIN_FOLDER)/cookieplone ## Create a sample package and tests it

backend_addon/README.md

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[![Cookieplone Backend Add-on CI](https://github.com/plone/cookieplone-templates/actions/workflows/backend_addon.yml/badge.svg)](https://github.com/plone/cookieplone-templates/actions/workflows/backend_addon.yml)
2-
[![Built with Cookiecutter](https://img.shields.io/badge/built%20with-Cookiecutter-ff69b4.svg?logo=cookiecutter)](https://github.com/plone/cookieplone-templates/)
3-
![GitHub](https://img.shields.io/github/license/plone/cookiecutter-plone)
2+
[![Built with Cookieplone](https://img.shields.io/badge/built%20with-Cookiecutter-ff69b4.svg?logo=cookiecutter)](https://github.com/plone/cookieplone-templates/)
3+
![GitHub](https://img.shields.io/github/license/plone/cookieplone-templates)
44
[![Black code style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
55

66
# Cookieplone Backend Add-on
@@ -15,16 +15,19 @@ Powered by [cookieplone](https://github.com/plone/cookieplone) and [Cookiecutter
1515

1616
### Installation Guide 🛠️
1717

18-
1. **pipx**
18+
1. **uv**
19+
20+
[`uv`](https://docs.astral.sh/uv/) is the recommended tool for managing Python versions and project dependencies.
21+
22+
To install `uv`, use the following command, or visit the [`uv` installation page](https://docs.astral.sh/uv/getting-started/installation/) for alternative methods:
1923

2024
```shell
21-
pip install pipx
22-
```
25+
curl -LsSf https://astral.sh/uv/install.sh | sh
2326

2427
### Generate Your Plone Add-on 🎉
2528

2629
```shell
27-
pipx run cookieplone backend_addon
30+
uvx cookieplone backend_addon
2831
```
2932

3033
## Project Generation Options

backend_addon/cookiecutter.json

+19-5
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,27 @@
99
"python_package_name": "{{ cookiecutter.github_organization|lower }}.{{ cookiecutter.title|replace(' ', '')|replace('-', '_')|replace('.', '')|lower }}",
1010
"__year": "{% now 'local', '%Y' %}",
1111
"feature_headless": ["1", "0"],
12+
"__project_slug": "{{ cookiecutter.python_package_name }}",
13+
"__repository_url": "https://github.com/{{ cookiecutter.github_organization }}/{{ cookiecutter.__project_slug }}",
1214
"__feature_headless": "{{ cookiecutter.feature_headless }}",
1315
"__feature_distribution": "0",
14-
"__package_namespaces": "{{ cookiecutter.python_package_name | package_namespaces }}",
1516
"__package_path": "{{ cookiecutter.python_package_name | package_path }}",
1617
"__folder_name": "{{ cookiecutter.python_package_name }}",
1718
"__python_package_name_upper": "{{ cookiecutter.python_package_name | pascal_case }}",
19+
"__supported_versions_python": ["3.10", "3.11", "3.12", "3.13"],
20+
"__supported_versions_plone": ["6.0", "6.1"],
21+
"__backend_managed_by_uv": "false",
22+
"__gha_version_checkout": "v4",
23+
"__gha_version_setup_uv": "v5",
24+
"__gha_version_cache": "v4",
25+
"__gha_python_versions": ["3.10", "3.11", "3.12", "3.13"],
26+
"__gha_plone_versions": ["6.1-latest", "6.0-latest"],
27+
"__gha_python_version": "3.12",
28+
"__python_version_identifier": "{{ cookiecutter.__supported_versions_python[0] | replace('.', '') }}",
29+
"__gha_plone_version": "{{ cookiecutter.plone_version }}",
1830
"__profile_language": "en",
1931
"__version_package": "1.0.0a0",
2032
"__profile_version": "1000",
21-
"__generator_date_long": "{% now 'utc', '%Y-%m-%d %H:%M:%S' %}",
22-
"__generator_signature": "This was generated by the [cookieplone-templates backend_addon template](https://github.com/plone/cookieplone-templates/tree/main/backend_addon) on {{ cookiecutter.__generator_date_long }}",
2333
"__backend_addon_git_initialize": "1",
2434
"__backend_addon_format": "1",
2535
"__prompts__": {
@@ -42,9 +52,13 @@
4252
"cookieplone.filters.latest_plone",
4353
"cookieplone.filters.use_prerelease_versions",
4454
"cookieplone.filters.pascal_case",
45-
"cookieplone.filters.package_namespaces",
55+
"cookieplone.filters.package_namespace_path",
4656
"cookieplone.filters.package_path"
4757
],
4858
"__cookieplone_repository_path": "",
49-
"__cookieplone_template": ""
59+
"__cookieplone_template": "backend_addon",
60+
"__generator_sha": "",
61+
"__generator_template_url": "https://github.com/plone/cookieplone-templates/tree/main/{{ cookiecutter.__cookieplone_template }}",
62+
"__generator_date_long": "{% now 'utc', '%Y-%m-%d %H:%M:%S' %}",
63+
"__generator_signature": "This was generated by [the cookieplone-templates {{ cookiecutter.__cookieplone_template }} template]({{ cookiecutter.__generator_template_url }}) on {{ cookiecutter.__generator_date_long }}"
5064
}

backend_addon/hooks/post_gen_project.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def handle_feature_headless(context: OrderedDict, output_dir: Path):
2626

2727
def handle_create_namespace_packages(context: OrderedDict, output_dir: Path):
2828
plone.create_namespace_packages(
29-
output_dir / "src/packagename", context["python_package_name"]
29+
output_dir / "src/packagename", context["python_package_name"], style="pkgutil"
3030
)
3131

3232

backend_addon/hooks/pre_prompt.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
sys.exit(1)
1212
from packaging.version import Version
1313

14-
15-
SUPPORTED_PYTHON_VERSIONS = [
16-
"3.10",
17-
"3.11",
18-
"3.12",
19-
"3.13"
20-
]
14+
SUPPORTED_PYTHON_VERSIONS = ["3.10", "3.11", "3.12", "3.13"]
15+
MIN_COOKIEPLONE = "0.9.3"
16+
COOKIEPLONE_INSTALLATION = (
17+
"https://github.com/plone/cookieplone/blob/main/README.md#installation-"
18+
)
2119

2220

2321
def sanity_check() -> data.SanityCheckResults:
@@ -27,16 +25,20 @@ def sanity_check() -> data.SanityCheckResults:
2725
"Cookieplone",
2826
lambda: (
2927
""
30-
if Version(cookieplone_version) > Version("0.8.0.dev0")
31-
else "This template requires Cookieplone 0.8 or higher."
28+
if Version(cookieplone_version) >= Version(MIN_COOKIEPLONE)
29+
else (
30+
f"This template requires Cookieplone {MIN_COOKIEPLONE} "
31+
"or higher. Upgrade information available "
32+
f"at {COOKIEPLONE_INSTALLATION}."
33+
)
3234
),
3335
[],
3436
"error",
3537
),
3638
data.SanityCheck(
37-
"Python",
38-
commands.check_python_version,
39-
[SUPPORTED_PYTHON_VERSIONS],
39+
"UV",
40+
commands.check_command_is_available,
41+
["uv"],
4042
"error",
4143
),
4244
data.SanityCheck("git", commands.check_command_is_available, ["git"], "error"),

backend_addon/tests/conftest.py

+19-21
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,18 @@
88

99
ROOT_FILES = [
1010
".editorconfig",
11-
".github/workflows/meta.yml",
11+
".github/workflows/ci.yml",
1212
".gitignore",
13-
".meta.toml",
14-
".pre-commit-config.yaml",
15-
"CHANGES.md",
16-
"constraints.txt",
13+
"CHANGELOG.md",
1714
"CONTRIBUTORS.md",
1815
"instance.yaml",
1916
"LICENSE.GPL",
2017
"LICENSE.md",
2118
"Makefile",
22-
"MANIFEST.in",
2319
"mx.ini",
2420
"pyproject.toml",
2521
"README.md",
26-
"requirements.txt",
2722
"scripts/create_site.py",
28-
"setup.py",
29-
"tox.ini",
3023
]
3124

3225

@@ -39,6 +32,8 @@
3932
"dependencies.zcml",
4033
"indexers/__init__.py",
4134
"indexers/configure.zcml",
35+
"locales/__init__.py",
36+
"locales/__main__.py",
4237
"profiles/default/browserlayer.xml",
4338
"profiles/default/catalog.xml",
4439
"profiles/default/controlpanel.xml",
@@ -73,19 +68,22 @@ def cookieplone_root() -> dict:
7368

7469

7570
@pytest.fixture(scope="session")
76-
def context(cookieplone_root) -> dict:
71+
def context(annotate_context, cookieplone_root) -> dict:
7772
"""Cookiecutter context."""
78-
return {
79-
"title": "Addon",
80-
"description": "A Tech blog.",
81-
"github_organization": "collective",
82-
"python_package_name": "collective.addon",
83-
"author": "Plone Collective",
84-
"email": "[email protected]",
85-
"feature_headless": "1",
86-
"__backend_addon_git_initialize": "1",
87-
"__cookieplone_repository_path": f"{cookieplone_root}",
88-
}
73+
return annotate_context(
74+
{
75+
"title": "Addon",
76+
"description": "A Tech blog.",
77+
"github_organization": "collective",
78+
"python_package_name": "collective.addon",
79+
"author": "Plone Collective",
80+
"email": "[email protected]",
81+
"feature_headless": "1",
82+
"__backend_addon_git_initialize": "1",
83+
},
84+
cookieplone_root,
85+
"backend_addon",
86+
)
8987

9088

9189
@pytest.fixture(scope="session")

backend_addon/tests/test_cutter.py

-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def test_pkg_src_feature_files_generated(cutter_result, file_path: str):
6161
@pytest.mark.parametrize(
6262
"file_path,schema_name",
6363
[
64-
[".github/workflows/meta.yml", "github-workflow"],
65-
[".pre-commit-config.yaml", "pre-commit-config"],
6664
["pyproject.toml", "pyproject"],
6765
],
6866
)

backend_addon/tests/test_cutter_distribution.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ def test_variable_substitution(build_files_list, variable_pattern, cutter_result
3131
def test_trove_classifier_set(cutter_result):
3232
"""Check feature-specific files were not generated."""
3333
trove_classifier = "Framework :: Plone :: Distribution"
34-
setup_py = cutter_result.project_path / "setup.py"
35-
assert trove_classifier in setup_py.read_text()
34+
pyproject = cutter_result.project_path / "pyproject.toml"
35+
assert trove_classifier in pyproject.read_text()

backend_addon/tests/test_variables.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ALLOWED_MISSING = []
2-
ALLOWED_NOT_USED = []
2+
ALLOWED_NOT_USED = ["__generator_sha"]
33

44

55
def test_no_missing_variables(variables_missing):
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
# Generated from:
2-
# https://github.com/plone/meta/tree/master/config/default
3-
# See the inline comments on how to expand/tweak this configuration file
4-
#
1+
52
# EditorConfig Configuration file, for more details see:
6-
# http://EditorConfig.org
3+
# https://EditorConfig.org
74
# EditorConfig is a convention description, that could be interpreted
85
# by multiple editors to enforce common coding conventions for specific
96
# file types
@@ -22,33 +19,17 @@ trim_trailing_whitespace = true
2219
charset = utf-8
2320
# Indent style default
2421
indent_style = space
25-
# Max Line Length - a hard line wrap, should be disabled
26-
max_line_length = off
2722

2823
[*.{py,cfg,ini}]
2924
# 4 space indentation
3025
indent_size = 4
3126

32-
[*.{yml,zpt,pt,dtml,zcml}]
33-
# 2 space indentation
34-
indent_size = 2
35-
36-
[*.{json,jsonl,js,jsx,ts,tsx,css,less,scss,html}] # Frontend development
27+
[*.{html,dtml,pt,zpt,xml,zcml,js,json,ts,less,scss,css,sass,yml,yaml}]
3728
# 2 space indentation
3829
indent_size = 2
39-
max_line_length = 80
4030

4131
[{Makefile,.gitmodules}]
4232
# Tab indentation (no size specified, but view as 4 spaces)
4333
indent_style = tab
4434
indent_size = unset
4535
tab_width = unset
46-
47-
48-
##
49-
# Add extra configuration options in .meta.toml:
50-
# [editorconfig]
51-
# extra_lines = """
52-
# _your own configuration lines_
53-
# """
54-
##

0 commit comments

Comments
 (0)