1 of 60

Stay in sync with your

Alexander Frenzel�alexander.frenzel@wolt.com��June 9th, 2021

2 of 60

This is Alex

Content & Personalisation

Enjoys climbing & bouldering

Alexander Frenzel

Python Developer��alexander.frenzel@wolt.com

🧗

3 of 60

“A command-line utility that creates projects from cookiecutters (project templates), �e.g. creating a Python package project from a Python package project template.”

https://github.com/cookiecutter/cookiecutter

4 of 60

Active community

5 of 60

Let’s see it in action.

6 of 60

7 of 60

Backup slide

8 of 60

How does it work?

9 of 60

How does it work?

10 of 60

How does it work?

11 of 60

How does it work?

12 of 60

How does it work?

13 of 60

Template Language - jinja2

https://jinja.palletsprojects.com/en/3.0.x/

14 of 60

How does it work?

15 of 60

How does it work?

16 of 60

cookiecutter.json

17 of 60

  1. Create a cookiecutter template�
  2. Publish it�
  3. Use cookiecutter to create a new project based on your template�$ cookiecutter <url to template>

https://cookiecutter.readthedocs.io/

18 of 60

What’s next?

How do I update my projects?

  1. Make changes to your templates�
  2. Figure out a way to to apply these changes to your projects�
    1. Fiddle with git diff and patch
    2. Just do it manually

🤬

19 of 60

20 of 60

https://github.com/cruft/cruft

21 of 60

Cruft

  • CLI�
  • Cookiecutter Compatible�
  • Automatic Template Updates

https://github.com/cruft/cruft

22 of 60

Cruft

https://github.com/cruft/cruft

23 of 60

Sounds great. How do i use it?

24 of 60

25 of 60

Backup slide

26 of 60

Let’s update our template

27 of 60

28 of 60

Backup slide

29 of 60

...and our project.

30 of 60

31 of 60

Backup slide

32 of 60

Backup slide

33 of 60

Amazing

34 of 60

Where does the magic happen?

35 of 60

Where does the magic happen?

36 of 60

.cruft.json

37 of 60

.cruft.json

38 of 60

.cruft.json

39 of 60

What happens on a conflict?

40 of 60

41 of 60

Backup slide

42 of 60

Backup slide

Backup slide

43 of 60

Backup slide

44 of 60

Backup slide

45 of 60

That was easy!

46 of 60

Cruft

  • Create a cookiecutter template�
  • Publish it�
  • Use cruft to create a new project based on your template�$ cruft create <url to template>�
  • Keep your project in sync by using�$ cruft update�
  • Resolve conflicts if necessary

https://github.com/cruft/cruft

47 of 60

Bonus

48 of 60

Let’s automate it

Powered by GitHub actions :)

.github/workflow/update.yml

49 of 60

Let’s automate it

Powered by GitHub actions :)

.github/workflow/update.yml

50 of 60

Let’s automate it

Powered by GitHub actions :)

.github/workflow/update.yml

51 of 60

Let’s automate it

Powered by GitHub actions :)

.github/workflow/update.yml

52 of 60

Let’s automate it

Powered by GitHub actions :)

.github/workflow/update.yml

53 of 60

Let’s automate it

Powered by GitHub actions :)

.github/workflow/update.yml

54 of 60

55 of 60

“ready to merge” PRs

56 of 60

Questions?

57 of 60

Links

Cookiecutter template used in this presentation

My opinionated cookiecutter templates with auto update

Cookiecutter

Cruft

58 of 60

Thank you

59 of 60

Templates maintained by the cookiecutter team

  • cookiecutter-pypackage: @audreyr’s ultimate Python package project template.
  • cookiecutter-django: A bleeding edge Django project template with Bootstrap 4, customizable users app, starter templates, working user registration, celery setup, and much more.
  • cookiecutter-pytest-plugin: Minimal Cookiecutter template for authoring pytest plugins that help you to write better programs.

https://cookiecutter.readthedocs.io/en/1.7.2/README.html#cookiecutter-specials

60 of 60

Template Language - jinja2

and much more...

https://jinja.palletsprojects.com/en/3.0.x/