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

1#!/usr/bin/env python 

2 

3""" 

4camcops_server/cc_modules/cc_pythonversion.py 

5 

6=============================================================================== 

7 

8 Copyright (C) 2012, University of Cambridge, Department of Psychiatry. 

9 Created by Rudolf Cardinal (rnc1001@cam.ac.uk). 

10 

11 This file is part of CamCOPS. 

12 

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. 

17 

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. 

22 

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/>. 

25 

26=============================================================================== 

27 

28**Single place to determine the Python version required.** 

29 

30Python v3.6 was required as of CamCOPS v2.3.1, 2019. That enables: 

31 

32- f-strings (v3.6) 

33 

34Python v3.7 was required as of CamCOPS v2.4.12, 2021. That enables: 

35 

36- dataclasses (v3.7) 

37 

38Not yet available: 

39 

40- assignment expressions, the "walrus" operator, ``:=`` (v3.8) 

41- positional-only parameters, ``/`` (v3.8) 

42- f-string ``=`` syntax to debug a variable (v3.8) 

43 

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) 

47 

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) 

51 

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. 

55 

56Note that Python versions are referred to in: 

57 

58- this file 

59- ``.github/workflows/*`` 

60- ``server/setup.py`` 

61- ``server/docker/dockerfiles/camcops.Dockerfile`` 

62- ``server/tools/MAKE_LINUX_PACKAGES.py`` 

63 

64and separately (not necessarily within a CamCOPS virtual environment) in 

65 

66- ``server/tools/install_virtualenv.py`` 

67- ``tablet_qt/tools/build_qt.py`` 

68 

69""" 

70 

71import sys 

72 

73MINIMUM_PYTHON_VERSION = (3, 7) 

74 

75 

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. 

81 

82 Raises: 

83 AssertionError 

84 

85 Note that this module/function should use only Python 2 syntax! 

86 

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 ) 

94 

95 

96if __name__ == "__main__": 

97 assert_minimum_python_version()