-
-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: drop jinja2-ansible-filters
and reimplement Jinja2 filters
#1809
base: master
Are you sure you want to change the base?
Conversation
b831a07
to
795ee70
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1809 +/- ##
==========================================
- Coverage 97.67% 97.54% -0.13%
==========================================
Files 49 50 +1
Lines 5108 5302 +194
==========================================
+ Hits 4989 5172 +183
- Misses 119 130 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
c45cf12
to
d72bd50
Compare
d72bd50
to
0480ab4
Compare
OMG you went so far with this! 😅 I thought just to_yaml would be enough for us. But well, now that's done, I IMHO think that the best you could do is release them as a separate library. These filters are very useful under many contexts outside of copier. Then we can just swap our default dependency here. |
Well, I was aiming for a drop-in replacement. In fact, I've bee using some regex filters and
I can definitely create a separate library. Should we create a project in the
I slightly dislike the Ansible-related naming of the |
@sisp you can always support |
@pawamoy But since Copier exposes those Jinja filters as default/builtin filters, isn't a breaking change in those filters also a breaking change in Copier? 🤔 The situation would be different if we only offered the library and advertised its use via the |
Yeah I'm not sure how maintainers usually deal with breaking changes in dependencies other than patching and owning support themselves, then do a major bump 🤔 I guess what I meant is that it's probably easier to handle it in the external lib rather in Copier. Copier can then wash its hands, relying on the fact that the external lib emitted all due warnings. Probably. |
I think we should make a breaking change anyway. There is no guarantee that nothing will break. The only reason we need to bundle some filters by default is that we recommend So, we could just change our docs and recommend using that filter instead. Then remove the dependency and only suggest it. This would be the easiest approach. However, the impact would be huge. 99% of templates would be broken (scientific research citation missing 😆). Many people don't know that YAML is a superset of JSON, so they would wonder why we're using JSON in a YAML document. And while the copier answers file is supposedly not hand-edited, it would still become much uglier. In hindsight, I should have used Now, back to the reality, let's create a new Copier project + repo !
I guess this is good enough. |
https://github.com/copier-org/jinja2-copier-extension @sisp is the admin there. 😉 |
@pawamoy Typically, some functionality of a dependency is used internally where it isn't directly exposed to the users and we merely use it to solve a problem in our software. For instance, when we migrated from Pydantic v1 to v2, we needed to adapt our use of Pydantic, but the change was transparent to the users because we compensated for the breaking changes in Pydantic in our internal code. I think it's different when we depend on a library and pass through its functionality as if it was bundled with Copier. In that case, breaking changes also get passed through, so they affect Copier directly. Perhaps pinning the library's version is the right way to handle this case. Then, we are in control of what version of the library is used and when it gets updated, so it's very similar to vendoring the library or inlining its code in our code base.
@yajo Yes, even omitting some other filters from Thanks for creating the |
I've dropped the
jinja2-ansible-filters
dependency and reimplemented most of the Jinja2 filters by relying on the Ansible filters documentation as much as possible to avoid copying/rewriting GPL-licensed code. The tests are based on a combination of Ansible filters documentation and some thinking of my own.This is the current status:
ans_groupby
ans_random
b64decode
b64encode
basename
bool
checksum
comment
– This filter seems a bit involved, and I'm not sure how relevant it is for Copier.dirname
expanduser
expandvars
extract
fileglob
flatten
from_json
from_yaml
from_yaml_all
hash
mandatory
md5
quote
random_mac
realpath
regex_escape
– Onlyre_type = "python"
is implemented, notre_type = "posix_basic"
because I'm uncertain how to implement it without relying on the GPL-licensed implementation.regex_findall
regex_replace
regex_search
relpath
sha1
shuffle
splitext
strftime
subelements
– This filter seems a bit involved, and I'm not sure how relevant it is for Copier.ternary
to_datetime
to_json
to_nice_json
to_nice_yaml
to_uuid
to_yaml
type_debug
win_basename
win_dirname
win_splitdrive
At this point, 2 filters are missing and one is only partially implemented. This means, if we decide to merge this PR without adding the missing implementations, it would be a breaking change (besides some residual risk of a bad reimplementation).
I'm marking this PR as a draft for now to ensure we properly assess its state before merging.
WDYT, @copier-org/maintainers?
Fixes #1398.