System checks for your project's environment.

Overview

django-version-checks

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

System checks for your project's environment.

Requirements

Python 3.6 to 3.9 supported.

Django 2.2 to 3.2 supported.


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.


Installation

First, install with pip:

python -m pip install django-version-checks

Second, add the app to your INSTALLED_APPS setting:

INSTALLED_APPS = [
    ...
    "django_version_checks",
    ...
]

Third, add a VERSION_CHECKS setting with the version checks you want to enforce (as documented below). For example:

VERSION_CHECKS = {
    "python": "==3.9.*",
}

Usage

See also the introductory blog post.

django-version-checks adds several system checks that can help ensure that the current environment has the right versions of Python, databases, etc. This is useful when coordinating upgrades across all your infrastructure.

Note that django-version-checks does not check the versions of your Python dependencies. This is because such checks need doing at the start of the Python process, in your manage.py file, before Django imports your apps. Any mismatched versions are likely to cause import time problems, before django-version-checks’ system checks can execute. To add checks on your Python dependencies, check out pip-lock.

Checks use the PEP 440 specifier format via the packaging module. This is the same format used by pip, and allows some flexibility in specifying valid version ranges. The ~= operator is particularly useful. For example, you can use ~=3.9.1 to mean “3.9.1+, but less than 3.10.0”, allowing environments to take on patch releases without changes, but nothing more.

The individual checks are documented below. Each occupies a key in the VERSION_CHECKS dictionary, and documents its supported types for specifiers. If a check is misconfigured with a bad type or specifier you will see one of these system check errors:

  • dvc.E001: <check> is misconfigured. Expected a <type> but got <value>.
  • dvc.E002: <check> is misconfigured. <value> is not a valid PEP440 specifier.

mysql check

This check compares the current version of MariaDB/MySQL to the given specifier. The range can specified either as a single string:

VERSION_CHECKS = {
    "mysql": "~=10.5.8",
}

...or as a dictionary mapping database aliases to their specifiers:

VERSION_CHECKS = {
    "postgresql": {
        "default": "~=10.5.8",
        "analytics": "~=10.4.17",
    },
}

Note: as a database check, Django will only run this during migrate or when using check --database (Django 3.1+) / check --tags database (Django <3.1). See (docs).

If this check fails, the system check will report:

  • dvc.E005: The current version of MariaDB/MySQL (<version>) for the <alias> database connection does not match the specified range (<range>).

python check

This check compares the current version of Python to the given single specifier:

VERSION_CHECKS = {
    "python": "~=3.9.1",
}

If this check fails, the system check will report:

  • dvc.E003: The current version of Python (<version>) does not match the specified range (<range>).

postgresql check

This check compares the current version of PostgreSQL to the given specifier. The range can specified either as a single string:

VERSION_CHECKS = {
    "postgresql": "~=12.2",
}

...or as a dictionary mapping database aliases to their specifiers:

VERSION_CHECKS = {
    "postgresql": {
        "default": "~=12.2",
        "analytics": "~=13.1",
    },
}

Note: as a database check, Django will only run this during migrate or when using check --database (Django 3.1+) / check --tags database (Django <3.1). See (docs).

If this check fails, the system check will report:

  • dvc.E004: The current version of PostgreSQL (<version>) for the <alias> database connection does not match the specified range (<range>).

sqlite check

This check compares the current version of SQLite to the given single specifier:

VERSION_CHECKS = {
    "sqlite": "~=12.2",
}

Note: as a database check, Django will only run this during migrate or when using check --database (Django 3.1+) / check --tags database (Django <3.1). See (docs).

If this check fails, the system check will report:

  • dvc.E006: The current version of SQLite (<version>) does not match the specified range (<range>).

Example Upgrade

Let’s walk through using django-version-checks to upgrade Python from version 3.8 to 3.9. We have an infrastructure consisting of CI, staging, and production environments, and several developers’ development machines.

First, we add a pre-existing check to ensure that all environments are on Python 3.8:

VERSION_CHECKS = {
    "python": "~=3.8.6",
}

Second, we rewrite the specifier to allow versions of Python 3.9:

VERSION_CHECKS = {
    "python": ">=3.8.6,<3.10.0",
}

Third, we upgrade our infrastructure. We’d probably upgrade in the order: CI, development environments, staging, production. Each environment should have an automated run of manage.py check, as per the Django deployment checklist.

