• Stars
    star
    179
  • Rank 214,039 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created over 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tool to automatically fix Django deprecations.

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.

More Repositories

1

gatsby-image-gallery

Very basic gallery grid based on gatsby-image
TypeScript
123
star
2

deezer-python

Deezer client for python
Python
107
star
3

pypackage-template

A project template for Python package with heavy use of Github actions
Jinja
58
star
4

hello-lambda

Minimal project to get up and running on AWS lambda and pipenv
Makefile
29
star
5

pre-commit-autoupdate-action

Github action to run pre-commit autoupdate
26
star
6

cookiecutter-lambda-function

A cookiecutter template to create AWS Lambda function
Python
23
star
7

read-nvmrc-action

Simple Github action to read value from .nvmrc file
9
star
8

django-remake-migrations

A Django admin command to recreate all migrations in a project.
Python
8
star
9

flake8-django-migrations

Flake8 plugin to lint for backwards incompatible database migrations
Python
7
star
10

deezer-oauth-cli

A small CLI to quickly obtain an API token for Deezer API.
Python
7
star
11

django-tinymce4-widget

Widget for TinyMCE 4 without any static files
Python
5
star
12

cookiecutter-action-py

A cookiecutter template for generating GitHub actions running Python
Python
5
star
13

edubase-now

Convert the daily Edubase dump into an API in seconds.
Makefile
3
star
14

github-actions

A collection of my own GitHub actions
3
star
15

hacktoberfest-labeler-action

A Github Action to labels issues for Hacktoberfest.
Python
2
star
16

all-my-repos

My config to run all-repos
Python
2
star
17

browniebroke.com

Personal blog
TypeScript
2
star
18

django-admin-helpers

A collections of helpers for the Django admin.
Python
1
star
19

carriere-web

Code for site
TypeScript
1
star
20

semaphoreci-notifier

A basic browser extension to send browser notifications on Semaphore CI
JavaScript
1
star
21

netlify-builds

A command line utility to check build usage across multiple Netlify accounts
Python
1
star
22

browniebroke-iac

Describe my infrastructure as code
HCL
1
star
23

festilist

Web application to create playlist based on a festival line up
Python
1
star
24

all-repos-envvar

An all-repos extension to read values from environment variables.
Python
1
star
25

semaphoreci-chrome-notifier

Chrome extension to send a desktop notification when Semaphore CI build terminates
JavaScript
1
star
26

stsmfa-cli

A small CLI to help with creating AWS profile for MFA protected sessions
Python
1
star
27

renovate-configs

My shareable Renovate configs
1
star