Skip to main content

Automatically upgrade your Django projects.

Reason this release was yanked:

faultily lists python 3.6 to 3.7 compatibility

Project description

https://img.shields.io/github/workflow/status/adamchainz/django-upgrade/CI/main?style=for-the-badge https://img.shields.io/codecov/c/github/adamchainz/django-upgrade/main?style=for-the-badge https://img.shields.io/pypi/v/django-upgrade.svg?style=for-the-badge https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge pre-commit

Automatically upgrade your Django projects.

Installation

Use pip:

python -m pip install django-upgrade

Python 3.6 to 3.9 supported.

Or with pre-commit in the repos section of your .pre-commit-config.yaml file:

-   repo: https://github.com/adamchainz/django-upgrade
    rev: ''  # replace with latest tag on GitHub
    hooks:
    -   id: django-upgrade

Are your tests slow? Check out my book Speed Up Your Django Tests which covers loads of best practices so you can write faster, more accurate tests.


Currently an experimental alternative to django-codemod, whose underlying library LibCST is relatively slow.

Usage

Run django-upgrade --help on the commandline for information.

Fixers

Django 2.2

Based on the Django 2.2 release notes.

django.core.paginator

  • QuerySetPaginatorPaginator

-from django.core.paginator import QuerySetPaginator
+from django.core.paginator import Paginator

-QuerySetPaginator(...)
+Paginator(...)

django.utils.timezone

  • FixedOffset(x, y)timezone(timedelta(minutes=x), y)

  • Will leave code broken with an ImportError if FixedOffset is called with (only) *args or **kwargs.

-from django.utils.timezone import FixedOffset
-FixedOffset(120, "Super time")
+from datetime import timedelta, timezone
+timezone(timedelta(minutes=120), "Super time")

Django 3.0

Based on the Django 3.0 release notes.

django.utils.encoding

  • smart_text()smart_str() , force_text()force_str()

  • django-upgrade does not support Python 2 so these names are always replaced.

-from django.utils.encoding import force_text, smart_text
+from django.utils.encoding import force_str, smart_str


-force_text("yada")
-smart_text("yada")
+force_str("yada")
+smart_str("yada")

Django 3.1

Based on the Django 3.1 release notes.

PASSWORD_RESET_TIMEOUT_DAYS

  • Rewrites the setting PASSWORD_RESET_TIMEOUT_DAYSPASSWORD_RESET_TIMEOUT, including multiplication by the number of seconds in a day.

  • Settings files are heuristically detected as modules with the word “settings” somewhere in their path.

-PASSWORD_RESET_TIMEOUT_DAYS = 4
+PASSWORD_RESET_TIMEOUT = 60 * 60 * 24 * 4

Django 3.2

Based on the Django 3.2 release notes.

django.core.validators.EmailValidator

  • Rewrites keyword arguments whitelistallowlist and domain_whitelistdomain_allowlist.

 from django.core.validators import EmailValidator

-EmailValidator(whitelist=["example.com"])
+EmailValidator(allowlist=["example.com"])
-EmailValidator(domain_whitelist=["example.org"])
+EmailValidator(domain_allowlist=["example.org"])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-upgrade-1.0.0.tar.gz (11.8 kB view hashes)

Uploaded Source

Built Distribution

django_upgrade-1.0.0-py3-none-any.whl (13.6 kB view hashes)

Uploaded Python 3

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