
Upgrading projects is somewhat equivalent to flossing, you know you have to do it, but rarely make time for it. After all, if the project is in active development, there are exciting new features to build. And we all know that new features > project upgrades. Well not to worry, Caktus wants to make you aware of some tools that will save you from considerable repetitive work & time while simultaneously modernizing your codebase. Combined, these tools will automate part of the upgrade process, decreasing the likelihood of neglecting parts of the codebase.
Switch to f-strings with flynt
flynt is a tool to automatically convert a project's Python code from old "%-formatted" and .format(...) strings into Python 3.6+'s "f-strings".
Add the following to your .pre-commit-config.yaml file:
- repo: https://github.com/ikamensh/flynt/
rev: 1.0.1
hooks:
- id: flynt
Now run pre-commit run --all-files to apply the changes.
Uprade to the latest Python syntax with pyupgrade
pyupgrade is a tool to automatically upgrade Python syntax to newer versions.
Add the following to your .pre-commit-config.yaml file:
- repo: https://github.com/asottile/pyupgrade
rev: v3.19.1
hooks:
- id: pyupgrade
args: [--py311-plus]
Now run pre-commit run --all-files to apply the changes.
Upgrade your Django code with django-upgrade
django-upgrade is a tool to automatically upgrade Django code to the latest version.
Add the following to your .pre-commit-config.yaml file:
- repo: https://github.com/adamchainz/django-upgrade
rev: 1.23.1
hooks:
- id: django-upgrade
args: [--target-version, "4.2"]
Now run pre-commit run --all-files to apply the changes.
Having these Python tools in your toolbelt will surely make your next project update smoother and more comprehensive. They complement each other, ensuring that different parts of the codebase are upgraded, especially files that would be easy to overlook.