How to use the sh.which function in sh

To help you get started, we’ve selected a few sh examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codelv / enaml-native / python-for-android / pythonforandroid / build.py View on Github external
ndk_ver, reported_ndk_ver))
                    warning('The build will try to continue, but it may '
                            'fail and you should check '
                            'that your setting is correct.')
                    warning('If the NDK dir result is correct, you don\'t '
                            'need to manually set the NDK ver.')
        if ndk_ver is None:
            warning('Android NDK version could not be found, exiting.')
            exit(1)
        self.ndk_ver = ndk_ver

        info('Using {} NDK {}'.format(self.ndk.capitalize(), self.ndk_ver))

        virtualenv = None
        if virtualenv is None:
            virtualenv = sh.which('virtualenv2')
        if virtualenv is None:
            virtualenv = sh.which('virtualenv-2.7')
        if virtualenv is None:
            virtualenv = sh.which('virtualenv')
        if virtualenv is None:
            raise IOError('Couldn\'t find a virtualenv executable, '
                          'you must install this to use p4a.')
        self.virtualenv = virtualenv
        info('Found virtualenv at {}'.format(virtualenv))

        # path to some tools
        self.ccache = sh.which("ccache")
        if not self.ccache:
            info('ccache is missing, the build will not be optimized in the '
                 'future.')
        for cython_fn in ("cython2", "cython-2.7", "cython"):
github codelv / enaml-native-cli / python-for-android / pythonforandroid / build.py View on Github external
ndk_ver, reported_ndk_ver))
                    warning('The build will try to continue, but it may '
                            'fail and you should check '
                            'that your setting is correct.')
                    warning('If the NDK dir result is correct, you don\'t '
                            'need to manually set the NDK ver.')
        if ndk_ver is None:
            warning('Android NDK version could not be found, exiting.')
            exit(1)
        self.ndk_ver = ndk_ver

        info('Using {} NDK {}'.format(self.ndk.capitalize(), self.ndk_ver))

        virtualenv = None
        if virtualenv is None:
            virtualenv = sh.which('virtualenv2')
        if virtualenv is None:
            virtualenv = sh.which('virtualenv-2.7')
        if virtualenv is None:
            virtualenv = sh.which('virtualenv')
        if virtualenv is None:
            raise IOError('Couldn\'t find a virtualenv executable, '
                          'you must install this to use p4a.')
        self.virtualenv = virtualenv
        info('Found virtualenv at {}'.format(virtualenv))

        # path to some tools
        self.ccache = sh.which("ccache")
        if not self.ccache:
            info('ccache is missing, the build will not be optimized in the '
                 'future.')
        for cython_fn in ("cython2", "cython-2.7", "cython"):
github codelv / enaml-native / python-for-ios / toolchain.py View on Github external
if key not in ctx.state:
                    continue
                recipe = Recipe.get_recipe(recipe, ctx)
                recipe.init_with_ctx(ctx)
            if not hasattr(ctx, "site_packages_dir"):
                info("ERROR: python must be compiled before using pip")
                sys.exit(1)

            pip_env = {
                "CC": "/bin/false",
                "CXX": "/bin/false",
                "PYTHONPATH": ctx.site_packages_dir,
                "PYTHONOPTIMIZE": "2",
                # "PIP_INSTALL_TARGET": ctx.site_packages_dir
            }
            pip_path = sh.which("pip2")
            pip_args = []
            if len(sys.argv) > 2 and sys.argv[2] == "install":
                pip_args = ["--isolated", "--prefix", ctx.python_prefix]
                args = [pip_path] + [sys.argv[2]] + pip_args + sys.argv[3:]
            else:
                args = [pip_path] + pip_args + sys.argv[2:]

            if not pip_path:
                info("ERROR: pip not found")
                sys.exit(1)
            import os
            info("-- execute pip with: {}".format(args))
            os.execve(pip_path, args, pip_env)
