Skip to content

Commit

Permalink
Merge pull request #2179 from AndreMiras/feature/narrow_context_manager
Browse files Browse the repository at this point in the history
Narrows some context manager scopes
  • Loading branch information
AndreMiras authored May 9, 2020
2 parents eaf4c2f + 581c4b4 commit f96356b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
5 changes: 2 additions & 3 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sh
import shutil
import subprocess
from contextlib import suppress

from pythonforandroid.util import (
current_directory, ensure_dir,
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pythonforandroid/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=.',
Expand Down Expand Up @@ -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',
Expand Down
10 changes: 5 additions & 5 deletions pythonforandroid/recipes/hostpython3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 6 additions & 6 deletions pythonforandroid/recipes/python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
2 changes: 1 addition & 1 deletion pythonforandroid/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit f96356b

Please sign in to comment.