Skip to content

Commit f96356b

Browse files
authored
Merge pull request #2179 from AndreMiras/feature/narrow_context_manager
Narrows some context manager scopes
2 parents eaf4c2f + 581c4b4 commit f96356b

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

pythonforandroid/build.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import sh
1212
import shutil
1313
import subprocess
14+
from contextlib import suppress
1415

1516
from pythonforandroid.util import (
1617
current_directory, ensure_dir,
@@ -621,10 +622,8 @@ def run_setuppy_install(ctx, project_dir, env=None):
621622
),
622623
"freeze"
623624
], env=copy.copy(env))
624-
try:
625+
with suppress(AttributeError):
625626
constraints = constraints.decode("utf-8", "replace")
626-
except AttributeError:
627-
pass
628627
info(constraints)
629628

630629
# Make sure all packages found are fixed in version

pythonforandroid/recipe.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,9 @@ def install_python_package(self, arch, name=None, env=None, is_dir=True):
956956

957957
info('Installing {} into site-packages'.format(self.name))
958958

959+
hostpython = sh.Command(self.hostpython_location)
960+
hpenv = env.copy()
959961
with current_directory(self.get_build_dir(arch.arch)):
960-
hostpython = sh.Command(self.hostpython_location)
961-
hpenv = env.copy()
962962
shprint(hostpython, 'setup.py', 'install', '-O2',
963963
'--root={}'.format(self.ctx.get_python_install_dir()),
964964
'--install-lib=.',
@@ -999,8 +999,8 @@ def build_compiled_components(self, arch):
999999
info('Building compiled components in {}'.format(self.name))
10001000

10011001
env = self.get_recipe_env(arch)
1002+
hostpython = sh.Command(self.hostpython_location)
10021003
with current_directory(self.get_build_dir(arch.arch)):
1003-
hostpython = sh.Command(self.hostpython_location)
10041004
if self.install_in_hostpython:
10051005
shprint(hostpython, 'setup.py', 'clean', '--all', _env=env)
10061006
shprint(hostpython, 'setup.py', self.build_cmd, '-v',

pythonforandroid/recipes/hostpython3/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ def build_arch(self, arch):
8686
build_dir = join(recipe_build_dir, self.build_subdir)
8787
ensure_dir(build_dir)
8888

89-
with current_directory(recipe_build_dir):
90-
# Configure the build
91-
with current_directory(build_dir):
92-
if not exists('config.status'):
93-
shprint(sh.Command(join(recipe_build_dir, 'configure')))
89+
# Configure the build
90+
with current_directory(build_dir):
91+
if not exists('config.status'):
92+
shprint(sh.Command(join(recipe_build_dir, 'configure')))
9493

94+
with current_directory(recipe_build_dir):
9595
# Create the Setup file. This copying from Setup.dist is
9696
# the normal and expected procedure before Python 3.8, but
9797
# after this the file with default options is already named "Setup"

pythonforandroid/recipes/python3/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ def build_arch(self, arch):
283283
sys_prefix = '/usr/local'
284284
sys_exec_prefix = '/usr/local'
285285

286-
with current_directory(build_dir):
287-
env = self.get_recipe_env(arch)
288-
env = self.set_libs_flags(env, arch)
286+
env = self.get_recipe_env(arch)
287+
env = self.set_libs_flags(env, arch)
289288

290-
android_build = sh.Command(
291-
join(recipe_build_dir,
292-
'config.guess'))().stdout.strip().decode('utf-8')
289+
android_build = sh.Command(
290+
join(recipe_build_dir,
291+
'config.guess'))().stdout.strip().decode('utf-8')
293292

293+
with current_directory(build_dir):
294294
if not exists('config.status'):
295295
shprint(
296296
sh.Command(join(recipe_build_dir, 'configure')),

pythonforandroid/toolchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ def _build_package(self, args, package_type):
10511051
"Unknown build mode {} for apk()".format(args.build_mode))
10521052
output = shprint(gradlew, gradle_task, _tail=20,
10531053
_critical=True, _env=env)
1054-
return output, build_args
1054+
return output, build_args
10551055

10561056
def _finish_package(self, args, output, build_args, package_type, output_dir):
10571057
"""

0 commit comments

Comments
 (0)