Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Narrows some context manager scopes #2179

Merged
merged 1 commit into from
May 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Comment on lines -624 to -627
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 two less lines of code without sacrificing readability 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I love that one :)
But it cannot really be used nicely if we have a large comment block above the pass, so yes I decided to introduced it only when we had a simple except ...: 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