Skip to content

Commit

Permalink
Flag to add distribution trove classifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ericof committed May 29, 2024
1 parent 9937161 commit 0d0c54f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions backend_addon/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"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 }}",
Expand Down
9 changes: 9 additions & 0 deletions backend_addon/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,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
4 changes: 3 additions & 1 deletion 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,7 +52,7 @@
python_requires=">=3.8",
install_requires=[
"setuptools",
"Plone",
"Products.CMFPlone",
"plone.api",
{%- if cookiecutter.__feature_headless == '1' %}
"plone.restapi",
Expand Down

0 comments on commit 0d0c54f

Please sign in to comment.