def test_util_exceptions(self):
        """
        Test exceptions for a couple of methods:

           - method :meth:`~pythonforandroid.util.BuildInterruptingException`
           - method :meth:`~pythonforandroid.util.handle_build_exception`

        Here we create an exception with method
        :meth:`~pythonforandroid.util.BuildInterruptingException` and we run it
        inside method :meth:`~pythonforandroid.util.handle_build_exception` to
        make sure that it raises an `SystemExit`.
        """
        exc = util.BuildInterruptingException(
            "missing dependency xxx", instructions="pip install --user xxx")
        with self.assertRaises(SystemExit):
            util.handle_build_exception(exc)
Exemple #2
0
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)
    shutil.rmtree(
        '_prebuild/skytemple_randomizer/frontend/common_web/node_modules')
    os.chdir(
        os.path.join('_prebuild', 'skytemple_randomizer', 'frontend',
                     'common_web'))
    os.system(f'npm install --only=prod')
    os.chdir(absp)

    sys.argv = ['p4a', 'apk']
    for k, v in options.items():
        sys.argv += [f'--{k}', str(v)]
    sys.argv += ['--no-optimize-python']
    if os.getenv('SKYTEMPLE_BUILD_PRODUCTION', False):
        sys.argv += ['--release', '--sign']

    try:
        from pythonforandroid.toolchain import ToolchainCL
        ToolchainCL()
    except BuildInterruptingException as exc:
        handle_build_exception(exc)
        error = True
except Exception as ex:
    traceback.print_exc()
    error = True
finally:
    shutil.rmtree(os.path.join(absp, '_prebuild'))

if error:
    print("Build error.")
    exit(1)
def main():
    try:
        ToolchainCL()
    except BuildInterruptingException as exc:
        handle_build_exception(exc)