Fourth, we change the specifier again to allow Python 3.9 only:

VERSION_CHECKS = {
    "python": "~=3.9.1",
}

And we’re upgraded! 🎉

You might also like...
Ugly single sign-on for django projects only

django-usso Ugly single sign-on for django projects only. Do you have many django apps with different users? Do you want to use only one of those apps

An orgizational tool to keep track of tasks/projects and the time spent on them.

Django-Task-Manager Task Tracker using Python Django About The Project This project is an orgizational tool to keep track of tasks/projects and the ti

Django Fett is an incomplete code generator used on several projects

Django Fett Django Fett is an incomplete code generator used on several projects. This is an attempt to clean it up and make it public for consumption

Get inside your stronghold and make all your Django views default login_required

Stronghold Get inside your stronghold and make all your Django views default login_required Stronghold is a very small and easy to use django app that

DCM is a set of tools that helps you to keep your data in your Django Models consistent.
DCM is a set of tools that helps you to keep your data in your Django Models consistent.

Django Consistency Model DCM is a set of tools that helps you to keep your data in your Django Models consistent. Motivation You have a lot of legacy

Exploit Discord's cache system to remote upload payloads on Discord users machines
Exploit Discord's cache system to remote upload payloads on Discord users machines

Exploit Discord's cache system to hide payloads PoC Remote upload embedded payload from image using EOF to Discord users machines through cache. Depen

A generic system for filtering Django QuerySets based on user selections

Django Filter Django-filter is a reusable Django application allowing users to declaratively add dynamic QuerySet filtering from URL parameters. Full

A Django based shop system

django-SHOP Django-SHOP aims to be a the easy, fun and fast e-commerce counterpart to django-CMS. Here you can find the full documentation for django-

Login System Django

Login-System-Django Login System Using Django Tech Used Django Python Html Run Locally Clone project git clone https://link-to-project Get project for

Owner
Adam Johnson
🦄 @django technical board member 🇬🇧 @djangolondon co-organizer ✍ AWS/Django/Python Author and Consultant
Adam Johnson
Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.

Django-environ django-environ allows you to use Twelve-factor methodology to configure your Django application with environment variables. import envi

Daniele Faraglia 2.7k Jan 7, 2023
Rosetta is a Django application that eases the translation process of your Django projects

Rosetta Rosetta is a Django application that facilitates the translation process of your Django projects. Because it doesn't export any models, Rosett

Marco Bonetti 909 Dec 26, 2022
Duckiter will Automatically dockerize your Django projects.

Duckiter Duckiter will Automatically dockerize your Django projects. Requirements : - python version : python version 3.6 or upper version - OS :

soroush safari 23 Sep 16, 2021
A simple Django dev environment setup with docker for demo purposes for GalsenDev community

GalsenDEV Docker Demo This is a basic Django dev environment setup with docker and docker-compose for a GalsenDev Meetup. The main purposes was to mak

null 3 Jul 3, 2021
Wagtail - Vue - Django : The initial environment of full-stack local dev web app with wagtail and vue

Wagtail - Vue - Django : The initial environment of full-stack local dev web app with wagtail and vue. A demo to show how to use .vue files inside django app.

Quang PHAM 2 Oct 20, 2022
Django Serverless Cron - Run cron jobs easily in a serverless environment

Django Serverless Cron - Run cron jobs easily in a serverless environment

Paul Onteri 41 Dec 16, 2022
Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly.

Cookiecutter Django Powered by Cookiecutter, Cookiecutter Django is a framework for jumpstarting production-ready Django projects quickly. Documentati

Daniel Feldroy 10k Dec 31, 2022
:couple: Multi-user accounts for Django projects

django-organizations Summary Groups and multi-user account management Author Ben Lopatin (http://benlopatin.com / https://wellfire.co) Status Separate

Ben Lopatin 1.1k Jan 1, 2023
A handy tool for generating Django-based backend projects without coding. On the other hand, it is a code generator of the Django framework.

Django Sage Painless The django-sage-painless is a valuable package based on Django Web Framework & Django Rest Framework for high-level and rapid web

sageteam 51 Sep 15, 2022
Analytics services for Django projects

django-analytical The django-analytical application integrates analytics services into a Django project. Using an analytics service with a Django proj

Jazzband 1.1k Dec 31, 2022