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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file django-upgrade-1.0.0.tar.gz.

File metadata

  • Download URL: django-upgrade-1.0.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for django-upgrade-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9aa312ef15225212acc41e9e0fca23d0eacec7f6cdd372ee4d92ceaac7ab34ea
MD5 2f8aea83eb629f895e35d0411dc1f96c
BLAKE2b-256 fd249c9819e4b9a673523cd69008f77a80040e9d9ad70833b4dc825802d92926

See more details on using hashes here.

File details

Details for the file django_upgrade-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_upgrade-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

File hashes

Hashes for django_upgrade-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c307513c2c514734a1bd84a3b6d944435feeee5d7ecdcf349d1e4edea8afc26b
MD5 b1ab8c7c2ec824bb76f40a0abe4d73f4
BLAKE2b-256 013503e1b2edc33d8a0938af297a32853a1b7cface42f980d10881d70b2f5b77

See more details on using hashes here.

Supported by

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