Skip to content

Use shutil.which instead of sh.which #2637

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

Merged
merged 1 commit into from
Jul 19, 2022
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
4 changes: 2 additions & 2 deletions pythonforandroid/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def prepare_build_environment(self,
self.ndk = AndroidNDK(self.ndk_dir)

# path to some tools
self.ccache = sh.which("ccache")
self.ccache = shutil.which("ccache")
if not self.ccache:
info('ccache is missing, the build will not be optimized in the '
'future.')
Expand Down Expand Up @@ -905,7 +905,7 @@ def copylibs_function(soname, objs_paths, extra_link_dirs=None, env=None):
elif 'READELF' in os.environ:
readelf = os.environ['READELF']
else:
readelf = sh.which('readelf').strip()
readelf = shutil.which('readelf').strip()
readelf = sh.Command(readelf).bake('-d')

dest = dirname(soname)
Expand Down
3 changes: 2 additions & 1 deletion pythonforandroid/recipes/lapack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from multiprocessing import cpu_count
from os.path import join
import sh
import shutil
from os import environ
from pythonforandroid.util import build_platform

Expand Down Expand Up @@ -43,7 +44,7 @@ def get_recipe_env(self, arch):
sysroot = f"{ndk_dir}/platforms/{env['NDK_API']}/arch-{sysroot_suffix}"
FC = f"{ndk_dir}/toolchains/{arch_to_toolchain(arch)}-{GCC_VER}/prebuilt/{HOST}/bin/{arch.command_prefix}-gfortran"
env['FC'] = f'{FC} --sysroot={sysroot}'
if sh.which(FC) is None:
if shutil.which(FC) is None:
raise BuildInterruptingException(f"{FC} not found. See https://github.com/mzakharo/android-gfortran")
return env

Expand Down
3 changes: 2 additions & 1 deletion pythonforandroid/recipes/numpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from os.path import join
import glob
import sh
import shutil


class NumpyRecipe(CompiledComponentsPythonRecipe):
Expand Down Expand Up @@ -67,7 +68,7 @@ def rebuild_compiled_components(self, arch, env):

def get_hostrecipe_env(self, arch):
env = super().get_hostrecipe_env(arch)
env['RANLIB'] = sh.which('ranlib')
env['RANLIB'] = shutil.which('ranlib')
return env


Expand Down
10 changes: 5 additions & 5 deletions pythonforandroid/recipes/python3/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from os import environ, utime
from os.path import dirname, exists, join
from pathlib import Path
from shutil import copy2
import shutil

from pythonforandroid.logger import info, warning, shprint
from pythonforandroid.patching import version_starts_with
Expand Down Expand Up @@ -73,7 +73,7 @@ class Python3Recipe(TargetPythonRecipe):
('patches/py3.8.1.patch', version_starts_with("3.9"))
]

if sh.which('lld') is not None:
if shutil.which('lld') is not None:
patches = patches + [
("patches/py3.7.1_fix_cortex_a8.patch", version_starts_with("3.7")),
("patches/py3.8.1_fix_cortex_a8.patch", version_starts_with("3.8")),
Expand Down Expand Up @@ -208,7 +208,7 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
)

env['LDFLAGS'] = env.get('LDFLAGS', '')
if sh.which('lld') is not None:
if shutil.which('lld') is not None:
# Note: The -L. is to fix a bug in python 3.7.
# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234409
env['LDFLAGS'] += ' -L. -fuse-ld=lld'
Expand Down Expand Up @@ -380,7 +380,7 @@ def create_python_bundle(self, dirn, arch):
info("Copy {} files into the bundle".format(len(module_filens)))
for filen in module_filens:
info(" - copy {}".format(filen))
copy2(filen, modules_dir)
shutil.copy2(filen, modules_dir)

# zip up the standard library
stdlib_zip = join(dirn, 'stdlib.zip')
Expand Down Expand Up @@ -408,7 +408,7 @@ def create_python_bundle(self, dirn, arch):
for filen in filens:
info(" - copy {}".format(filen))
ensure_dir(join(dirn, 'site-packages', dirname(filen)))
copy2(filen, join(dirn, 'site-packages', filen))
shutil.copy2(filen, join(dirn, 'site-packages', filen))

# copy the python .so files into place
python_build_dir = join(self.get_build_dir(arch.arch),
Expand Down