-
-
Notifications
You must be signed in to change notification settings - Fork 186
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
feat(context): expose a _phase
context variable (fix #1883)
#1948
base: master
Are you sure you want to change the base?
Conversation
8173a15
to
166fc44
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1948 +/- ##
==========================================
- Coverage 98.05% 97.91% -0.15%
==========================================
Files 53 53
Lines 5511 5551 +40
==========================================
+ Hits 5404 5435 +31
- Misses 107 116 +9
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Looking super good to me 😄 Thank you for the awesome PRs @noirbizarre! |
3d6dbd8
to
dc3071d
Compare
PR updated with the typo fixes. You're welcome 🙏🏼 It benefits everybody 👌🏼 |
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.
Fantastic work again, @noirbizarre! 🙏
Just a minor stylistic request: It seems Python enums should be upper-case12. I suggest following this guideline.
Footnotes
317a8ed
to
41bef6c
Compare
Updated to upper case 👍🏼 I, personally, tend to do the opposite with |
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.
It seems you're right, there isn't a definitive style rule about enums. 🫣 Thanks for elaborating on this topic (especially the detailed message before you edited it 😉)! Well, now it's upper-case. Shall we leave it like this?
Just a final thought: Shall we expose the phase via the _phase
variable (as it is now) or would it be better to rename/move it? E.g.:
_copier_phase
– only_folder_name
,now
, andmake_secret
seems to not have the_copier
prefix wherenow
andmake_secret
are both deprecated._copier_conf.phase
– or should we only have static values under_copier_conf
?
@noirbizarre @copier-org/maintainers Any opinions?
I tend to use lowercase too, except when the enum contains names that are reserved keywords like I'm accessing the phase with |
@pawamoy So, would you tend to be in favor of |
This comment was marked as outdated.
This comment was marked as outdated.
Yes, |
Here's my final comprehension of the issue (which may be worth adding as documentation or code comments at least).
|
41bef6c
to
badf574
Compare
Oh, I didn't though about all that 😅 Note that I actually use context extensions during prompt on my projects, and actually this PR can maybe help to have a more general approach on this and assume that extensions can run at any phase. (This might later lead to having copier-template-extensions Anyway, PR update with |
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.
I've thought about this PR some more and also about – what @pawamoy noticed – the phase value being automatically exposed as _copier_conf.phase
because most Worker
dataclass attributes are automatically included in _copier_conf
. As
I would go for a root
_copier_phase
as it is not a configuration, just a runtime state.
makes sense to me, I think the phase value should not be accessible under _copier_conf
though. This PR also reminds me of a similar situation we've had in #1733 where initially a dataclass attribute was used as well and I suggested to use a context variable instead. Now, it feels odd to me to use a dataclass attribute here to manage the phase value because it has no meaning while not rendering, prompting or executing tasks/migrations. How about applying an approach similar to #1733 (review) in this PR as well?
Slightly off-topic: I just realized that #1733 exposes a top-level _operation
Jinja variable; we might want to rename it to _copier_operation
there for consistency.
I agree with all of @sisp's points 🙂 Regarding Lines 334 to 339 in 57439e5
Not sure what it means exactly, but it seems like we wanted to stray away from this anyway. |
@pawamoy This comment pre-dates my involvement with Copier, but I don't think the (raw) |
Fine by me. I'd suggest making sure |
badf574
to
a8c7d53
Compare
PR updated with I saw the deprecation noticed, but it is used by all rendering except those for the prompts.
Agreed, but I would go even further (not in this PR to keep it scoped), I would isolate rendering in a single class/module/function/whatever, so future modification of this kind occurs in a single place. It would be easier to maintain and evolve, and easier to test. |
a8c7d53
to
17efb40
Compare
This PR exposes a
_phase
variable which can be one ofprompt
,tasks
,mmigrate
andrender
.The known phases are grouped into the
copier.types.Phase
enum.This implements #1883 and allows fixing copier-org/copier-templates-extensions#7