-
-
Notifications
You must be signed in to change notification settings - Fork 225
Conditional transclusion: Issue #1076 #2332
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
base: master
Are you sure you want to change the base?
Conversation
Some tests are placeholders for now.
…copier into conditional_transclusion
Refs: 1076#issue-1653172783
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2332 +/- ##
==========================================
+ Coverage 97.07% 97.14% +0.06%
==========================================
Files 55 55
Lines 6158 6294 +136
==========================================
+ Hits 5978 6114 +136
Misses 180 180
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
… [to be removed in prod]
b18d4a8
to
d352f95
Compare
Complying to CodeCov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a pretty massive change for a seemingly small feature. 🙈
I'm not sure about the alternative syntax:
!include env/dev.yml
when "{{ env_type == 'dev' }}"
If
!include env/dev.yml
when: "{{ env_type == 'dev' }}"
doesn't work, I'd prefer moving back to the design discussion. There was already another suggestion, although I think _include
looks like the opposite of _exclude
, but the two are semantically unrelated. Ideally, we'd use a widely adopted syntax, but it might not exist.
Feature
Issue #1076 proposed the following feature:
This PR thus proposes an implementation of this feature (with a small syntax change so as not to break the handling of
!include
):Implementation idea
The idea is the following: when a file transclusion is conditioned on a condition
condition
, everything in that file will be subsequently jinja conditioned oncondition
. The variables will be defaulted to falsy values of the corresponding type with a Falsewhen
when thecondition
is False, so as to reproduce the behavior of non-existing variable.Potential current shortcomings
copier.yml
) are interpreted by jinja, if they are not, these settings would require additional work to be conditionedcopier.yml
) (that, I did test), I did not test the execution of the settings exhaustively: only tested the correct execution of_exclude
type
, whenwhen
is False, could be changed tostr
with an empty str as valuePotential required improvement
copier.yml
), which then test whether they are correctly applied or ignored depending on the conditionTests
To run the tests only for the new feature, I have added a temporary pytest marker
conditional_transclusion
:uv run poe test -m conditional_transclusion