github codelv / enaml-native-cli / python-for-android / pythonforandroid / build.py View on Github external
self.toolchain_version = toolchain_version
        # Modify the path so that sh finds modules appropriately
        environ['PATH'] = (
            '{ndk_dir}/toolchains/{toolchain_prefix}-{toolchain_version}/'
            'prebuilt/{py_platform}-x86/bin/:{ndk_dir}/toolchains/'
            '{toolchain_prefix}-{toolchain_version}/prebuilt/'
            '{py_platform}-x86_64/bin/:{ndk_dir}:{sdk_dir}/'
            'tools:{path}').format(
                sdk_dir=self.sdk_dir, ndk_dir=self.ndk_dir,
                toolchain_prefix=toolchain_prefix,
                toolchain_version=toolchain_version,
                py_platform=py_platform, path=environ.get('PATH'))

        for executable in ("pkg-config", "autoconf", "automake", "libtoolize",
                           "tar", "bzip2", "unzip", "make", "gcc", "g++"):
            if not sh.which(executable):
                warning("Missing executable: {} is not installed".format(
                    executable))

        if not ok:
            error('{}python-for-android cannot continue; aborting{}'.format(
                Err_Fore.RED, Err_Fore.RESET))
            sys.exit(1)
github kootenpv / access_points / deploy.py View on Github external
minor = re.search("MINOR_VERSION = '([0-9]+)'", setup).groups()[0]
micro = re.search("MICRO_VERSION = '([0-9]+)'", setup).groups()[0]
version = '{}.{}.{}'.format(major, minor, micro)

with open('setup.py', 'w') as f:
    f.write(setup)

with open('access_points/__init__.py') as f:
    init = f.read()

with open('access_points/__init__.py', 'w') as f:
    f.write(
        re.sub('__version__ = "[0-9.]+"',
               '__version__ = "{}"'.format(version), init))

py_version = "python3.7" if sh.which("python3.7") is not None else "python"
os.system('{} setup.py sdist bdist_wheel upload'.format(py_version))
github lbryio / lbry-android / p4a / pythonforandroid / build.py View on Github external
'the default of {} = min(android-api={}, default ndk-api={})'.format(
                        ndk_api, self.android_api, RECOMMENDED_NDK_API))
        ndk_api = int(ndk_api)
        self.ndk_api = ndk_api

        check_ndk_api(ndk_api, self.android_api)

        virtualenv = get_virtualenv_executable()
        if virtualenv is None:
            raise IOError('Couldn\'t find a virtualenv executable, '
                          'you must install this to use p4a.')
        self.virtualenv = virtualenv
        info('Found virtualenv at {}'.format(virtualenv))

        # path to some tools
        self.ccache = sh.which("ccache")
        if not self.ccache:
            info('ccache is missing, the build will not be optimized in the '
                 'future.')
        for cython_fn in ("cython", "cython3", "cython2", "cython-2.7"):
            cython = sh.which(cython_fn)
            if cython:
                self.cython = cython
                break
        else:
            raise BuildInterruptingException('No cython binary found.')
        if not self.cython:
            ok = False
            warning("Missing requirement: cython is not installed")

        # This would need to be changed if supporting multiarch APKs
        arch = self.archs[0]
