Skip to content

Commit 6a7e6ff

Browse files
authored
Added missing recommendations command and cleaned up code (#1975)
* Added missing recommendations command and cleaned up code * Added test for print_recommendations running correctly * Updated minimum Python version to 3.6 This should have been the original value, agreed in #1918 * Added a blank line to make pylint happy * Moved f-strings to format calls to preserve py2 compat in this file * Changed travis build to use Python 3.8 * Undid travis change, for merging in a separate PR
1 parent f771ccb commit 6a7e6ff

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

pythonforandroid/recommendations.py

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,39 @@
1111
MIN_NDK_VERSION = 19
1212
MAX_NDK_VERSION = 20
1313

14+
# DO NOT CHANGE LINE FORMAT: buildozer parses the existence of a RECOMMENDED_NDK_VERSION
1415
RECOMMENDED_NDK_VERSION = "19b"
16+
1517
NDK_DOWNLOAD_URL = "https://developer.android.com/ndk/downloads/"
1618

1719
# Important log messages
1820
NEW_NDK_MESSAGE = 'Newer NDKs may not be fully supported by p4a.'
1921
UNKNOWN_NDK_MESSAGE = (
20-
'Could not determine NDK version, no source.properties in the NDK dir'
22+
'Could not determine NDK version, no source.properties in the NDK dir.'
2123
)
2224
PARSE_ERROR_NDK_MESSAGE = (
23-
'Could not parse $NDK_DIR/source.properties, not checking NDK version'
25+
'Could not parse $NDK_DIR/source.properties, not checking NDK version.'
2426
)
2527
READ_ERROR_NDK_MESSAGE = (
26-
'Unable to read the NDK version from the given directory {ndk_dir}'
28+
'Unable to read the NDK version from the given directory {ndk_dir}.'
2729
)
2830
ENSURE_RIGHT_NDK_MESSAGE = (
2931
'Make sure your NDK version is greater than {min_supported}. If you get '
30-
'build errors, download the recommended NDK {rec_version} from {ndk_url}'
32+
'build errors, download the recommended NDK {rec_version} from {ndk_url}.'
3133
)
3234
NDK_LOWER_THAN_SUPPORTED_MESSAGE = (
3335
'The minimum supported NDK version is {min_supported}. '
34-
'You can download it from {ndk_url}'
36+
'You can download it from {ndk_url}.'
3537
)
3638
UNSUPPORTED_NDK_API_FOR_ARMEABI_MESSAGE = (
3739
'Asked to build for armeabi architecture with API '
38-
'{req_ndk_api}, but API {max_ndk_api} or greater does not support armeabi'
40+
'{req_ndk_api}, but API {max_ndk_api} or greater does not support armeabi.'
3941
)
4042
CURRENT_NDK_VERSION_MESSAGE = (
4143
'Found NDK version {ndk_version}'
4244
)
4345
RECOMMENDED_NDK_VERSION_MESSAGE = (
44-
'Maximum recommended NDK version is {recommended_ndk_version}'
46+
'Maximum recommended NDK version is {recommended_ndk_version}, but newer versions may work.'
4547
)
4648

4749

@@ -187,7 +189,7 @@ def check_ndk_api(ndk_api, android_api):
187189

188190

189191
MIN_PYTHON_MAJOR_VERSION = 3
190-
MIN_PYTHON_MINOR_VERSION = 4
192+
MIN_PYTHON_MINOR_VERSION = 6
191193
MIN_PYTHON_VERSION = LooseVersion('{major}.{minor}'.format(major=MIN_PYTHON_MAJOR_VERSION,
192194
minor=MIN_PYTHON_MINOR_VERSION))
193195
PY2_ERROR_TEXT = (
@@ -218,3 +220,15 @@ def check_python_version():
218220
):
219221

220222
raise BuildInterruptingException(PY_VERSION_ERROR_TEXT)
223+
224+
225+
def print_recommendations():
226+
"""
227+
Print the main recommended dependency versions as simple key-value pairs.
228+
"""
229+
print('Min supported NDK version: {}'.format(MIN_NDK_VERSION))
230+
print('Recommended NDK version: {}'.format(RECOMMENDED_NDK_VERSION))
231+
print('Min target API: {}'.format(MIN_TARGET_API))
232+
print('Recommended target API: {}'.format(RECOMMENDED_TARGET_API))
233+
print('Min NDK API: {}'.format(MIN_NDK_API))
234+
print('Recommended NDK API: {}'.format(RECOMMENDED_NDK_API))

pythonforandroid/toolchain.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pythonforandroid import __version__
1212
from pythonforandroid.pythonpackage import get_dep_names_of_package
1313
from pythonforandroid.recommendations import (
14-
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API)
14+
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API, print_recommendations)
1515
from pythonforandroid.util import BuildInterruptingException
1616
from pythonforandroid.entrypoints import main
1717

@@ -1163,6 +1163,9 @@ def _adb(self, commands):
11631163
sys.stdout.write(line)
11641164
sys.stdout.flush()
11651165

1166+
def recommendations(self, args):
1167+
print_recommendations()
1168+
11661169
def build_status(self, _args):
11671170
"""Print the status of the specified build. """
11681171
print('{Style.BRIGHT}Bootstraps whose core components are probably '

tests/test_recommendations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
check_target_api,
1010
read_ndk_version,
1111
check_python_version,
12+
print_recommendations,
1213
MAX_NDK_VERSION,
1314
RECOMMENDED_NDK_VERSION,
1415
RECOMMENDED_TARGET_API,
@@ -237,3 +238,12 @@ def test_check_python_version(self):
237238
fake_version_info.major = MIN_PYTHON_MAJOR_VERSION
238239
fake_version_info.minor = MIN_PYTHON_MINOR_VERSION
239240
check_python_version()
241+
242+
def test_print_recommendations(self):
243+
"""
244+
Simple test that the function actually runs.
245+
"""
246+
# The main failure mode is if the function tries to print a variable
247+
# that doesn't actually exist, so simply running to check all the
248+
# prints work is the most important test.
249+
print_recommendations()

0 commit comments

Comments
 (0)