Member-only story
How to Write a Python Script to Create and Update a Changelog
No more generators, logs, or dependencies-now for Python!
If you read my previous post about how to write a bash script to create and update a changelog, you might find this post interesting as well. I was working on some python scripts for work when it occurred to me that some Python devs might appreciate having a changelog script in Python.
Now they do!
I’ve added Python support to extend my original changelog script to engineers with a preference for Python. You can now use the same script logic with Python code. If you’re a python developer and want to add more customizations to your changelog creation/generation, you can do so more easily now with this added support.
Since it’s the same logic as my previous script, I won’t go too in depth in terms of functionality. Instead, I’ll highlight some syntactic differences. Let’s jump right in!
First, create a changelog.py
file to run the script’s logic. You can make this file executable by running chmod 755 changelog.py
. With this you will be able to run ./changelog.py
from your command line or include it in another script if that’s preferred by appending ./changelog.py
to it.
Next, we need our project’s version to be synced with our changelog. Here is how we get the version in Bash.
version="$(git describe --long)"
In Python, you can achieve the same result with the below code.
version=subprocess.check_output([“git”, “describe”, “ — long”]).strip()
In other parts of the code, you will need to use string interpolation. This is done a little differently in Python than it is in Bash. See below for Bash string interpolation.
name="Matthew Croak"
introduction="My name is $name"echo $introduction> "My name is Matthew"
Now here is string interpolation for Python.
name="Matthew Croak"
introduction="My name is {}".format(name)print(introduction)> "My name is Matthew"