Skip to main content

A command line tool to automatically fix Django deprecations.

Project description

Django Codemod

CI Status Documentation Status Test coverage percentage pre-commit.ci status

Poetry black pre-commit

PyPi Status pyversions license LoC

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

django-codemod-1.10.8.tar.gz (27.7 kB view details)

Uploaded Source

Built Distribution

django_codemod-1.10.8-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file django-codemod-1.10.8.tar.gz.

File metadata

  • Download URL: django-codemod-1.10.8.tar.gz
  • Upload date:
  • Size: 27.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.12.0 keyring/23.6.0 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.13

File hashes

Hashes for django-codemod-1.10.8.tar.gz
Algorithm Hash digest
SHA256 7fd99e942a89d32ea69357d418da7bd4e2c4af1335e012fba5bfb8fb5fea1ac8
MD5 49a5d47adc84614e308908a66db468bf
BLAKE2b-256 599ae02adc7b17d84a773109e5e0484b9eb5155622245d20c83449cf27fb13f3

See more details on using hashes here.

File details

Details for the file django_codemod-1.10.8-py3-none-any.whl.

File metadata

  • Download URL: django_codemod-1.10.8-py3-none-any.whl
  • Upload date:
  • Size: 34.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/35.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.64.0 importlib-metadata/4.12.0 keyring/23.6.0 rfc3986/2.0.0 colorama/0.4.5 CPython/3.9.13

File hashes

Hashes for django_codemod-1.10.8-py3-none-any.whl
Algorithm Hash digest
SHA256 d0efbb57733a4e7eb6a3fd49e6169b0102e1780fa9f44c5e9e92e96a82f1d9f3
MD5 1efe2f086a2a68953ed646eac6e3268d
BLAKE2b-256 11a596158329e0f7a8721c457170c3684f43c2326e007ba95452e509b39db5e2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page