A command line tool to automatically fix Django deprecations.
Project description
Documentation: https://django-codemod.readthedocs.io
Source Code: https://github.com/browniebroke/django-codemod
A tool to help upgrade Django projects to newer version of the framework by automatically fixing deprecations.
The problem
When maintaining a Django site, over time you'll find yourself to a point where you'll need to update to the next major version of Django. When Django APIs changes, functions move or are removed, changing usages in your project might add up to many changes. Often these changes are simple to do, but sometimes a simple "find and replace" is not possible.
Take, for instance, the removal of the url()
function from Django 4.0, to be replaced by re_path()
. In simple cases, you might even want to switch to path()
, which has a nicer API. A typical Django project easily has 100's or routes, so this simple decision becomes a much longer task when to be made for each of them.
This solution
This project solves this problem by providing codemodders for simple changes like this. A codemodder re-writes your code from the old way to the new way.
With the help of AST analysis, we're able to understand what modifications are applicable, remove imports as they become irrelevant, and add missing ones as they are needed.
To continue the example, the tool will look at the route in the url()
call, and decide whether the regular expression may be replaced by one of the built-in URL converters and use path()
or stick to a regex and use re_path()
.
Interested? Check out the documentation for usage and the full list of codemodders.
What this tool is not
- This tool is best suited for Django sites, NOT for reusable Django applications. The project needs to target a single Django version, e.g. 3.1.x.
- You do NOT need to install this tool as part of your project dependencies, it is a CLI tool, not a Django package to be installed in your site.
Similar tools
django-upgrade is a similar tool written by Adam Johnson. It's a reimplementation taking a different approach based only on standard library module.
django-codemod is based on libCST (Concrete Syntax Tree) which is a limiting factor in terms of speed. By using standard library modules, django-upgrade is a lot faster and is able to support the latest Python, however it requires Python 3.8+.
Contributors ✨
Thanks goes to these wonderful people (emoji key):
Bruno Alla 💻 📖 🤔 |
Aarni Koskela 💻 🤔 ⚠️ |
Adam Johnson 📖 |
Nikita Sobolev 📖 |
Chris VanderKolk 💻 |
John Vandenberg 🐛 💻 |
Anjishnu 🚇 |
Drew Winstel 🤔 |
Dmytro Litvinov 📖 |
M. Zulqarnain 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Credits
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django_codemod-2.2.2.tar.gz
.
File metadata
- Download URL: django_codemod-2.2.2.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94123beab05a30be6f78c7fb06b2ce1235aba0b9ee0d7a31d804763d1d3554e3 |
|
MD5 | 6b72ec21521d69cbdaf4047307047e3e |
|
BLAKE2b-256 | 7f625c18a8540d21d3750377b6cff051c39fde50e5a98d490aaea547f445afae |
Provenance
The following attestation bundles were made for django_codemod-2.2.2.tar.gz
:
Publisher:
ci.yml
on browniebroke/django-codemod
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
django_codemod-2.2.2.tar.gz
- Subject digest:
94123beab05a30be6f78c7fb06b2ce1235aba0b9ee0d7a31d804763d1d3554e3
- Sigstore transparency entry: 149645835
- Sigstore integration time:
- Predicate type:
File details
Details for the file django_codemod-2.2.2-py3-none-any.whl
.
File metadata
- Download URL: django_codemod-2.2.2-py3-none-any.whl
- Upload date:
- Size: 33.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f45656c928e3eca9a67db97a0093f5a05dcb22ab35a1e170a33ad1982f440ac |
|
MD5 | 28c8c550b5f037236310270964c8ff6b |
|
BLAKE2b-256 | c8761d29fd7fed65e934a99a62bb8d64338b17cd05d35dd58cec250123fa03dc |
Provenance
The following attestation bundles were made for django_codemod-2.2.2-py3-none-any.whl
:
Publisher:
ci.yml
on browniebroke/django-codemod
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
django_codemod-2.2.2-py3-none-any.whl
- Subject digest:
9f45656c928e3eca9a67db97a0093f5a05dcb22ab35a1e170a33ad1982f440ac
- Sigstore transparency entry: 149645836
- Sigstore integration time:
- Predicate type: