diff --git a/pythonforandroid/bdistapk.py b/pythonforandroid/bdistapk.py index 04e09d5391..fd293cb9ad 100644 --- a/pythonforandroid/bdistapk.py +++ b/pythonforandroid/bdistapk.py @@ -136,7 +136,7 @@ def _set_user_options(): for i, arg in enumerate(sys.argv): if arg.startswith('--'): if ('=' in arg or - (i < (len(sys.argv) - 1) and not sys.argv[i+1].startswith('-'))): + (i < (len(sys.argv) - 1) and not sys.argv[i+1].startswith('-'))): user_options.append((arg[2:].split('=')[0] + '=', None, None)) else: user_options.append((arg[2:], None, None)) diff --git a/pythonforandroid/bootstraps/pygame/build/build.py b/pythonforandroid/bootstraps/pygame/build/build.py index 46a6b64f25..1c08339413 100755 --- a/pythonforandroid/bootstraps/pygame/build/build.py +++ b/pythonforandroid/bootstraps/pygame/build/build.py @@ -133,10 +133,10 @@ def select(fn): fn = realpath(fn) assert(fn.startswith(d)) fn = fn[len(d):] - if (fn.startswith('/site-packages/') or - fn.startswith('/config/') or - fn.startswith('/lib-dynload/') or - fn.startswith('/libpymodules.so')): + if (fn.startswith('/site-packages/') + or fn.startswith('/config/') + or fn.startswith('/lib-dynload/') + or fn.startswith('/libpymodules.so')): return False return fn diff --git a/pythonforandroid/bootstraps/pygame/build/buildlib/argparse.py b/pythonforandroid/bootstraps/pygame/build/buildlib/argparse.py index 8d097d33b4..f8c3d305ef 100644 --- a/pythonforandroid/bootstraps/pygame/build/buildlib/argparse.py +++ b/pythonforandroid/bootstraps/pygame/build/buildlib/argparse.py @@ -651,8 +651,8 @@ def _split_lines(self, text, width): def _fill_text(self, text, width, indent): text = self._whitespace_matcher.sub(' ', text).strip() - return _textwrap.fill(text, width, initial_indent=indent, - subsequent_indent=indent) + return _textwrap.fill( + text, width, initial_indent=indent, subsequent_indent=indent) def _get_help_string(self, action): return action.help @@ -2070,8 +2070,8 @@ def _parse_optional(self, arg_string): # if multiple actions match, the option string was ambiguous if len(option_tuples) > 1: - options = ', '.join([option_string - for action, option_string, explicit_arg in option_tuples]) + options = ', '.join( + [option_string for action, option_string, explicit_arg in option_tuples]) tup = arg_string, options self.error(_('ambiguous option: %s could match %s') % tup) diff --git a/pythonforandroid/bootstraps/sdl2/build/build.py b/pythonforandroid/bootstraps/sdl2/build/build.py index ef60d63545..9d22fb5ec6 100644 --- a/pythonforandroid/bootstraps/sdl2/build/build.py +++ b/pythonforandroid/bootstraps/sdl2/build/build.py @@ -137,10 +137,10 @@ def select(fn): fn = realpath(fn) assert(fn.startswith(d)) fn = fn[len(d):] - if (fn.startswith('/site-packages/') or - fn.startswith('/config/') or - fn.startswith('/lib-dynload/') or - fn.startswith('/libpymodules.so')): + if (fn.startswith('/site-packages/') + or fn.startswith('/config/') + or fn.startswith('/lib-dynload/') + or fn.startswith('/libpymodules.so')): return False return fn diff --git a/pythonforandroid/bootstraps/service_only/build/build.py b/pythonforandroid/bootstraps/service_only/build/build.py index 9364b71b1b..29420cf23d 100755 --- a/pythonforandroid/bootstraps/service_only/build/build.py +++ b/pythonforandroid/bootstraps/service_only/build/build.py @@ -128,10 +128,10 @@ def select(fn): fn = realpath(fn) assert(fn.startswith(d)) fn = fn[len(d):] - if (fn.startswith('/site-packages/') or - fn.startswith('/config/') or - fn.startswith('/lib-dynload/') or - fn.startswith('/libpymodules.so')): + if (fn.startswith('/site-packages/') + or fn.startswith('/config/') + or fn.startswith('/lib-dynload/') + or fn.startswith('/libpymodules.so')): return False return fn diff --git a/pythonforandroid/bootstraps/webview/build/build.py b/pythonforandroid/bootstraps/webview/build/build.py index bcdf17b533..bc70b16c34 100755 --- a/pythonforandroid/bootstraps/webview/build/build.py +++ b/pythonforandroid/bootstraps/webview/build/build.py @@ -129,10 +129,10 @@ def select(fn): fn = realpath(fn) assert(fn.startswith(d)) fn = fn[len(d):] - if (fn.startswith('/site-packages/') or - fn.startswith('/config/') or - fn.startswith('/lib-dynload/') or - fn.startswith('/libpymodules.so')): + if (fn.startswith('/site-packages/') + or fn.startswith('/config/') + or fn.startswith('/lib-dynload/') + or fn.startswith('/libpymodules.so')): return False return fn diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index 8cba4553d4..9a2e84c770 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -23,14 +23,19 @@ class Context(object): will be instantiated and used to hold all the build state.''' env = environ.copy() - root_dir = None # the filepath of toolchain.py - storage_dir = None # the root dir where builds and dists will be stored - - build_dir = None # in which bootstraps are copied for building - # and recipes are built - dist_dir = None # the Android project folder where everything ends up - libs_dir = None # where Android libs are cached after build but - # before being placed in dists + # the filepath of toolchain.py + root_dir = None + # the root dir where builds and dists will be stored + storage_dir = None + + # in which bootstraps are copied for building + # and recipes are built + build_dir = None + # the Android project folder where everything ends up + dist_dir = None + # where Android libs are cached after build + # but before being placed in dists + libs_dir = None aars_dir = None ccache = None # whether to use ccache @@ -178,12 +183,14 @@ def prepare_build_environment(self, user_sdk_dir, user_ndk_dir, sdk_dir = None if user_sdk_dir: sdk_dir = user_sdk_dir - if sdk_dir is None: # This is the old P4A-specific var + # This is the old P4A-specific var + if sdk_dir is None: sdk_dir = environ.get('ANDROIDSDK', None) - if sdk_dir is None: # This seems used more conventionally + # This seems used more conventionally + if sdk_dir is None: sdk_dir = environ.get('ANDROID_HOME', None) - if sdk_dir is None: # Checks in the buildozer SDK dir, useful - # for debug tests of p4a + # Checks in the buildozer SDK dir, useful for debug tests of p4a + if sdk_dir is None: possible_dirs = glob.glob(expanduser(join( '~', '.buildozer', 'android', 'platform', 'android-sdk-*'))) possible_dirs = [d for d in possible_dirs if not @@ -842,8 +849,8 @@ def copylibs_function(soname, objs_paths, extra_link_dirs=[], env=None): if needso: lib = needso.group(1) if (lib not in needed_libs - and lib not in found_libs - and lib not in blacklist_libs): + and lib not in found_libs + and lib not in blacklist_libs): needed_libs.append(needso.group(1)) sofiles += found_sofiles diff --git a/pythonforandroid/recipe.py b/pythonforandroid/recipe.py index 20bab446e3..77256ce470 100644 --- a/pythonforandroid/recipe.py +++ b/pythonforandroid/recipe.py @@ -367,7 +367,7 @@ def download(self): debug('* Expected md5sum: {}'.format(expected_md5)) raise ValueError( ('Generated md5sum does not match expected md5sum ' - 'for {} recipe').format(self.name)) + 'for {} recipe').format(self.name)) else: info('{} download already cached, skipping'.format(self.name)) @@ -410,10 +410,11 @@ def unpack(self, arch): try: sh.unzip(extraction_filename) except (sh.ErrorReturnCode_1, sh.ErrorReturnCode_2): - pass # return code 1 means unzipping had - # warnings but did complete, - # apparently happens sometimes with - # github zips + # return code 1 means unzipping had + # warnings but did complete, + # apparently happens sometimes with + # github zips + pass import zipfile fileh = zipfile.ZipFile(extraction_filename, 'r') root_directory = fileh.filelist[0].filename.split('/')[0] @@ -765,8 +766,8 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True): env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() env['CFLAGS'] += ' -I' + env[ 'PYTHON_ROOT'] + '/include/python2.7' - env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \ - ' -lpython2.7' + env['LDFLAGS'] += ( + ' -L' + env['PYTHON_ROOT'] + '/lib' + ' -lpython2.7') elif self.ctx.python_recipe.from_crystax: ndk_dir_python = join(self.ctx.ndk_dir, 'sources', 'python', python_version) @@ -783,9 +784,9 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True): env['CFLAGS'] += ' -I' + env[ 'PYTHON_ROOT'] + '/include/python{}m'.format( python_short_version) - env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + \ - ' -lpython{}m'.format( - python_short_version) + env['LDFLAGS'] += ( + ' -L' + env['PYTHON_ROOT'] + '/lib' + + ' -lpython{}m'.format(python_short_version)) hppath = [] hppath.append(join(dirname(self.hostpython_location), 'Lib')) hppath.append(join(hppath[0], 'site-packages')) @@ -920,12 +921,14 @@ def get_recipe_env(self, arch): arch_noeabi=arch.arch.replace('eabi', '') ) env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' - env['CFLAGS'] += " -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" \ - " -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/include" \ - " -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}/include".format(**keys) + env['CFLAGS'] += ( + " -I{ctx.ndk_dir}/platforms/android-{ctx.android_api}/arch-{arch_noeabi}/usr/include" + + " -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/include" + + " -I{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}/include".format(**keys)) env['CXXFLAGS'] = env['CFLAGS'] + ' -frtti -fexceptions' - env['LDFLAGS'] += " -L{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}" \ - " -lgnustl_shared".format(**keys) + env['LDFLAGS'] += ( + " -L{ctx.ndk_dir}/sources/cxx-stl/gnu-libstdc++/{ctx.toolchain_version}/libs/{arch.arch}" + + " -lgnustl_shared".format(**keys)) return env diff --git a/pythonforandroid/recipes/Pillow/__init__.py b/pythonforandroid/recipes/Pillow/__init__.py index d713e19f54..0ddfb66a12 100644 --- a/pythonforandroid/recipes/Pillow/__init__.py +++ b/pythonforandroid/recipes/Pillow/__init__.py @@ -29,7 +29,8 @@ def get_recipe_env(self, arch=None): ndk_dir = self.ctx.ndk_platform ndk_lib_dir = join(ndk_dir, 'usr', 'lib') - ndk_include_dir = (join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') + ndk_include_dir = ( + join(self.ctx.ndk_dir, 'sysroot', 'usr', 'include') if py_ver == '2.7' else join(ndk_dir, 'usr', 'include')) png = self.get_recipe('png', self.ctx) @@ -48,23 +49,24 @@ def get_recipe_env(self, arch=None): cflags += ' -I{} -L{}'.format(jpeg_jni_dir, jpeg_lib_dir) cflags += ' -I{} -L{}'.format(ndk_include_dir, ndk_lib_dir) - gcc_lib = (shprint(sh.gcc, '-print-libgcc-file-name') - .stdout.decode('utf-8').split('\n')[0]) + gcc_lib = shprint( + sh.gcc, '-print-libgcc-file-name').stdout.decode('utf-8').split('\n')[0] gcc_include = join(dirname(gcc_lib), 'include') cflags += ' -I{}'.format(gcc_include) if self.ctx.ndk == 'crystax': - py_inc_dir = join(self.ctx.ndk_dir, 'sources', 'python', py_ver, - 'include', 'python') - py_lib_dir = join(self.ctx.ndk_dir, 'sources', 'python', py_ver, - 'libs', arch.arch) + py_inc_dir = join( + self.ctx.ndk_dir, 'sources', 'python', py_ver, 'include', 'python') + py_lib_dir = join( + self.ctx.ndk_dir, 'sources', 'python', py_ver, 'libs', arch.arch) cflags += ' -I{}'.format(py_inc_dir) env['LDFLAGS'] += ' -L{} -lpython{}m'.format(py_lib_dir, py_ver) env['LDFLAGS'] += ' {} -L{}'.format(env['CFLAGS'], self.ctx.libs_dir) if cflags not in env['CFLAGS']: env['CFLAGS'] += cflags - env['LDSHARED'] = '{} {}'.format(env['CC'], + env['LDSHARED'] = '{} {}'.format( + env['CC'], '-pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions') return env diff --git a/pythonforandroid/recipes/android/__init__.py b/pythonforandroid/recipes/android/__init__.py index b8b10e7d05..3c96a5fd82 100644 --- a/pythonforandroid/recipes/android/__init__.py +++ b/pythonforandroid/recipes/android/__init__.py @@ -55,22 +55,24 @@ def prebuild_arch(self, arch): 'JNI_NAMESPACE': jni_ns, } - with current_directory(self.get_build_dir(arch.arch)): - with open(join('android', 'config.pxi'), 'w') as fpxi: - with open(join('android', 'config.h'), 'w') as fh: - with open(join('android', 'config.py'), 'w') as fpy: - for key, value in config.items(): - fpxi.write(tpxi.format(key, repr(value))) - fpy.write(tpy.format(key, repr(value))) - fh.write(th.format(key, value if isinstance(value, int) - else '"{}"'.format(value))) - self.config_env[key] = str(value) - - if is_sdl2: - fh.write('JNIEnv *SDL_AndroidGetJNIEnv(void);\n') - fh.write('#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n') - elif is_pygame: - fh.write('JNIEnv *SDL_ANDROID_GetJNIEnv(void);\n') + with ( + current_directory(self.get_build_dir(arch.arch))), ( + open(join('android', 'config.pxi'), 'w')) as fpxi, ( + open(join('android', 'config.h'), 'w')) as fh, ( + open(join('android', 'config.py'), 'w')) as fpy: + for key, value in config.items(): + fpxi.write(tpxi.format(key, repr(value))) + fpy.write(tpy.format(key, repr(value))) + fh.write(th.format(key, + value if isinstance(value, int) + else '"{}"'.format(value))) + self.config_env[key] = str(value) + + if is_sdl2: + fh.write('JNIEnv *SDL_AndroidGetJNIEnv(void);\n') + fh.write('#define SDL_ANDROID_GetJNIEnv SDL_AndroidGetJNIEnv\n') + elif is_pygame: + fh.write('JNIEnv *SDL_ANDROID_GetJNIEnv(void);\n') recipe = AndroidRecipe() diff --git a/pythonforandroid/recipes/android/src/android/broadcast.py b/pythonforandroid/recipes/android/src/android/broadcast.py index 85b8728ed7..cb34cd9d19 100644 --- a/pythonforandroid/recipes/android/src/android/broadcast.py +++ b/pythonforandroid/recipes/android/src/android/broadcast.py @@ -61,8 +61,8 @@ def start(self): Handler = autoclass('android.os.Handler') self.handlerthread.start() self.handler = Handler(self.handlerthread.getLooper()) - self.context.registerReceiver(self.receiver, self.receiver_filter, None, - self.handler) + self.context.registerReceiver( + self.receiver, self.receiver_filter, None, self.handler) def stop(self): self.context.unregisterReceiver(self.receiver) diff --git a/pythonforandroid/recipes/hostpython2/__init__.py b/pythonforandroid/recipes/hostpython2/__init__.py index 19fd5fc83d..e47d16f7cd 100644 --- a/pythonforandroid/recipes/hostpython2/__init__.py +++ b/pythonforandroid/recipes/hostpython2/__init__.py @@ -31,10 +31,8 @@ def build_arch(self, arch): if exists('hostpython'): info('hostpython already exists, skipping build') - self.ctx.hostpython = join(self.get_build_dir(), - 'hostpython') - self.ctx.hostpgen = join(self.get_build_dir(), - 'hostpgen') + self.ctx.hostpython = join(self.get_build_dir(), 'hostpython') + self.ctx.hostpgen = join(self.get_build_dir(), 'hostpgen') return if 'LIBS' in os.environ: diff --git a/pythonforandroid/recipes/ifaddrs/__init__.py b/pythonforandroid/recipes/ifaddrs/__init__.py index f53cde1e00..5d6d4a0b9e 100644 --- a/pythonforandroid/recipes/ifaddrs/__init__.py +++ b/pythonforandroid/recipes/ifaddrs/__init__.py @@ -18,10 +18,9 @@ class IFAddrRecipe(CompiledComponentsPythonRecipe): def should_build(self, arch): """It's faster to build than check""" - return not (exists(join(self.ctx.libs_dir, arch.arch, 'libifaddrs.so')) - and exists(join(self.ctx.get_python_install_dir(), 'lib' - "libifaddrs.so")) - ) + return not ( + exists(join(self.ctx.libs_dir, arch.arch, 'libifaddrs.so')) + and exists(join(self.ctx.get_python_install_dir(), 'lib' "libifaddrs.so"))) def prebuild_arch(self, arch): """Make the build and target directories""" @@ -33,10 +32,10 @@ def prebuild_arch(self, arch): def build_arch(self, arch): """simple shared compile""" env = self.get_recipe_env(arch, with_flags_in_cc=False) - for path in (self.get_build_dir(arch.arch), - join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'), - join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include'), - ): + for path in ( + self.get_build_dir(arch.arch), + join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'), + join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include')): if not exists(path): info("creating {}".format(path)) shprint(sh.mkdir, '-p', path) @@ -56,12 +55,12 @@ def build_arch(self, arch): shprint(sh.cp, 'libifaddrs.so', self.ctx.get_libs_dir(arch.arch)) shprint(sh.cp, "libifaddrs.so", join(self.ctx.get_python_install_dir(), 'lib')) # drop header in to the Python include directory - shprint(sh.cp, "ifaddrs.h", join(self.ctx.get_python_install_dir(), - 'include/python{}'.format( - self.ctx.python_recipe.version[0:3] - ) - ) - ) + python_version = self.ctx.python_recipe.version[0:3] + shprint(sh.cp, "ifaddrs.h", + join( + self.ctx.get_python_install_dir(), + 'include/python{}'.format(python_version)) + ) include_path = join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include') shprint(sh.cp, "ifaddrs.h", include_path) diff --git a/pythonforandroid/recipes/libglob/__init__.py b/pythonforandroid/recipes/libglob/__init__.py index 09e69d1840..aa5925883f 100644 --- a/pythonforandroid/recipes/libglob/__init__.py +++ b/pythonforandroid/recipes/libglob/__init__.py @@ -38,10 +38,10 @@ def prebuild_arch(self, arch): def build_arch(self, arch): """simple shared compile""" env = self.get_recipe_env(arch, with_flags_in_cc=False) - for path in (self.get_build_dir(arch.arch), - join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'), - join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include'), - ): + for path in ( + self.get_build_dir(arch.arch), + join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Lib'), + join(self.ctx.python_recipe.get_build_dir(arch.arch), 'Include')): if not exists(path): info("creating {}".format(path)) shprint(sh.mkdir, '-p', path) diff --git a/pythonforandroid/recipes/libtorrent/__init__.py b/pythonforandroid/recipes/libtorrent/__init__.py index 74afe0ef24..f358f5166d 100644 --- a/pythonforandroid/recipes/libtorrent/__init__.py +++ b/pythonforandroid/recipes/libtorrent/__init__.py @@ -16,8 +16,9 @@ class LibtorrentRecipe(Recipe): patches = ['disable-so-version.patch', 'use-soname-python.patch', 'setup-lib-name.patch'] def should_build(self, arch): - return not (self.has_libs(arch, 'libboost_python.so', 'libboost_system.so', 'libtorrent_rasterbar.so') - and self.ctx.has_package('libtorrent', arch.arch) ) + return not ( + self.has_libs(arch, 'libboost_python.so', 'libboost_system.so', 'libtorrent_rasterbar.so') + and self.ctx.has_package('libtorrent', arch.arch)) def prebuild_arch(self, arch): super(LibtorrentRecipe, self).prebuild_arch(arch) @@ -54,12 +55,15 @@ def build_arch(self, arch): shutil.copyfile(join(env['BOOST_BUILD_PATH'], 'bin.v2/libs/system/build', build_subdirs, 'libboost_system.so'), join(self.ctx.get_libs_dir(arch.arch), 'libboost_system.so')) if 'openssl' in recipe.ctx.recipe_build_order: - shutil.copyfile(join(env['BOOST_BUILD_PATH'], 'bin.v2/libs/date_time/build', build_subdirs, 'libboost_date_time.so'), - join(self.ctx.get_libs_dir(arch.arch), 'libboost_date_time.so')) - shutil.copyfile(join(self.get_build_dir(arch.arch), 'bin', build_subdirs, 'libtorrent_rasterbar.so'), - join(self.ctx.get_libs_dir(arch.arch), 'libtorrent_rasterbar.so')) - shutil.copyfile(join(self.get_build_dir(arch.arch), 'bindings/python/bin', build_subdirs, 'libtorrent.so'), - join(self.ctx.get_site_packages_dir(arch.arch), 'libtorrent.so')) + shutil.copyfile( + join(env['BOOST_BUILD_PATH'], 'bin.v2/libs/date_time/build', build_subdirs, 'libboost_date_time.so'), + join(self.ctx.get_libs_dir(arch.arch), 'libboost_date_time.so')) + shutil.copyfile( + join(self.get_build_dir(arch.arch), 'bin', build_subdirs, 'libtorrent_rasterbar.so'), + join(self.ctx.get_libs_dir(arch.arch), 'libtorrent_rasterbar.so')) + shutil.copyfile( + join(self.get_build_dir(arch.arch), 'bindings/python/bin', build_subdirs, 'libtorrent.so'), + join(self.ctx.get_site_packages_dir(arch.arch), 'libtorrent.so')) def get_recipe_env(self, arch): env = super(LibtorrentRecipe, self).get_recipe_env(arch) diff --git a/pythonforandroid/recipes/libvorbis/__init__.py b/pythonforandroid/recipes/libvorbis/__init__.py index ea28e63f48..87c7a449db 100644 --- a/pythonforandroid/recipes/libvorbis/__init__.py +++ b/pythonforandroid/recipes/libvorbis/__init__.py @@ -27,11 +27,11 @@ def build_arch(self, arch): configure = sh.Command('./configure') shprint(configure, *flags, _env=env) shprint(sh.make, _env=env) - self.install_libs(arch, + self.install_libs( + arch, join('lib', '.libs', 'libvorbis.so'), join('lib', '.libs', 'libvorbisfile.so'), - join('lib', '.libs', 'libvorbisenc.so') - ) + join('lib', '.libs', 'libvorbisenc.so')) recipe = VorbisRecipe() diff --git a/pythonforandroid/recipes/opencv/__init__.py b/pythonforandroid/recipes/opencv/__init__.py index 6e183b3330..3533e0f097 100644 --- a/pythonforandroid/recipes/opencv/__init__.py +++ b/pythonforandroid/recipes/opencv/__init__.py @@ -34,16 +34,17 @@ def build_arch(self, arch): lib_dir = os.path.join(self.ctx.get_python_install_dir(), "lib") shprint(sh.cmake, - '-DP4A=ON', '-DANDROID_ABI={}'.format(arch.arch), - '-DCMAKE_TOOLCHAIN_FILE={}/platforms/android/android.toolchain.cmake'.format(cvsrc), - '-DPYTHON_INCLUDE_PATH={}/include/python2.7'.format(env['PYTHON_ROOT']), - '-DPYTHON_LIBRARY={}/lib/libpython2.7.so'.format(env['PYTHON_ROOT']), - '-DPYTHON_NUMPY_INCLUDE_DIR={}/numpy/core/include'.format(env['SITEPACKAGES_PATH']), - '-DANDROID_EXECUTABLE={}/tools/android'.format(env['ANDROID_SDK']), - '-DBUILD_TESTS=OFF', '-DBUILD_PERF_TESTS=OFF', '-DBUILD_EXAMPLES=OFF', '-DBUILD_ANDROID_EXAMPLES=OFF', - '-DPYTHON_PACKAGES_PATH={}'.format(env['SITEPACKAGES_PATH']), - cvsrc, - _env=env) + '-DP4A=ON', '-DANDROID_ABI={}'.format(arch.arch), + '-DCMAKE_TOOLCHAIN_FILE={}/platforms/android/android.toolchain.cmake'.format(cvsrc), + '-DPYTHON_INCLUDE_PATH={}/include/python2.7'.format(env['PYTHON_ROOT']), + '-DPYTHON_LIBRARY={}/lib/libpython2.7.so'.format(env['PYTHON_ROOT']), + '-DPYTHON_NUMPY_INCLUDE_DIR={}/numpy/core/include'.format(env['SITEPACKAGES_PATH']), + '-DANDROID_EXECUTABLE={}/tools/android'.format(env['ANDROID_SDK']), + '-DBUILD_TESTS=OFF', '-DBUILD_PERF_TESTS=OFF', + '-DBUILD_EXAMPLES=OFF', '-DBUILD_ANDROID_EXAMPLES=OFF', + '-DPYTHON_PACKAGES_PATH={}'.format(env['SITEPACKAGES_PATH']), + cvsrc, + _env=env) shprint(sh.make, '-j', str(cpu_count()), 'opencv_python') shprint(sh.cmake, '-DCOMPONENT=python', '-P', './cmake_install.cmake') sh.cp('-a', sh.glob('./lib/{}/lib*.so'.format(arch.arch)), lib_dir) diff --git a/pythonforandroid/recipes/protobuf_cpp/__init__.py b/pythonforandroid/recipes/protobuf_cpp/__init__.py index 9fa5fbef11..1c01901a9c 100644 --- a/pythonforandroid/recipes/protobuf_cpp/__init__.py +++ b/pythonforandroid/recipes/protobuf_cpp/__init__.py @@ -29,16 +29,17 @@ def build_arch(self, arch): shprint(sh.Command('./autogen.sh'), _env=env) shprint(sh.Command('./configure'), - '--host={}'.format(env['HOSTARCH']), - '--enable-shared', - _env=env) + '--host={}'.format(env['HOSTARCH']), + '--enable-shared', + _env=env) with current_directory(join(self.get_build_dir(arch.arch), 'src')): shprint(sh.make, 'libprotobuf.la', '-j'+str(cpu_count()), _env=env) shprint(sh.cp, '.libs/libprotobuf.a', join(self.ctx.get_libs_dir(arch.arch), 'libprotobuf.a')) - # Copy stl library - shutil.copyfile(self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/libgnustl_shared.so', + # Copy stl library + shutil.copyfile( + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/libgnustl_shared.so', join(self.ctx.get_libs_dir(arch.arch), 'libgnustl_shared.so')) # Build python bindings and _message.so @@ -87,16 +88,22 @@ def get_recipe_env(self, arch): env['PROTOC'] = '/home/fipo/soft/protobuf-3.1.0/src/protoc' env['PYTHON_ROOT'] = self.ctx.get_python_install_dir() env['TARGET_OS'] = 'OS_ANDROID_CROSSCOMPILE' - env['CFLAGS'] += ' -I' + self.ctx.ndk_dir + '/platforms/android-' + str( - self.ctx.android_api) + '/arch-' + arch.arch.replace('eabi', '') + '/usr/include' + \ - ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/include' + \ - ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + '/include' + \ - ' -I' + env['PYTHON_ROOT'] + '/include/python2.7' + env['CFLAGS'] += ( + ' -I' + self.ctx.ndk_dir + '/platforms/android-' + + str(self.ctx.android_api) + + '/arch-' + arch.arch.replace('eabi', '') + '/usr/include' + + ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + + self.ctx.toolchain_version + '/include' + + ' -I' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + + self.ctx.toolchain_version + '/libs/' + arch.arch + '/include' + + ' -I' + env['PYTHON_ROOT'] + '/include/python2.7') env['CXXFLAGS'] = env['CFLAGS'] env['CXXFLAGS'] += ' -frtti' env['CXXFLAGS'] += ' -fexceptions' - env['LDFLAGS'] += ' -L' + self.ctx.ndk_dir + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + '/libs/' + arch.arch + \ - ' -lgnustl_shared -lpython2.7' + env['LDFLAGS'] += ( + ' -L' + self.ctx.ndk_dir + + '/sources/cxx-stl/gnu-libstdc++/' + self.ctx.toolchain_version + + '/libs/' + arch.arch + ' -lgnustl_shared -lpython2.7') env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions' return env diff --git a/pythonforandroid/recipes/vlc/__init__.py b/pythonforandroid/recipes/vlc/__init__.py index 513275587c..2895ed1afb 100644 --- a/pythonforandroid/recipes/vlc/__init__.py +++ b/pythonforandroid/recipes/vlc/__init__.py @@ -33,15 +33,15 @@ def prebuild_arch(self, arch): else: aar_path = join(port_dir, 'libvlc', 'build', 'outputs', 'aar') self.aars[arch] = aar = join(aar_path, 'libvlc-{}.aar'.format(self.version)) - warning("HINT: set path to precompiled libvlc-.aar bundle " \ - "in {} environment!".format(self.ENV_LIBVLC_AAR)) - info("libvlc-.aar should build " \ - "from sources at {}".format(port_dir)) + warning("HINT: set path to precompiled libvlc-.aar bundle " + "in {} environment!".format(self.ENV_LIBVLC_AAR)) + info("libvlc-.aar should build " + "from sources at {}".format(port_dir)) if not isfile(join(port_dir, 'compile.sh')): info("clone vlc port for android sources from {}".format( self.port_git)) shprint(sh.git, 'clone', self.port_git, port_dir, - _tail=20, _critical=True) + _tail=20, _critical=True) # now "git clone ..." is a part of compile.sh # vlc_dir = join(port_dir, 'vlc') # if not isfile(join(vlc_dir, 'Makefile.am')): @@ -66,9 +66,9 @@ def build_arch(self, arch): debug("environment: {}".format(env)) if not isfile(join('bin', 'VLC-debug.apk')): shprint(sh.Command('./compile.sh'), _env=env, - _tail=50, _critical=True) + _tail=50, _critical=True) shprint(sh.Command('./compile-libvlc.sh'), _env=env, - _tail=50, _critical=True) + _tail=50, _critical=True) shprint(sh.cp, '-a', aar, self.ctx.aars_dir) diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index ff8ab85a99..a8b8de91a7 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -223,9 +223,9 @@ def __init__(self): # Buildozer used to pass these arguments in a now-invalid order # If that happens, apply this fix # This fix will be removed once a fixed buildozer is released - if (len(argv) > 2 and - argv[1].startswith('--color') and - argv[2].startswith('--storage-dir')): + if (len(argv) > 2 + and argv[1].startswith('--color') + and argv[2].startswith('--storage-dir')): argv.append(argv.pop(1)) # the --color arg argv.append(argv.pop(1)) # the --storage-dir arg @@ -347,7 +347,8 @@ def add_parser(subparsers, *args, **kwargs): kwargs.pop('aliases') return subparsers.add_parser(*args, **kwargs) - parser_recipes = add_parser(subparsers, + parser_recipes = add_parser( + subparsers, 'recipes', parents=[generic_parser], help='List the available recipes') @@ -380,27 +381,32 @@ def add_parser(subparsers, *args, **kwargs): help='Delete all builds', parents=[generic_parser]) - parser_clean = add_parser(subparsers, 'clean', - help='Delete build components.', - parents=[generic_parser]) + parser_clean = add_parser( + subparsers, 'clean', + help='Delete build components.', + parents=[generic_parser]) parser_clean.add_argument( 'component', nargs='+', help=('The build component(s) to delete. You can pass any ' 'number of arguments from "all", "builds", "dists", ' '"distributions", "bootstrap_builds", "downloads".')) - parser_clean_recipe_build = add_parser(subparsers, + parser_clean_recipe_build = add_parser( + subparsers, 'clean_recipe_build', aliases=['clean-recipe-build'], help=('Delete the build components of the given recipe. ' 'By default this will also delete built dists'), parents=[generic_parser]) - parser_clean_recipe_build.add_argument('recipe', help='The recipe name') - parser_clean_recipe_build.add_argument('--no-clean-dists', default=False, - dest='no_clean_dists', - action='store_true', - help='If passed, do not delete existing dists') + parser_clean_recipe_build.add_argument( + 'recipe', help='The recipe name') + parser_clean_recipe_build.add_argument( + '--no-clean-dists', default=False, + dest='no_clean_dists', + action='store_true', + help='If passed, do not delete existing dists') - parser_clean_download_cache= add_parser(subparsers, + parser_clean_download_cache= add_parser( + subparsers, 'clean_download_cache', aliases=['clean-download-cache'], help='Delete cached downloads for requirement builds', parents=[generic_parser]) @@ -409,7 +415,8 @@ def add_parser(subparsers, *args, **kwargs): help=('The recipes to clean (space-separated). If no recipe name is ' 'provided, the entire cache is cleared.')) - parser_export_dist = add_parser(subparsers, + parser_export_dist = add_parser( + subparsers, 'export_dist', aliases=['export-dist'], help='Copy the named dist to the given path', parents=[generic_parser]) @@ -417,50 +424,64 @@ def add_parser(subparsers, *args, **kwargs): parser_export_dist.add_argument('--symlink', action='store_true', help=('Symlink the dist instead of copying')) - parser_apk = add_parser(subparsers, + parser_apk = add_parser( + subparsers, 'apk', help='Build an APK', parents=[generic_parser]) - parser_apk.add_argument('--release', dest='build_mode', action='store_const', - const='release', default='debug', - help='Build the PARSER_APK. in Release mode') - parser_apk.add_argument('--keystore', dest='keystore', action='store', default=None, - help=('Keystore for JAR signing key, will use jarsigner ' - 'default if not specified (release build only)')) - parser_apk.add_argument('--signkey', dest='signkey', action='store', default=None, - help='Key alias to sign PARSER_APK. with (release build only)') - parser_apk.add_argument('--keystorepw', dest='keystorepw', action='store', default=None, - help='Password for keystore') - parser_apk.add_argument('--signkeypw', dest='signkeypw', action='store', default=None, - help='Password for key alias') - - parser_create = add_parser(subparsers, + parser_apk.add_argument( + '--release', dest='build_mode', action='store_const', + const='release', default='debug', + help='Build the PARSER_APK. in Release mode') + parser_apk.add_argument( + '--keystore', dest='keystore', action='store', default=None, + help=('Keystore for JAR signing key, will use jarsigner ' + 'default if not specified (release build only)')) + parser_apk.add_argument( + '--signkey', dest='signkey', action='store', default=None, + help='Key alias to sign PARSER_APK. with (release build only)') + parser_apk.add_argument( + '--keystorepw', dest='keystorepw', action='store', default=None, + help='Password for keystore') + parser_apk.add_argument( + '--signkeypw', dest='signkeypw', action='store', default=None, + help='Password for key alias') + + parser_create = add_parser( + subparsers, 'create', help='Compile a set of requirements into a dist', parents=[generic_parser]) - parser_archs = add_parser(subparsers, + parser_archs = add_parser( + subparsers, 'archs', help='List the available target architectures', parents=[generic_parser]) - parser_distributions = add_parser(subparsers, + parser_distributions = add_parser( + subparsers, 'distributions', aliases=['dists'], help='List the currently available (compiled) dists', parents=[generic_parser]) - parser_delete_dist = add_parser(subparsers, + parser_delete_dist = add_parser( + subparsers, 'delete_dist', aliases=['delete-dist'], help='Delete a compiled dist', parents=[generic_parser]) - parser_sdk_tools = add_parser(subparsers, + parser_sdk_tools = add_parser( + subparsers, 'sdk_tools', aliases=['sdk-tools'], help='Run the given binary from the SDK tools dis', parents=[generic_parser]) parser_sdk_tools.add_argument( 'tool', help=('The tool binary name to run')) - parser_adb = add_parser(subparsers, + parser_adb = add_parser( + subparsers, 'adb', help='Run adb from the given SDK', parents=[generic_parser]) - parser_logcat = add_parser(subparsers, + parser_logcat = add_parser( + subparsers, 'logcat', help='Run logcat from the given SDK', parents=[generic_parser]) - parser_build_status = add_parser(subparsers, + parser_build_status = add_parser( + subparsers, 'build_status', aliases=['build-status'], help='Print some debug information about current built components', parents=[generic_parser]) @@ -728,8 +749,8 @@ def apk(self, args): argx = arg.split('=') if argx[0] in fix_args: if len(argx) > 1: - unknown_args[i] = '='.join((argx[0], - realpath(expanduser(argx[1])))) + unknown_args[i] = '='.join( + (argx[0], realpath(expanduser(argx[1])))) else: unknown_args[i+1] = realpath(expanduser(unknown_args[i+1])) diff --git a/tox.ini b/tox.ini index c01021337c..541318d25c 100644 --- a/tox.ini +++ b/tox.ini @@ -15,7 +15,7 @@ commands = flake8 pythonforandroid/ tests/ [flake8] ignore = - E111, E114, E116, E202, E121, E123, E124, E225, E126, E127, E128, - E129, E226, E241, E265, E266, + E111, E116, E202, E121, E123, E124, E225, E126, + E226, E241, E265, E266, E401, E402, E501, E502, E722, E741, F403, F812, F841, F811, W292, W503