We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 773c080 commit 8d962f8Copy full SHA for 8d962f8
cookieplone/cli.py
@@ -31,7 +31,7 @@ def validate_extra_context(value: list[str] | None = None) -> list[str]:
31
return value
32
33
34
-def parse_extra_content(value: list[str]) -> dict:
+def parse_extra_context(value: list[str]) -> dict:
35
"""Parse extra content and return a dictionary with options."""
36
if not value:
37
return {}
@@ -151,17 +151,20 @@ def cli(
151
if not output_dir:
152
output_dir = Path().cwd()
153
154
+ # Annotate extra_context
155
+ ## We do this to always get the latest information about the repository
156
+ ## and template being used
157
+ extra_context = parse_extra_context(extra_context)
158
+ extra_context["__generator_sha"] = internal.repo_sha(repo_path)
159
+ extra_context["__generator_signature"] = internal.signature_md(repo_path)
160
+ extra_context["__cookieplone_repository_path"] = f"{repo_path}"
161
+ extra_context["__cookieplone_template"] = f"{template}"
162
+
163
replay_file = files.resolve_path(replay_file) if replay_file else replay_file
164
if replay_file and replay_file.exists():
165
# Use replay_file
166
replay = replay_file
- elif not replay:
- # Annotate extra_context
- extra_context = parse_extra_content(extra_context)
- extra_context["__generator_sha"] = internal.repo_sha(repo_path)
- extra_context["__generator_signature"] = internal.signature_md(repo_path)
- extra_context["__cookieplone_repository_path"] = f"{repo_path}"
- extra_context["__cookieplone_template"] = f"{template}"
167
168
# Run generator
169
try:
170
generate(
cookieplone/filters/__init__.py
@@ -35,6 +35,13 @@ def package_namespaces(v) -> str:
return ", ".join(f'"{item}"' for item in result)
38
+@simple_filter
39
+def package_namespace_path(v: str) -> str:
40
+ """Return path to the package namespace including the src directory."""
41
+ top_namespace = v.split(".")[0]
42
+ return f"src/{top_namespace}"
43
44
45
@simple_filter
46
def package_path(v) -> str:
47
"""Return path to the package code within the src directory."""
@@ -139,3 +146,9 @@ def as_semver(v: str) -> str:
139
146
def unscoped_package_name(v: str) -> str:
140
147
"""Return the unscoped name for a given package."""
141
148
return npm.unscoped_package_name(v)
149
150
+def as_major_minor(v: str) -> str:
+ """Return a version in the major.minor format."""
+ return versions.format_as_major_minor(v)
cookieplone/utils/versions.py
@@ -145,3 +145,12 @@ def python_version_for_plone(plone_version: str) -> str:
145
"""Return the latest supported Python version for a given Plone version."""
version_support = python_versions_for_plone(plone_version)
return version_support.latest
+def format_as_major_minor(version: str) -> str:
+ """Format a list of versions as major.minor."""
+ # Handle "versions" used in tests / constraints
+ if "-" in version:
+ version = version.split("-")[0]
+ v = Version(version)
+ return f"{v.major}.{v.minor}"
news/+as_major_minor.feature
@@ -0,0 +1 @@
1
+Add `as_major_minor` filter. @ericof
news/+extra_context.feature
+Parse extra-context information even if we are running with a replay file. @ericof
news/+package_namespace_path.feature
+Add `package_namespace_path` filter. @ericof
tests/test_cli.py
@@ -12,8 +12,8 @@
12
(["foo=1", "bar=2"], {"foo": "1", "bar": "2"}),
13
],
14
)
15
-def test_parse_extra_content(value: list[str], expected: dict):
16
- func = cli.parse_extra_content
+def test_parse_extra_context(value: list[str], expected: dict):
+ func = cli.parse_extra_context
17
assert func(value) == expected
18
19
tests/test_filters.py
@@ -74,6 +74,26 @@ def func(filter_: str) -> Path:
74
"{{'@plone/volto' | unscoped_package_name}}",
75
"volto",
76
77
+ ["as_major_minor", "{{'1.0.0a0' | as_major_minor}}", "1.0"],
78
+ ["as_major_minor", "{{'6.1.1rc1' | as_major_minor}}", "6.1"],
79
+ ["as_major_minor", "{{'1' | as_major_minor}}", "1.0"],
80
+ ["package_namespace_path", "{{'foo' | package_namespace_path}}", "src/foo"],
81
+ ["package_namespace_path", "{{'foo.bar' | package_namespace_path}}", "src/foo"],
82
+ [
83
+ "package_namespace_path",
84
+ "{{'foo.bar.foobar' | package_namespace_path}}",
85
+ "src/foo",
86
+ ],
87
88
89
+ "{{'collective.addon' | package_namespace_path}}",
90
+ "src/collective",
91
92
93
94
+ "{{'collective_addon' | package_namespace_path}}",
95
+ "src/collective_addon",
96
97
98
99
def test_filters(generate_context_file, filter_: str, raw: str, expected: str):
tests/utils/test_versions.py
@@ -275,3 +275,25 @@ def test_convert_pep440_semver(pep440: str, expected: str):
275
func = versions.convert_pep440_semver
276
result = func(pep440)
277
assert result == expected
278
279
280
+@pytest.mark.parametrize(
281
+ "version,expected",
282
283
+ ["1.0.0a0", "1.0"],
284
+ ["1.0.0b1", "1.0"],
285
+ ["1.0.0rc1", "1.0"],
286
+ ["1.0.0rc1.dev0", "1.0"],
287
+ ["1.0.0", "1.0"],
288
+ ["6.1.1.dev0", "6.1"],
289
+ ["6.1.1.post0", "6.1"],
290
+ ["6.1-dev", "6.1"],
291
+ ["6.1-latest", "6.1"],
292
+ ["202503.1", "202503.1"],
293
+ ["202512.1", "202512.1"],
294
295
+)
296
+def test_format_as_major_minor(version: str, expected: str):
297
+ func = versions.format_as_major_minor
298
+ result = func(version)
299
+ assert result == expected
0 commit comments