Proposal: scripts and hooks improvements #3344
noirbizarre
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi 👋🏼
I have been thinking a lot about this one, but never had the time to share and implement it.
I contributed a lot to scripts handling that I have been extensively using since, and I'd like to share my feedback and an evolution proposal from this experience.
Current state
As of today
pre
andpost
scripts and hooks are defined like this:pre_<script>
andpost_<script>
for scriptspre_<signal>
andpost_<script>
for hooksThey come with documented drawbacks:
As well as non-documented ones, but obvious when you use them:
At the same time, composite tasks are great, but they suffer (in my opinion) a few issues:
cmd
unless a task matching the name existsProposal
My idea is to make a few changes, not radical ones, to make this both more powerful and flexible.
pre
andpost
as attributesThe first change I'd like to make is to formalize
pre
andpost
tasks or hooks as attribute instead of name convention.This would allow having dedicated schema entries with completion, validation and discoverability.
But it would also make syntax more clean and logical. As an example, here are the same scripts definitions in the current syntax and the one I propose, each time as object syntax, dot syntax or table syntax
Object syntax
Current:
Proposal:
I think this is the form where it does not shine, but I don't use much this form because it already has the same drawback on other attributes (
help
,env
,env_file
...):Dot syntax
This is the syntax I use the more.
Current:
Proposal:
As you can see, grouping is more obvious.
Table syntax
Current:
Proposal:
With this one, the grouping drawback is even more obvious
pre
andpost
as compositespre
andpost
hooks being tasks is a bit overkill because:Making them composite would provide the following benefit:
inline composite tasks
Currently, composite tasks are very practical, but they are ambiguous.
The algorithm is the following:
You can't define a
shell
script orcall
script, they need to be defined as separate plain task.My proposal is to allow an inline task object syntax:
To be consistent and explicit, I would:
use
attribute for explicit task reuseuse
This would make this syntax equivalent:
Combined with the previous proposition, it would allow:
Bonus: Syntactic sugar for single element composite
I often use composite with a single entry just to benefit from reuse:
As there is currently no case where composite accept a single entry (string or object as defined above),
I would allow single entry composite to remove the array:
or with the previous proposition:
The hooks ?
Same as above for everything, meaning you would write:
It would give the following benefits:
<signal>.cmd
,<signal>.shell
,<signal>.call
or<signal>.composite
, only.pre
and.post
)Proposal migration path
If this proposal is accepted, I suggest naming the new section
tasks
instead ofscripts
to avoid keeping naming constraint onpre_
/post_
as well as being able to properly detect syntax version and also provide a dedicated schema.It would be consistent with the fact they are already called tasks in the code base and I think the wording task is more representative as
scripts
might not be scripts. From the user point of view, they are tasks to execute.The way I see it, there are 2 possible paths:
Deprecation period
tool.pdm.scripts
is foundpdm fix
which can migratetool.pdm.scripts
totool.pdm.tasks
tool.pdm.scripts
support after the deprecation periodThis is the smooth migration path, but I think it's harder to maintain as during the deprecation period, it needs to support both syntax so most probably it will be more complex to test, and keep a lot more code. Plus, it means people might report bugs for both syntax during this period.
Forced migration
tool.pdm.scripts
is found and ask for migrationpdm fix
which can migratetool.pdm.scripts
totool.pdm.tasks
This is the one I prefer as it is simpler to handle, represent way less maintenance, we can update the schema without having support for both format...
There it is ! What do you think about it ? Is this proposition worth it ? What would you choose or do differently ? Should I submit a pull request for it ?
Beta Was this translation helpful? Give feedback.
All reactions