|
1 | 1 | """Simple functions for checking dependency versions."""
|
2 | 2 |
|
| 3 | +import sys |
3 | 4 | from distutils.version import LooseVersion
|
4 | 5 | from os.path import join
|
| 6 | + |
5 | 7 | from pythonforandroid.logger import info, warning
|
6 | 8 | from pythonforandroid.util import BuildInterruptingException
|
7 | 9 |
|
@@ -182,3 +184,37 @@ def check_ndk_api(ndk_api, android_api):
|
182 | 184 |
|
183 | 185 | if ndk_api < MIN_NDK_API:
|
184 | 186 | warning(OLD_NDK_API_MESSAGE)
|
| 187 | + |
| 188 | + |
| 189 | +MIN_PYTHON_MAJOR_VERSION = 3 |
| 190 | +MIN_PYTHON_MINOR_VERSION = 4 |
| 191 | +MIN_PYTHON_VERSION = LooseVersion('{major}.{minor}'.format(major=MIN_PYTHON_MAJOR_VERSION, |
| 192 | + minor=MIN_PYTHON_MINOR_VERSION)) |
| 193 | +PY2_ERROR_TEXT = ( |
| 194 | + 'python-for-android no longer supports running under Python 2. Either upgrade to ' |
| 195 | + 'Python {min_version} or higher (recommended), or revert to python-for-android 2019.07.08. ' |
| 196 | + 'Note that you *can* still target Python 2 on Android by including python2 in your ' |
| 197 | + 'requirements.').format( |
| 198 | + min_version=MIN_PYTHON_VERSION) |
| 199 | + |
| 200 | +PY_VERSION_ERROR_TEXT = ( |
| 201 | + 'Your Python version {user_major}.{user_minor} is not supported by python-for-android, ' |
| 202 | + 'please upgrade to {min_version} or higher.' |
| 203 | + ).format( |
| 204 | + user_major=sys.version_info.major, |
| 205 | + user_minor=sys.version_info.minor, |
| 206 | + min_version=MIN_PYTHON_VERSION) |
| 207 | + |
| 208 | + |
| 209 | +def check_python_version(): |
| 210 | + # Python 2 special cased because it's a major transition. In the |
| 211 | + # future the major or minor versions can increment more quietly. |
| 212 | + if sys.version_info.major == 2: |
| 213 | + raise BuildInterruptingException(PY2_ERROR_TEXT) |
| 214 | + |
| 215 | + if ( |
| 216 | + sys.version_info.major < MIN_PYTHON_MAJOR_VERSION or |
| 217 | + sys.version_info.minor < MIN_PYTHON_MINOR_VERSION |
| 218 | + ): |
| 219 | + |
| 220 | + raise BuildInterruptingException(PY_VERSION_ERROR_TEXT) |
0 commit comments