-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added build failure if run under Python 2 * Made Python 2 check more robust * Style fixes * Changed minimum python3 minor version to 3.4 * Added a deprecation warning log to the Python 2 recipe during build * Updated tox.ini to run py2 tests only on android module * Added tests for Python version checking * Added test for Python 2 running long enough to exit nicely * Pep8 and code style improvements * Added descriptions for flake8 exceptions * Hardcoded python2 tests in tox.ini * Removed E127 and E129 global disable
- Loading branch information
Showing
12 changed files
with
179 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from pythonforandroid.recommendations import check_python_version | ||
from pythonforandroid.util import BuildInterruptingException, handle_build_exception | ||
|
||
|
||
def main(): | ||
""" | ||
Main entrypoint for running python-for-android as a script. | ||
""" | ||
|
||
try: | ||
# Check the Python version before importing anything heavier than | ||
# the util functions. This lets us provide a nice message about | ||
# incompatibility rather than having the interpreter crash if it | ||
# reaches unsupported syntax from a newer Python version. | ||
check_python_version() | ||
|
||
from pythonforandroid.toolchain import ToolchainCL | ||
ToolchainCL() | ||
except BuildInterruptingException as exc: | ||
handle_build_exception(exc) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
# This test is a special case that we expect to run under Python 2, so | ||
# include the necessary compatibility imports: | ||
try: # Python 3 | ||
from unittest import mock | ||
except ImportError: # Python 2 | ||
import mock | ||
|
||
from pythonforandroid.recommendations import PY2_ERROR_TEXT | ||
from pythonforandroid import entrypoints | ||
|
||
|
||
def test_main_python2(): | ||
"""Test that running under Python 2 leads to the build failing, while | ||
running under a suitable version works fine. | ||
Note that this test must be run *using* Python 2 to truly test | ||
that p4a can reach the Python version check before importing some | ||
Python-3-only syntax and crashing. | ||
""" | ||
|
||
# Under Python 2, we should get a normal control flow exception | ||
# that is handled properly, not any other type of crash | ||
handle_exception_path = 'pythonforandroid.entrypoints.handle_build_exception' | ||
with mock.patch('sys.version_info') as fake_version_info, \ | ||
mock.patch(handle_exception_path) as handle_build_exception: # noqa: E127 | ||
|
||
fake_version_info.major = 2 | ||
fake_version_info.minor = 7 | ||
|
||
def check_python2_exception(exc): | ||
"""Check that the exception message is Python 2 specific.""" | ||
assert exc.message == PY2_ERROR_TEXT | ||
handle_build_exception.side_effect = check_python2_exception | ||
|
||
entrypoints.main() | ||
|
||
handle_build_exception.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters