Skip to content

Commit 25450ea

Browse files
committed
refactor!: replace jinja2-ansible-filters by jinja2-copier-extension
1 parent 1b4bbb7 commit 25450ea

File tree

6 files changed

+20
-42
lines changed

6 files changed

+20
-42
lines changed

copier/main.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,7 @@ def jinja_env(self) -> YieldEnvironment:
627627
"""
628628
paths = [str(self.template.local_abspath)]
629629
loader = FileSystemLoader(paths)
630-
default_extensions = [
631-
"jinja2_ansible_filters.AnsibleCoreFiltersExtension",
632-
YieldExtension,
633-
]
630+
default_extensions = ["jinja2_copier_extension.CopierExtension", YieldExtension]
634631
extensions = default_extensions + list(self.template.jinja_extensions)
635632
try:
636633
env = YieldEnvironment(

copier/tools.py

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import re
99
import stat
1010
import sys
11-
from contextlib import suppress
1211
from decimal import Decimal
1312
from enum import Enum
1413
from importlib.metadata import version
@@ -17,6 +16,7 @@
1716
from typing import Any, Callable, Iterator, Literal, TextIO, cast
1817

1918
import colorama
19+
from jinja2_copier_extension._filters.types import do_bool
2020
from packaging.version import Version
2121
from pathspec.patterns.gitwildmatch import GitWildMatchPattern
2222
from pydantic import StrictBool
@@ -110,31 +110,7 @@ def cast_to_str(value: Any) -> str:
110110
raise ValueError(f"Could not convert {value} to string")
111111

112112

113-
def cast_to_bool(value: Any) -> bool:
114-
"""Parse anything to bool.
115-
116-
Params:
117-
value:
118-
Anything to be casted to a bool. Tries to be as smart as possible.
119-
120-
1. Cast to number. Then: 0 = False; anything else = True.
121-
1. Find [YAML booleans](https://yaml.org/type/bool.html),
122-
[YAML nulls](https://yaml.org/type/null.html) or `none` in it
123-
and use it appropriately.
124-
1. Cast to boolean using standard python `bool(value)`.
125-
"""
126-
# Assume it's a number
127-
with suppress(TypeError, ValueError):
128-
return bool(float(value))
129-
# Assume it's a string
130-
with suppress(AttributeError):
131-
lower = value.lower()
132-
if lower in {"y", "yes", "t", "true", "on"}:
133-
return True
134-
elif lower in {"n", "no", "f", "false", "off", "~", "null", "none"}:
135-
return False
136-
# Assume nothing
137-
return bool(value)
113+
cast_to_bool = do_bool
138114

139115

140116
def force_str_end(original_str: str, end: str = "\n") -> str:

docs/configuring.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ filters, global variables and functions, or tags to the environment.
10711071

10721072
The following extensions are _always_ loaded:
10731073

1074-
- [`jinja2_ansible_filters.AnsibleCoreFiltersExtension`](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/):
1074+
- [`jinja2_copier_extension.CopierExtension`](https://github.com/copier-org/jinja2-copier-extension):
10751075
this extension adds most of the
10761076
[Ansible filters](https://docs.ansible.com/ansible/2.3/playbooks_filters.html) to
10771077
the environment.

poetry.lock

Lines changed: 9 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ colorama = ">=0.4.6"
3232
dunamai = ">=1.7.0"
3333
funcy = ">=1.17"
3434
jinja2 = ">=3.1.5"
35-
jinja2-ansible-filters = ">=1.3.1"
35+
jinja2-copier-extension = "0.1.0"
3636
packaging = ">=23.0"
3737
pathspec = ">=0.9.0"
3838
plumbum = ">=1.6.9"

renovate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
{
1818
"matchManagers": ["github-actions"],
1919
"addLabels": ["github_actions"]
20+
},
21+
{
22+
"matchCategories": ["python"],
23+
"matchDepNames": ["jinja2-copier-extension"],
24+
"rangeStrategy": "replace",
25+
"semanticCommitType": "fix"
2026
}
2127
]
2228
}

0 commit comments

Comments
 (0)