DEV Community

Waylon Walker
Waylon Walker

Posted on • Originally published at waylonwalker.com

4 1

Copier Tasks | Python templating post run task

Copier allows you to run post render tasks, just like cookiecutter. These are defined as a list of tasks in your copier.yml. They are simply shell commands to run.

The example I have below runs an update-gratitude bash script after the copier template has been rendered.

# copier.yml
num: 128
_answers_file: .gratitude-copier-answers.yml
_tasks:
  - "update-gratitude"
Enter fullscreen mode Exit fullscreen mode

I have put the script in ~/.local/bin so that I know it's always on my
$PATH. It will reach back into the copier.yml and update the default
number.

#!/bin/bash
# ~/.local/bin/update-gratitude
current=`awk '{print $2}' ~/.copier-templates/gratitude/copier.yml | head -n 1` new=`expr $current + 1` echo $current echo $new sed -i "s/$current/$new/g" ~/.copier-templates/gratitude/copier.yml
Enter fullscreen mode Exit fullscreen mode

Image of Stellar post

How a Hackathon Win Led to My Startup Getting Funded

In this episode, you'll see:

  • The hackathon wins that sparked the journey.
  • The moment José and Joseph decided to go all-in.
  • Building a working prototype on Stellar.
  • Using the PassKeys feature of Soroban.
  • Getting funded via the Stellar Community Fund.

Watch the video 🎥

Top comments (1)

Collapse
 
alblimubtel profile image
alblimubtel

In Python's Copier library, post-run tasks offer a powerful way to automate actions after a template has been copied, making the templating process highly customizable and efficient. With post-run tasks, you can execute scripts, install dependencies, or configure settings automatically, streamlining workflow setup and reducing manual steps. This functionality is particularly useful for creating templates that require specific configurations immediately after they’re generated. For example, if you're using templates for social media automation, post-run tasks could be set up to instantly configure integrations, similar to how RunPost Instagram helps streamline and automate Instagram posting, making it easier to manage content effortlessly.

Jetbrains image

Is Your CI/CD Server a Prime Target for Attack?

57% of organizations have suffered from a security incident related to DevOps toolchain exposures. It makes sense—CI/CD servers have access to source code, a highly valuable asset. Is yours secure? Check out nine practical tips to protect your CI/CD.

Learn more

👋 Kindness is contagious

Value this insightful article and join the thriving DEV Community. Developers of every skill level are encouraged to contribute and expand our collective knowledge.

A simple “thank you” can uplift someone’s spirits. Leave your appreciation in the comments!

On DEV, exchanging expertise lightens our path and reinforces our bonds. Enjoyed the read? A quick note of thanks to the author means a lot.

Okay