Code Monkey home page Code Monkey logo

django-codemod's Introduction

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), and it's a limiting factor in terms of supported Python versions as well as its 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.

django-codemod's People

Contributors

actions-user avatar adamchainz avatar akx avatar allcontributors[bot] avatar browniebroke avatar cvanderkolk avatar dependabot[bot] avatar dmytrolitvinov avatar github-actions[bot] avatar iamshnoo avatar jayvdb avatar pre-commit-ci[bot] avatar pyup-bot avatar renovate-bot avatar renovate[bot] avatar sobolevn avatar sourcery-ai-bot avatar sourcery-ai[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.