Package: django-version-checks
System checks for your project’s environment.RequirementsPython 3.8 to 3.12 supported.Django 3.2 to 5.0 supported.Want to work smarter and faster?Check out my bookBoost Your Django DXwhich covers many ways to improve your development experience.InstallationFirst, install withpip:python-mpipinstalldjango-version-checksSecond, add the app to yourINSTALLED_APPSsetting:INSTALLED_APPS=[...,"django_version_checks",...,]Third, add aVERSION_CHECKSsetting with the version checks you want to enforce (as documented below).
For example:VERSION_CHECKS={"python":"==3.9.*",}UsageSee also theintroductory blog post.django-version-checks adds severalsystem checksthat 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 mismatched dependency versions are likely to causeImportErrors or other import-time problems, before system checks run.
To version check your Python dependencies, trypip-lock.Checks use thePEP 440 specifier formatvia thepackagingmodule.
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.1to 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 theVERSION_CHECKSdictionary, 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.mysqlcheckThis 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 duringmigrateor when usingcheck--database(Django 3.1+) /check--tagsdatabase(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>).postgresqlcheckThis 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 duringmigrateor when usingcheck--database(Django 3.1+) /check--tagsdatabase(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>).pythoncheckThis 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>).sqlitecheckThis check compares the current version of SQLite to the given single specifier:VERSION_CHECKS={"sqlite":"~=3.37",}Note: as a database check, Django will only run this duringmigrateor when usingcheck--database(Django 3.1+) /check--tagsdatabase(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 UpgradeLet’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 ofmanage.py check, as per theDjango deployment checklist.Fourth, we change the specifier again to allow Python 3.9 only:VERSION_CHECKS={"python":"~=3.9.1",}And we’re upgraded! 🎉