github kivy / kivy-ios / toolchain.py View on Github external
self.iossdkroot = "{}/SDKs/iPhoneOS{}.sdk".format(
            self.devroot, self.sdkver)

        # root of the toolchain
        self.root_dir = realpath(dirname(__file__))
        self.build_dir = "{}/build".format(self.root_dir)
        self.cache_dir = "{}/.cache".format(self.root_dir)
        self.dist_dir = "{}/dist".format(self.root_dir)
        self.install_dir = "{}/dist/root".format(self.root_dir)
        self.include_dir = "{}/dist/include".format(self.root_dir)
        self.archs = (
            Arch64Simulator(self),
            Arch64IOS(self))

        # path to some tools
        self.ccache = sh.which("ccache")
        if not self.ccache:
            #print("ccache is missing, the build will not be optimized in the future.")
            pass
        for cython_fn in ("cython-2.7", "cython"):
            cython = sh.which(cython_fn)
            if cython:
                self.cython = cython
                break
        if not self.cython:
            ok = False
            logger.error("Missing requirement: cython is not installed")

        # check the basic tools
        for tool in ("pkg-config", "autoconf", "automake", "libtool"):
            if not sh.which(tool):
                logger.error("Missing requirement: {} is not installed".format(
github kivy / python-for-android / pythonforandroid / build.py View on Github external
'the default of {} = min(android-api={}, default ndk-api={})'.format(
                        ndk_api, self.android_api, RECOMMENDED_NDK_API))
        ndk_api = int(ndk_api)
        self.ndk_api = ndk_api

        check_ndk_api(ndk_api, self.android_api)

        virtualenv = get_virtualenv_executable()
        if virtualenv is None:
            raise IOError('Couldn\'t find a virtualenv executable, '
                          'you must install this to use p4a.')
        self.virtualenv = virtualenv
        info('Found virtualenv at {}'.format(virtualenv))

        # path to some tools
        self.ccache = sh.which("ccache")
        if not self.ccache:
            info('ccache is missing, the build will not be optimized in the '
                 'future.')
        try:
            subprocess.check_output([
                "python3", "-m", "cython", "--help",
            ])
        except subprocess.CalledProcessError:
            warning('Cython for python3 missing. If you are building for '
                    ' a python 3 target (which is the default)'
                    ' then THINGS WILL BREAK.')

        # This would need to be changed if supporting multiarch APKs
        arch = self.archs[0]
        toolchain_prefix = arch.toolchain_prefix
        self.ndk_platform, ndk_platform_dir_exists = get_ndk_platform_dir(
github AndreMiras / EtherollApp / src / python-for-android / recipes / hostpython3crystax / __init__.py View on Github external
def build_arch(self, arch):
        """
        Creates expected build and symlinks system Python version.
        """
        self.ctx.hostpython = '/usr/bin/false'
        self.ctx.hostpgen = '/usr/bin/false'
        # creates the sub buildir (used by other recipes)
        # https://github.com/kivy/python-for-android/issues/1154
        sub_build_dir = join(self.get_build_dir(), 'build')
        shprint(sh.mkdir, '-p', sub_build_dir)
        system_python = sh.which("python" + self.version)
        link_dest = join(self.get_build_dir(), 'hostpython')
        shprint(sh.ln, '-sf', system_python, link_dest)
github Mati365 / pyWinUSB / pywinusb / creator.py View on Github external
# self.uuid = re.search("UUID=\"(\w*)\"", str(sh.blkid(self.device + "1"))).group(1)
        # print("Device UUID:", self.uuid)

        # W niektórych wersjach windows katalog ten jest z drukowanej
        def try_move(old_file, new_file):
            try: sh.mv(old_file, new_file)
            except:
                print("File {} already exists, nothing to move".format(new_file))

        self.boot_folder = self.destination_mount + "/boot"
        try_move(self.destination_mount + "/BOOT", self.boot_folder)
        try_move(self.destination_mount + "/BOOTMGR", self.destination_mount + "/bootmgr")

        # Instalownie bootloadera
        # grub-install --target=i386-pc --boot-directory="//boot" /dev/sdX
        installer = sh.Command(sh.which("grub-install")
                               or sh.which("grub2-install"))
        installer(self.device, target="i386-pc", skip_fs_probe=True, force=True, boot_directory=self.destination_mount + "/boot")

        # Tworzenie konfiguracji GRUBa
        with open( "{}/{}/grub.cfg".format( self.boot_folder, "grub2" if str(installer).find("grub2") != -1 else "grub")
                 , "wt"
                 ) as config:
            config.write("""
                set menu_color_normal=white/black