Skip to content

Commit b831a07

Browse files
committed
refactor: drop jinja2-ansible-filters and reimplement Jinja2 filters
1 parent a4d38b1 commit b831a07

File tree

6 files changed

+773
-40
lines changed

6 files changed

+773
-40
lines changed

copier/main.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
UnsafeTemplateError,
4545
UserMessageError,
4646
)
47+
from .jinja_ext import CopierExtension
4748
from .subproject import Subproject
4849
from .template import Task, Template
4950
from .tools import (
@@ -547,9 +548,7 @@ def jinja_env(self) -> SandboxedEnvironment:
547548
"""
548549
paths = [str(self.template.local_abspath)]
549550
loader = FileSystemLoader(paths)
550-
default_extensions = [
551-
"jinja2_ansible_filters.AnsibleCoreFiltersExtension",
552-
]
551+
default_extensions = [CopierExtension]
553552
extensions = default_extensions + list(self.template.jinja_extensions)
554553
# We want to minimize the risk of hidden malware in the templates
555554
# so we use the SandboxedEnvironment instead of the regular one.

docs/configuring.md

+46-9
Original file line numberDiff line numberDiff line change
@@ -950,15 +950,52 @@ Overwrite files that already exist, without asking.
950950
Additional Jinja2 extensions to load in the Jinja2 environment. Extensions can add
951951
filters, global variables and functions, or tags to the environment.
952952

953-
The following extensions are _always_ loaded:
954-
955-
- [`jinja2_ansible_filters.AnsibleCoreFiltersExtension`](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/):
956-
this extension adds most of the
957-
[Ansible filters](https://docs.ansible.com/ansible/2.3/playbooks_filters.html) to
958-
the environment.
959-
960-
You don't need to tell your template users to install these extensions: Copier depends
961-
on them, so they are always installed when Copier is installed.
953+
By default, most of the
954+
[Ansible filters](https://docs.ansible.com/ansible/2.3/playbooks_filters.html) are
955+
_always_ loaded:
956+
957+
- `ans_groupby`
958+
- `ans_random`
959+
- `b64decode`
960+
- `b64encode`
961+
- `basename`
962+
- `bool`
963+
- `checksum`
964+
- `dirname`
965+
- `expanduser`
966+
- `expandvars`
967+
- `extract`
968+
- `fileglob`
969+
- `flatten`
970+
- `from_json`
971+
- `from_yaml`
972+
- `from_yaml_all`
973+
- `hash`
974+
- `mandatory`
975+
- `md5`
976+
- `quote`
977+
- `random_mac`
978+
- `realpath`
979+
- `regex_escape`
980+
- `regex_findall`
981+
- `regex_replace`
982+
- `regex_search`
983+
- `relpath`
984+
- `sha1`
985+
- `shuffle`
986+
- `splitext`
987+
- `strftime`
988+
- `ternary`
989+
- `to_datetime`
990+
- `to_json`
991+
- `to_nice_json`
992+
- `to_nice_yaml`
993+
- `to_uuid`
994+
- `to_yaml`
995+
- `type_debug`
996+
- `win_basename`
997+
- `win_dirname`
998+
- `win_splitdrive`
962999

9631000
!!! warning
9641001

docs/creating.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,10 @@ In addition to
7777
[all the features Jinja supports](https://jinja.palletsprojects.com/en/3.1.x/templates/),
7878
Copier includes:
7979
80-
- All functions and filters from
81-
[jinja2-ansible-filters](https://gitlab.com/dreamer-labs/libraries/jinja2-ansible-filters/).
82-
83-
- This includes the `to_nice_yaml` filter, which is used extensively in our
84-
context.
85-
80+
- Most of the
81+
[Ansible filters](https://docs.ansible.com/ansible/2.3/playbooks_filters.html)
82+
including the `to_nice_yaml` filter, which is used extensively in our context. See
83+
the [`jinja_extensions`][] setting for more details.
8684
- `_copier_answers` includes the current answers dict, but slightly modified to make
8785
it suitable to [autoupdate your project safely][the-copier-answersyml-file]:
8886
- It doesn't contain secret answers.

poetry.lock

+97-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ colorama = ">=0.4.6"
3333
dunamai = ">=1.7.0"
3434
funcy = ">=1.17"
3535
jinja2 = ">=3.1.4"
36-
jinja2-ansible-filters = ">=1.3.1"
3736
packaging = ">=23.0"
3837
pathspec = ">=0.9.0"
3938
plumbum = ">=1.6.9"
4039
pydantic = ">=2.4.2"
4140
pygments = ">=2.7.1"
4241
pyyaml = ">=5.3.1"
4342
questionary = ">=1.8.1"
44-
typing-extensions = { version = ">=3.7.4,<5.0.0", python = "<3.9" }
43+
typing-extensions = { version = ">=3.10.0.0,<5.0.0", python = "<3.9" }
4544
eval-type-backport = { version = ">=0.1.3,<0.3.0", python = "<3.10" }
4645

4746
[tool.poetry.group.dev]
4847
optional = true
4948

5049
[tool.poetry.group.dev.dependencies]
50+
backports-zoneinfo = { version = ">=0.2.1", python = "<3.9" }
5151
mypy = ">=0.931"
5252
pexpect = ">=4.8.0"
5353
poethepoet = ">=0.12.3"
@@ -56,6 +56,7 @@ pytest = ">=7.2.0"
5656
pytest-cov = ">=3.0.0"
5757
pytest-gitconfig = ">=0.6.0"
5858
pytest-xdist = ">=2.5.0"
59+
time-machine = ">=2.14.2"
5960
types-backports = ">=0.1.3"
6061
types-colorama = ">=0.4"
6162
types-psutil = "*"

0 commit comments

Comments
 (0)