Coverage for cc_modules/cc_pythonversion.py: 50%
10 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-08 23:14 +0000
1#!/usr/bin/env python
3"""
4camcops_server/cc_modules/cc_pythonversion.py
6===============================================================================
8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
11 This file is part of CamCOPS.
13 CamCOPS is free software: you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 CamCOPS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
26===============================================================================
28**Single place to determine the Python version required.**
30Python v3.6 was required as of CamCOPS v2.3.1, 2019. That enables:
32- f-strings (v3.6)
34Python v3.7 was required as of CamCOPS v2.4.12, 2021. That enables:
36- dataclasses (v3.7)
38Not yet available:
40- assignment expressions, the "walrus" operator, ``:=`` (v3.8)
41- positional-only parameters, ``/`` (v3.8)
42- f-string ``=`` syntax to debug a variable (v3.8)
44- new dictionary merge/update syntax (v3.9)
45- string prefix/suffix removal functions (v3.9)
46- use of generics like ``list`` (not just ``List``) for type hinting (v3.9)
48- ``match/case`` statement, like C++'s ``switch`` (v3.10)
49- ``|`` as well as ``Union`` for type hints (v3.10)
50- explicit ``typing.TypeAlias`` annotation (v3.10)
52Note that one can set the environment variable ``PYTHONDEVMODE=1`` to enable
53extra checks, such as whether there are deprecation warnings with newer Python
54versions.
56Note that Python versions are referred to in:
58- this file
59- ``.github/workflows/*``
60- ``server/setup.py``
61- ``server/docker/dockerfiles/camcops.Dockerfile``
62- ``server/tools/MAKE_LINUX_PACKAGES.py``
64and separately (not necessarily within a CamCOPS virtual environment) in
66- ``server/tools/install_virtualenv.py``
67- ``tablet_qt/tools/build_qt.py``
69"""
71import sys
73MINIMUM_PYTHON_VERSION = (3, 7)
76def assert_minimum_python_version():
77 """
78 Asserts that this version of Python meets our minimum requirements.
79 This function should be used except in installation environments where
80 CamCOPS modules are unavailable.
82 Raises:
83 AssertionError
85 Note that this module/function should use only Python 2 syntax!
87 """
88 if sys.version_info < MINIMUM_PYTHON_VERSION:
89 required = ".".join(str(x) for x in MINIMUM_PYTHON_VERSION)
90 actual = ".".join(str(x) for x in sys.version_info)
91 raise AssertionError(
92 "Need Python %s or higher; this is %s" % (required, actual)
93 )
96if __name__ == "__main__":
97 assert_minimum_python_version()