コード例 #1
0
ファイル: __init__.py プロジェクト: zeuxion23/BentoML
    def run(api_name, run_args, bento=None, with_conda=False):
        track_cli('run')
        bento_service_bundle_path = resolve_bundle_path(
            bento, pip_installed_bundle_path)

        if with_conda:
            run_with_conda_env(
                bento_service_bundle_path,
                'bentoml run {api_name} {bento} {args}'.format(
                    bento=bento_service_bundle_path,
                    api_name=api_name,
                    args=' '.join(map(escape_shell_params, run_args)),
                ),
            )
            return

        api = load_bento_service_api(bento_service_bundle_path, api_name)
        api.handle_cli(run_args)
コード例 #2
0
ファイル: __init__.py プロジェクト: seantur/BentoML
    def run(ctx, api_name, bundle_path=bundle_path, with_conda=False):
        if with_conda:
            config = load_saved_bundle_config(bundle_path)
            metadata = config['metadata']
            env_name = metadata['service_name'] + '_' + metadata[
                'service_version']

            yaml = YAML()
            yaml.default_flow_style = False
            tmpf = tempfile.NamedTemporaryFile(delete=False)
            env_path = tmpf.name
            yaml.dump(config['env']['conda_env'], Path(env_path))

            pip_req = os.path.join(bundle_path, 'requirements.txt')

            subprocess.call(
                'command -v conda >/dev/null 2>&1 || {{ echo >&2 "--with-conda '
                'parameter requires conda but it\'s not installed."; exit 1; }} && '
                'conda env update -n {env_name} -f {env_file} && '
                'conda init bash && '
                'eval "$(conda shell.bash hook)" && '
                'conda activate {env_name} && '
                '{{ [ -f {pip_req} ] && pip install -r {pip_req} || echo "no pip '
                'dependencies."; }} &&'
                'bentoml {api_name} {bundle_path} {args}'.format(
                    env_name=env_name,
                    env_file=env_path,
                    bundle_path=bundle_path,
                    api_name=api_name,
                    args=' '.join(map(escape_shell_params, ctx.args)),
                    pip_req=pip_req,
                ),
                shell=True,
            )
            return

        track_cli('run')

        api = load_bento_service_api(bundle_path, api_name)
        api.handle_cli(ctx.args)