diff --git a/pythonforandroid/build.py b/pythonforandroid/build.py index 34de065854..fba23ce0ae 100644 --- a/pythonforandroid/build.py +++ b/pythonforandroid/build.py @@ -11,6 +11,7 @@ import sh import shutil import subprocess +from contextlib import suppress from pythonforandroid.util import ( current_directory, ensure_dir, @@ -621,10 +622,8 @@ def run_setuppy_install(ctx, project_dir, env=None): ), "freeze" ], env=copy.copy(env)) - try: + with suppress(AttributeError): constraints = constraints.decode("utf-8", "replace") - except AttributeError: - pass info(constraints) # Make sure all packages found are fixed in version diff --git a/pythonforandroid/recipe.py b/pythonforandroid/recipe.py index 378c1e2777..6128074e51 100644 --- a/pythonforandroid/recipe.py +++ b/pythonforandroid/recipe.py @@ -956,9 +956,9 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True): info('Installing {} into site-packages'.format(self.name)) + hostpython = sh.Command(self.hostpython_location) + hpenv = env.copy() with current_directory(self.get_build_dir(arch.arch)): - hostpython = sh.Command(self.hostpython_location) - hpenv = env.copy() shprint(hostpython, 'setup.py', 'install', '-O2', '--root={}'.format(self.ctx.get_python_install_dir()), '--install-lib=.', @@ -999,8 +999,8 @@ def build_compiled_components(self, arch): info('Building compiled components in {}'.format(self.name)) env = self.get_recipe_env(arch) + hostpython = sh.Command(self.hostpython_location) with current_directory(self.get_build_dir(arch.arch)): - hostpython = sh.Command(self.hostpython_location) if self.install_in_hostpython: shprint(hostpython, 'setup.py', 'clean', '--all', _env=env) shprint(hostpython, 'setup.py', self.build_cmd, '-v', diff --git a/pythonforandroid/recipes/hostpython3/__init__.py b/pythonforandroid/recipes/hostpython3/__init__.py index f1838283da..8a26dfc698 100644 --- a/pythonforandroid/recipes/hostpython3/__init__.py +++ b/pythonforandroid/recipes/hostpython3/__init__.py @@ -86,12 +86,12 @@ def build_arch(self, arch): build_dir = join(recipe_build_dir, self.build_subdir) ensure_dir(build_dir) - with current_directory(recipe_build_dir): - # Configure the build - with current_directory(build_dir): - if not exists('config.status'): - shprint(sh.Command(join(recipe_build_dir, 'configure'))) + # Configure the build + with current_directory(build_dir): + if not exists('config.status'): + shprint(sh.Command(join(recipe_build_dir, 'configure'))) + with current_directory(recipe_build_dir): # Create the Setup file. This copying from Setup.dist is # the normal and expected procedure before Python 3.8, but # after this the file with default options is already named "Setup" diff --git a/pythonforandroid/recipes/python3/__init__.py b/pythonforandroid/recipes/python3/__init__.py index 569afc2d26..97d56cb812 100644 --- a/pythonforandroid/recipes/python3/__init__.py +++ b/pythonforandroid/recipes/python3/__init__.py @@ -283,14 +283,14 @@ def build_arch(self, arch): sys_prefix = '/usr/local' sys_exec_prefix = '/usr/local' - with current_directory(build_dir): - env = self.get_recipe_env(arch) - env = self.set_libs_flags(env, arch) + env = self.get_recipe_env(arch) + env = self.set_libs_flags(env, arch) - android_build = sh.Command( - join(recipe_build_dir, - 'config.guess'))().stdout.strip().decode('utf-8') + android_build = sh.Command( + join(recipe_build_dir, + 'config.guess'))().stdout.strip().decode('utf-8') + with current_directory(build_dir): if not exists('config.status'): shprint( sh.Command(join(recipe_build_dir, 'configure')), diff --git a/pythonforandroid/toolchain.py b/pythonforandroid/toolchain.py index 7fe1ffa2b8..0da2a2a8f9 100644 --- a/pythonforandroid/toolchain.py +++ b/pythonforandroid/toolchain.py @@ -1051,7 +1051,7 @@ def _build_package(self, args, package_type): "Unknown build mode {} for apk()".format(args.build_mode)) output = shprint(gradlew, gradle_task, _tail=20, _critical=True, _env=env) - return output, build_args + return output, build_args def _finish_package(self, args, output, build_args, package_type, output_dir): """