Skip to content
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(tasks): allow skipping tasks with the flag #1561

Merged
merged 6 commits into from
Apr 4, 2024

Conversation

noirbizarre
Copy link
Contributor

@noirbizarre noirbizarre commented Mar 22, 2024

This PR add a -T/--skip-tasks flag allowing to skip template tasks execution.

Some known use cases I have:

  • while testing my template, I want to be able to perform multiple rendering with the extensions actives but without running tasks (which may be slow or depending on connection...)
  • when applying a template with some bootstrap tasks on an existing project, I want to be able to skip the bootstrap tasks because I know they will fail
  • when applying a third party template that I trust, I want to only skip tasks for some reason (known to break, not compatible with the environment...)

Should fix #1415

Copy link

codecov bot commented Mar 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.29%. Comparing base (0fb2d06) to head (05c1762).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1561      +/-   ##
==========================================
+ Coverage   97.28%   97.29%   +0.01%     
==========================================
  Files          48       48              
  Lines        4603     4621      +18     
==========================================
+ Hits         4478     4496      +18     
  Misses        125      125              
Flag Coverage Δ
unittests 97.29% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks solid 🙂

Do I understand correctly that passing --skip-tasks means I don't have to also pass --trust?

copier/main.py Outdated Show resolved Hide resolved
@noirbizarre
Copy link
Contributor Author

noirbizarre commented Mar 22, 2024

No, you still have to pass --trust (if you want to have jinja extensions loaded), but if you have --trust --skip-tasks only extension will be loaded (and migrations applied in case of update) while --trust will load extension and execute tasks (and apply migrations in the case of update).
In fact it doesn't touch the --trust behavior, just skipping tasks, whether the template is trusted or not (but in the second case, tasks are disabled by security, not from user intent)

@pawamoy
Copy link
Contributor

pawamoy commented Mar 22, 2024

OK yes that makes sense.

copier/cli.py Outdated Show resolved Hide resolved
Copy link
Contributor

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two suggestions regarding readability and then I'll have nothing left to say I think 😄

tests/test_migrations.py Outdated Show resolved Hide resolved
tests/test_migrations.py Outdated Show resolved Hide resolved
Copy link
Contributor

@pawamoy pawamoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

tests/test_tasks.py Show resolved Hide resolved
Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also need to document this setting here.

@noirbizarre
Copy link
Contributor Author

PR updated with the setting documentation 👍🏼

docs/configuring.md Outdated Show resolved Hide resolved
Co-authored-by: Timothée Mazzucotelli <[email protected]>
Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some final 🤞 docs suggestions, @noirbizarre. I'll be happy to merge afterwards.

docs/configuring.md Outdated Show resolved Hide resolved
docs/configuring.md Outdated Show resolved Hide resolved
docs/configuring.md Outdated Show resolved Hide resolved
docs/configuring.md Outdated Show resolved Hide resolved
noirbizarre and others added 4 commits April 4, 2024 11:32
Co-authored-by: Sigurd Spieckermann <[email protected]>
Co-authored-by: Sigurd Spieckermann <[email protected]>
Co-authored-by: Sigurd Spieckermann <[email protected]>
Co-authored-by: Sigurd Spieckermann <[email protected]>
Copy link
Member

@sisp sisp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, thanks @noirbizarre! 🙏

@sisp sisp merged commit 4ca2e35 into copier-org:master Apr 4, 2024
21 checks passed
@yajo
Copy link
Member

yajo commented Apr 4, 2024

Sorry for being late to the party.

I think that, if you pass this flag, it should be taken into account around here to avoid marking the template as unsafe if it's only because of tasks but you're skipping them:

copier/copier/main.py

Lines 233 to 234 in 70aa69f

if self.template.tasks:
features.add("tasks")

@sisp
Copy link
Member

sisp commented Apr 4, 2024

@yajo I think that's the same thought that I had, but we decided against it in that discussion. WDYT?

@yajo
Copy link
Member

yajo commented Apr 7, 2024

Consider migrations. Even if the template uses migrations, we only mark it as unsafe if the current update will trigger them.

In the same fashion, if it has tasks but you're ignoring them, there's no unsafety produced by tasks. Other unsafety criteria should still be honored, but not that one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to define safe/unsafe modes and force to ignore _tasks
4 participants