en de
Back

Online Magazine

Code repository: It can be so simple!

Oops, I forgot to add a README ... again! Forgetting or doing things wrong when setting up code repositories is very easy, especially if you are collaborating with others. Luckily, there is an uncomplicated way to standardize this process.

 

By Yves Mauron

Setting up a new repository in a project is always cumbersome. There are certain standards and agreements to adhere, there are mandatory files, deployment artifacts must be placed somewhere; the requirements should be in a certain place et cetera.

Project templates can be a fantastic way of mitigating these challenges and lower the bar for new team members while, at the same time, enforcing standards. One awesome tool that facilitates creating and using such templates is cookiecutter.

Cookiecutter is a CLI tool (Command Line Interface) to create application boilerplate code from a template. It uses Jinja2 as a templating system to replace or customize folder and file names, as well as file content. Cookiecutter is written in Python, however, it can be used to generate code repos for any other programming language as well.

Noob Hack

You will need a working Python installation on your machine; thereafter you can install cookiecutter using your favorite package manager, e.g.:

Pip:

$ pip install --user cookiecutter

Conda:

$ conda install cookiecutter

Find an existing template and use it for your project. Below there is an example using the cookiecutter-pypackage template created by @audreyfeldroy to setup a “best-practice” Python project in no time.


Now, you can focus on what really matters, building your application. Happy coding!

Pro Hack

As usual, there is a high chance that you do things a little differently in your organization or, maybe, you can even generate more boilerplate code, increasing the potential of templates to save time and increase reusability. So, one might decide to create a custom template adjusted to the needs of an organization or team; essentially standardizing how to do things.

To create your own cookiecutter templates, you need to learn some Jinja and Python. A great way to get started is this guide and, of course, the respective documentation pages of Jinja and Python.

Besides the above-mentioned reasons, building your own templates to automate how to setup projects in your own organization is also fun. Because it essentially forces a team to think about how to best do things. Putting the outcome of these discussions in a template that everyone can use, can be an efficiency-booster.

Your contact

EVEN MORE HACKS AND TECHNICAL ARTICLES THAT CAN MAKE YOUR LIFE EASIER:

TechTalk
Digital transformation

Who needs a digital strategy?
Hack of the Week
Data analytics

Excel Files & Azure Synapse Analytics
TechTalk
AI in business Automation AI

Thoughts on GPT-3
Read