=====================
django-version-checks
=====================
.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/django-version-checks/main.yml?branch=main&style=for-the-badge
:target: https://github.com/adamchainz/django-version-checks/actions?workflow=CI
.. image:: https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge
:target: https://github.com/adamchainz/django-version-checks/actions?workflow=CI
.. image:: https://img.shields.io/pypi/v/django-version-checks.svg?style=for-the-badge
:target: https://pypi.org/project/django-version-checks/
.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge
:target: https://github.com/psf/black
.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge
:target: https://github.com/pre-commit/pre-commit
:alt: pre-commit
System checks for your project's environment.
Requirements
============
Python 3.8 to 3.12 supported.
Django 3.2 to 5.0 supported.
----
**Want to work smarter and faster?**
Check out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers many ways to improve your development experience.
----
Installation
============
First, install with **pip**:
.. code-block:: bash
python -m pip install django-version-checks
Second, add the app to your ``INSTALLED_APPS`` setting:
.. code-block:: python
INSTALLED_APPS = [
...,
"django_version_checks",
...,
]
Third, add a ``VERSION_CHECKS`` setting with the version checks you want to enforce (as documented below).
For example:
.. code-block:: python
VERSION_CHECKS = {
"python": "==3.9.*",
}
Usage
=====
See also the `introductory blog post <https://adamj.eu/tech/2020/12/14/introducing-django-version-checks/>`__.
django-version-checks adds several `system checks <https://docs.djangoproject.com/en/stable/topics/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 mismatched dependency versions are likely to cause ``ImportError``\s or other import-time problems, before system checks run.
To version check your Python dependencies, try `pip-lock <https://github.com/adamchainz/pip-lock/>`__.
Checks use the `PEP 440 specifier format <https://www.python.org/dev/peps/pep-0440/#id53>`__ 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:
.. code-block:: python
VERSION_CHECKS = {
"mysql": "~=10.5.8",
}
…or as a dictionary mapping database aliases to their specifiers:
.. code-block:: python
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 <https://docs.djangoproject.com/en/3.1/ref/checks/#builtin-tags>`__).
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>``).
``postgresql`` check
--------------------
This check compares the current version of PostgreSQL to the given specifier.
The range can specified either as a single string:
.. code-block:: python
VERSION_CHECKS = {
"postgresql": "~=12.2",
}
…or as a dictionary mapping database aliases to their specifiers:
.. code-block:: python
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 <https://docs.djangoproject.com/en/3.1/ref/checks/#builtin-tags>`__).
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>``).
``python`` check
----------------
This check compares the current version of Python to the given single specifier:
.. code-block:: python
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>``).
``sqlite`` check
--------------------
This check compares the current version of SQLite to the given single specifier:
.. code-block:: python
VERSION_CHECKS = {
"sqlite": "~=3.37",
}
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 <https://docs.djangoproject.com/en/3.1/ref/checks/#builtin-tags>`__).
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:
.. code-block:: python
VERSION_CHECKS = {
"python": "~=3.8.6",
}
Second, we rewrite the specifier to allow versions of Python 3.9:
.. code-block:: python
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 <https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/>`__.
Fourth, we change the specifier again to allow Python 3.9 only:
.. code-block:: python
VERSION_CHECKS = {
"python": "~=3.9.1",
}
And we’re upgraded! 🎉
Raw data
{
"_id": null,
"home_page": "https://github.com/adamchainz/django-version-checks",
"name": "django-version-checks",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "Django",
"author": "Adam Johnson",
"author_email": "me@adamj.eu",
"download_url": "https://files.pythonhosted.org/packages/4a/4f/63b2c2e69d8216ed7fa936b6950312ba842f8a35d468b053d5e5e277f5cf/django_version_checks-1.11.0.tar.gz",
"platform": null,
"description": "=====================\ndjango-version-checks\n=====================\n\n.. image:: https://img.shields.io/github/actions/workflow/status/adamchainz/django-version-checks/main.yml?branch=main&style=for-the-badge\n :target: https://github.com/adamchainz/django-version-checks/actions?workflow=CI\n\n.. image:: https://img.shields.io/badge/Coverage-100%25-success?style=for-the-badge\n :target: https://github.com/adamchainz/django-version-checks/actions?workflow=CI\n\n.. image:: https://img.shields.io/pypi/v/django-version-checks.svg?style=for-the-badge\n :target: https://pypi.org/project/django-version-checks/\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg?style=for-the-badge\n :target: https://github.com/psf/black\n\n.. image:: https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=for-the-badge\n :target: https://github.com/pre-commit/pre-commit\n :alt: pre-commit\n\nSystem checks for your project's environment.\n\nRequirements\n============\n\nPython 3.8 to 3.12 supported.\n\nDjango 3.2 to 5.0 supported.\n\n----\n\n**Want to work smarter and faster?**\nCheck out my book `Boost Your Django DX <https://adamchainz.gumroad.com/l/byddx>`__ which covers many ways to improve your development experience.\n\n----\n\nInstallation\n============\n\nFirst, install with **pip**:\n\n.. code-block:: bash\n\n python -m pip install django-version-checks\n\nSecond, add the app to your ``INSTALLED_APPS`` setting:\n\n.. code-block:: python\n\n INSTALLED_APPS = [\n ...,\n \"django_version_checks\",\n ...,\n ]\n\nThird, add a ``VERSION_CHECKS`` setting with the version checks you want to enforce (as documented below).\nFor example:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"python\": \"==3.9.*\",\n }\n\nUsage\n=====\n\nSee also the `introductory blog post <https://adamj.eu/tech/2020/12/14/introducing-django-version-checks/>`__.\n\ndjango-version-checks adds several `system checks <https://docs.djangoproject.com/en/stable/topics/checks/>`__ that can help ensure that the current environment has the right versions of Python, databases, etc.\nThis is useful when coordinating upgrades across all your infrastructure.\n\nNote that django-version-checks does not check the versions of your Python dependencies.\nThis is because mismatched dependency versions are likely to cause ``ImportError``\\s or other import-time problems, before system checks run.\nTo version check your Python dependencies, try `pip-lock <https://github.com/adamchainz/pip-lock/>`__.\n\nChecks use the `PEP 440 specifier format <https://www.python.org/dev/peps/pep-0440/#id53>`__ via the ``packaging`` module.\nThis is the same format used by pip, and allows some flexibility in specifying valid version ranges.\nThe ``~=`` operator is particularly useful.\nFor example, you can use ``~=3.9.1`` to mean \u201c3.9.1+, but less than 3.10.0\u201d, allowing environments to take on patch releases without changes, but nothing more.\n\nThe individual checks are documented below.\nEach occupies a key in the ``VERSION_CHECKS`` dictionary, and documents its supported types for specifiers.\nIf a check is misconfigured with a bad type or specifier you will see one of these system check errors:\n\n* ``dvc.E001``: ``<check>`` is misconfigured. Expected a ``<type>`` but got ``<value>``.\n* ``dvc.E002``: ``<check>`` is misconfigured. ``<value>`` is not a valid PEP440 specifier.\n\n``mysql`` check\n----------------\n\nThis check compares the current version of MariaDB/MySQL to the given specifier.\nThe range can specified either as a single string:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"mysql\": \"~=10.5.8\",\n }\n\n\u2026or as a dictionary mapping database aliases to their specifiers:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"postgresql\": {\n \"default\": \"~=10.5.8\",\n \"analytics\": \"~=10.4.17\",\n },\n }\n\nNote: 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).\nSee (`docs <https://docs.djangoproject.com/en/3.1/ref/checks/#builtin-tags>`__).\n\nIf this check fails, the system check will report:\n\n* ``dvc.E005``: The current version of MariaDB/MySQL (``<version>``) for the ``<alias>`` database connection does not match the specified range (``<range>``).\n\n``postgresql`` check\n--------------------\n\nThis check compares the current version of PostgreSQL to the given specifier.\nThe range can specified either as a single string:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"postgresql\": \"~=12.2\",\n }\n\n\u2026or as a dictionary mapping database aliases to their specifiers:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"postgresql\": {\n \"default\": \"~=12.2\",\n \"analytics\": \"~=13.1\",\n },\n }\n\nNote: 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).\nSee (`docs <https://docs.djangoproject.com/en/3.1/ref/checks/#builtin-tags>`__).\n\nIf this check fails, the system check will report:\n\n* ``dvc.E004``: The current version of PostgreSQL (``<version>``) for the ``<alias>`` database connection does not match the specified range (``<range>``).\n\n``python`` check\n----------------\n\nThis check compares the current version of Python to the given single specifier:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"python\": \"~=3.9.1\",\n }\n\nIf this check fails, the system check will report:\n\n* ``dvc.E003``: The current version of Python (``<version>``) does not match the specified range (``<range>``).\n\n``sqlite`` check\n--------------------\n\nThis check compares the current version of SQLite to the given single specifier:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"sqlite\": \"~=3.37\",\n }\n\nNote: 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).\nSee (`docs <https://docs.djangoproject.com/en/3.1/ref/checks/#builtin-tags>`__).\n\nIf this check fails, the system check will report:\n\n* ``dvc.E006``: The current version of SQLite (``<version>``) does not match the specified range (``<range>``).\n\nExample Upgrade\n===============\n\nLet\u2019s walk through using django-version-checks to upgrade Python from version 3.8 to 3.9.\nWe have an infrastructure consisting of CI, staging, and production environments, and several developers\u2019 development machines.\n\nFirst, we add a pre-existing check to ensure that all environments are on Python 3.8:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"python\": \"~=3.8.6\",\n }\n\nSecond, we rewrite the specifier to allow versions of Python 3.9:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"python\": \">=3.8.6,<3.10.0\",\n }\n\nThird, we upgrade our infrastructure.\nWe\u2019d probably upgrade in the order: CI, development environments, staging, production.\nEach environment should have an automated run of ``manage.py check``, as per the `Django deployment checklist <https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/>`__.\n\nFourth, we change the specifier again to allow Python 3.9 only:\n\n.. code-block:: python\n\n VERSION_CHECKS = {\n \"python\": \"~=3.9.1\",\n }\n\nAnd we\u2019re upgraded! \ud83c\udf89\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "System checks for your project's environment.",
"version": "1.11.0",
"project_urls": {
"Changelog": "https://github.com/adamchainz/django-version-checks/blob/main/CHANGELOG.rst",
"Homepage": "https://github.com/adamchainz/django-version-checks",
"Mastodon": "https://fosstodon.org/@adamchainz",
"Twitter": "https://twitter.com/adamchainz"
},
"split_keywords": [
"django"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5217dc46f7b0dccd670f29ce3b5bf4ca66c20cc88626fa251a34e0338e0b0aad",
"md5": "a3e486c6eb445b129bc91698055c8184",
"sha256": "9d1a147fab2290e1f567446ba47af3fdd6d50f9491475a06f03178bd73163142"
},
"downloads": -1,
"filename": "django_version_checks-1.11.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a3e486c6eb445b129bc91698055c8184",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 7747,
"upload_time": "2023-10-11T09:32:53",
"upload_time_iso_8601": "2023-10-11T09:32:53.510798Z",
"url": "https://files.pythonhosted.org/packages/52/17/dc46f7b0dccd670f29ce3b5bf4ca66c20cc88626fa251a34e0338e0b0aad/django_version_checks-1.11.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4a4f63b2c2e69d8216ed7fa936b6950312ba842f8a35d468b053d5e5e277f5cf",
"md5": "b514bdf2eaa2666216616048f810d02c",
"sha256": "4285ac540af107ef8741ad204bdedd239f2ddc0e7dd45fb6e81609aa9f93ca58"
},
"downloads": -1,
"filename": "django_version_checks-1.11.0.tar.gz",
"has_sig": false,
"md5_digest": "b514bdf2eaa2666216616048f810d02c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 10145,
"upload_time": "2023-10-11T09:32:54",
"upload_time_iso_8601": "2023-10-11T09:32:54.734927Z",
"url": "https://files.pythonhosted.org/packages/4a/4f/63b2c2e69d8216ed7fa936b6950312ba842f8a35d468b053d5e5e277f5cf/django_version_checks-1.11.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-11 09:32:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adamchainz",
"github_project": "django-version-checks",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "django-version-checks"
}