Skip to content

Commit

Permalink
Require cookieplone 0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
davisagli committed Nov 13, 2024
1 parent 766919a commit 4bea887
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 20 deletions.
6 changes: 4 additions & 2 deletions backend_addon/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Post generation hook."""

import os
from collections import OrderedDict
from copy import deepcopy
from pathlib import Path
import os

from cookieplone.settings import QUIET_MODE_VAR
from cookieplone.utils import console, files, git, plone
Expand All @@ -25,7 +25,9 @@ def handle_feature_headless(context: OrderedDict, output_dir: Path):


def handle_create_namespace_packages(context: OrderedDict, output_dir: Path):
plone.create_namespace_packages(output_dir / "src/packagename", context["python_package_name"])
plone.create_namespace_packages(
output_dir / "src/packagename", context["python_package_name"]
)


def handle_format(context: OrderedDict, output_dir: Path):
Expand Down
20 changes: 14 additions & 6 deletions backend_addon/hooks/pre_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import sys

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

HAS_COOKIEPLONE = True
except ModuleNotFoundError:
HAS_COOKIEPLONE = False
print("This template should be run with cookieplone")
sys.exit(1)
from packaging.version import Version


SUPPORTED_PYTHON_VERSIONS = [
Expand All @@ -23,6 +24,16 @@
def sanity_check() -> data.SanityCheckResults:
"""Run sanity checks on the system."""
checks = [
data.SanityCheck(
"Cookieplone",
lambda: (
""
if Version(cookieplone_version) > Version("0.8.0.dev0")
else "This template requires Cookieplone 0.8 or higher."
),
[],
"error",
),
data.SanityCheck(
"Python",
commands.check_python_version,
Expand All @@ -36,9 +47,6 @@ def sanity_check() -> data.SanityCheckResults:

def main():
"""Validate context."""
if not HAS_COOKIEPLONE:
print("This template should be run with cookieplone")
sys.exit(1)

msg = """
Creating a new Plone Addon
Expand Down
9 changes: 6 additions & 3 deletions backend_addon/tests/test_cutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ def cutter_result_two_namespaces(context, cookies_session) -> dict:
return cookies_session.bake(extra_context=new_context)



@pytest.mark.parametrize("file_path", PKG_SRC_FILES)
def test_pkg_src_files_generated_without_namespace(cutter_result_no_namespace, file_path: str):
def test_pkg_src_files_generated_without_namespace(
cutter_result_no_namespace, file_path: str
):
"""Check package contents with no namespaces."""
src_path = cutter_result_no_namespace.project_path / "src/addon"
path = src_path / file_path
Expand All @@ -116,7 +117,9 @@ def test_pkg_src_files_generated_without_namespace(cutter_result_no_namespace, f


@pytest.mark.parametrize("file_path", PKG_SRC_FILES)
def test_pkg_src_files_generated_with_two_namespaces(cutter_result_two_namespaces, file_path: str):
def test_pkg_src_files_generated_with_two_namespaces(
cutter_result_two_namespaces, file_path: str
):
"""Check package contents with 2 namespaces."""
src_path = cutter_result_two_namespaces.project_path / "src/foo/bar/baz"
path = src_path / file_path
Expand Down
4 changes: 3 additions & 1 deletion project/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def main():
func(new_context, output_dir)

# Create namespace packages
plone.create_namespace_packages(output_dir / "backend/src/packagename", context["python_package_name"])
plone.create_namespace_packages(
output_dir / "backend/src/packagename", context["python_package_name"]
)

# Run format
if backend_format:
Expand Down
25 changes: 18 additions & 7 deletions project/hooks/pre_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

import sys

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

HAS_COOKIEPLONE = True
try:
from cookieplone import __version__ as cookieplone_version
from cookieplone import data
from cookieplone.utils import commands, console, sanity
except ModuleNotFoundError:
print("This template should be run with cookieplone")
sys.exit(1)
from packaging.version import Version

SUPPORTED_PYTHON_VERSIONS = [
"3.8",
Expand All @@ -19,6 +23,16 @@
def sanity_check() -> data.SanityCheckResults:
"""Run sanity checks on the system."""
checks = [
data.SanityCheck(
"Cookieplone",
lambda: (
""
if Version(cookieplone_version) > Version("0.8.0.dev0")
else "This template requires Cookieplone 0.8 or higher."
),
[],
"error",
),
data.SanityCheck(
"Python",
commands.check_python_version,
Expand All @@ -41,9 +55,6 @@ def sanity_check() -> data.SanityCheckResults:

def main():
"""Validate context."""
if not HAS_COOKIEPLONE:
print("This template should be run with cookieplone")
sys.exit(1)

msg = """
Creating a new Plone Project
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ isort
pytest
pytest-cookies
pytest-jsonschema >= 1.0.0a2
cookieplone @ git+https://github.com/plone/cookieplone@main
cookieplone >= 0.8.0
GitPython
wheel

0 comments on commit 4bea887

Please sign in to comment.