Skip to content

Commit

Permalink
Added missing recommendations command and cleaned up code (#1975)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
inclement authored Feb 16, 2020
1 parent f771ccb commit 6a7e6ff
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
30 changes: 22 additions & 8 deletions pythonforandroid/recommendations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,39 @@
MIN_NDK_VERSION = 19
MAX_NDK_VERSION = 20

# DO NOT CHANGE LINE FORMAT: buildozer parses the existence of a RECOMMENDED_NDK_VERSION
RECOMMENDED_NDK_VERSION = "19b"

NDK_DOWNLOAD_URL = "https://developer.android.com/ndk/downloads/"

# Important log messages
NEW_NDK_MESSAGE = 'Newer NDKs may not be fully supported by p4a.'
UNKNOWN_NDK_MESSAGE = (
'Could not determine NDK version, no source.properties in the NDK dir'
'Could not determine NDK version, no source.properties in the NDK dir.'
)
PARSE_ERROR_NDK_MESSAGE = (
'Could not parse $NDK_DIR/source.properties, not checking NDK version'
'Could not parse $NDK_DIR/source.properties, not checking NDK version.'
)
READ_ERROR_NDK_MESSAGE = (
'Unable to read the NDK version from the given directory {ndk_dir}'
'Unable to read the NDK version from the given directory {ndk_dir}.'
)
ENSURE_RIGHT_NDK_MESSAGE = (
'Make sure your NDK version is greater than {min_supported}. If you get '
'build errors, download the recommended NDK {rec_version} from {ndk_url}'
'build errors, download the recommended NDK {rec_version} from {ndk_url}.'
)
NDK_LOWER_THAN_SUPPORTED_MESSAGE = (
'The minimum supported NDK version is {min_supported}. '
'You can download it from {ndk_url}'
'You can download it from {ndk_url}.'
)
UNSUPPORTED_NDK_API_FOR_ARMEABI_MESSAGE = (
'Asked to build for armeabi architecture with API '
'{req_ndk_api}, but API {max_ndk_api} or greater does not support armeabi'
'{req_ndk_api}, but API {max_ndk_api} or greater does not support armeabi.'
)
CURRENT_NDK_VERSION_MESSAGE = (
'Found NDK version {ndk_version}'
)
RECOMMENDED_NDK_VERSION_MESSAGE = (
'Maximum recommended NDK version is {recommended_ndk_version}'
'Maximum recommended NDK version is {recommended_ndk_version}, but newer versions may work.'
)


Expand Down Expand Up @@ -187,7 +189,7 @@ def check_ndk_api(ndk_api, android_api):


MIN_PYTHON_MAJOR_VERSION = 3
MIN_PYTHON_MINOR_VERSION = 4
MIN_PYTHON_MINOR_VERSION = 6
MIN_PYTHON_VERSION = LooseVersion('{major}.{minor}'.format(major=MIN_PYTHON_MAJOR_VERSION,
minor=MIN_PYTHON_MINOR_VERSION))
PY2_ERROR_TEXT = (
Expand Down Expand Up @@ -218,3 +220,15 @@ def check_python_version():
):

raise BuildInterruptingException(PY_VERSION_ERROR_TEXT)


def print_recommendations():
"""
Print the main recommended dependency versions as simple key-value pairs.
"""
print('Min supported NDK version: {}'.format(MIN_NDK_VERSION))
print('Recommended NDK version: {}'.format(RECOMMENDED_NDK_VERSION))
print('Min target API: {}'.format(MIN_TARGET_API))
print('Recommended target API: {}'.format(RECOMMENDED_TARGET_API))
print('Min NDK API: {}'.format(MIN_NDK_API))
print('Recommended NDK API: {}'.format(RECOMMENDED_NDK_API))
5 changes: 4 additions & 1 deletion pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pythonforandroid import __version__
from pythonforandroid.pythonpackage import get_dep_names_of_package
from pythonforandroid.recommendations import (
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API)
RECOMMENDED_NDK_API, RECOMMENDED_TARGET_API, print_recommendations)
from pythonforandroid.util import BuildInterruptingException
from pythonforandroid.entrypoints import main

Expand Down Expand Up @@ -1163,6 +1163,9 @@ def _adb(self, commands):
sys.stdout.write(line)
sys.stdout.flush()

def recommendations(self, args):
print_recommendations()

def build_status(self, _args):
"""Print the status of the specified build. """
print('{Style.BRIGHT}Bootstraps whose core components are probably '
Expand Down
10 changes: 10 additions & 0 deletions tests/test_recommendations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
check_target_api,
read_ndk_version,
check_python_version,
print_recommendations,
MAX_NDK_VERSION,
RECOMMENDED_NDK_VERSION,
RECOMMENDED_TARGET_API,
Expand Down Expand Up @@ -237,3 +238,12 @@ def test_check_python_version(self):
fake_version_info.major = MIN_PYTHON_MAJOR_VERSION
fake_version_info.minor = MIN_PYTHON_MINOR_VERSION
check_python_version()

def test_print_recommendations(self):
"""
Simple test that the function actually runs.
"""
# The main failure mode is if the function tries to print a variable
# that doesn't actually exist, so simply running to check all the
# prints work is the most important test.
print_recommendations()

0 comments on commit 6a7e6ff

Please sign in to comment.