Exemplo n.º 1
0
    def save(self, path, bento_service):
        conda_yml_file = os.path.join(path, "environment.yml")
        self._conda_env.write_to_yaml_file(conda_yml_file)

        requirements_txt_file = os.path.join(path, "requirements.txt")

        with open(requirements_txt_file, "wb") as f:
            dependencies_map = {}
            for dep in self._pip_dependencies:
                name, version = parse_requirement_string(dep)
                dependencies_map[name] = version

            if self._auto_pip_dependencies:
                bento_service_module = sys.modules[bento_service.__class__.__module__]
                if hasattr(bento_service_module, "__file__"):
                    bento_service_py_file_path = bento_service_module.__file__
                    reqs, unknown_modules = seek_pip_dependencies(
                        bento_service_py_file_path
                    )
                    dependencies_map.update(reqs)
                    for module_name in unknown_modules:
                        logger.warning(
                            "unknown package dependency for module: %s", module_name
                        )

                # Reset bentoml to configured deploy version - this is for users using
                # customized BentoML branch for development but use a different stable
                # version for deployment
                #
                # For example, a BentoService created with local dirty branch will fail
                # to deploy with docker due to the version can't be found on PyPI, but
                # get_bentoml_deploy_version gives the user the latest released PyPI
                # version that's closest to the `dirty` branch
                dependencies_map['bentoml'] = get_bentoml_deploy_version()

            # Set self._pip_dependencies so it get writes to BentoService config file
            self._pip_dependencies = []
            for pkg_name, pkg_version in dependencies_map.items():
                self._pip_dependencies.append(
                    "{}{}".format(
                        pkg_name, "=={}".format(pkg_version) if pkg_version else ""
                    )
                )

            pip_content = "\n".join(self._pip_dependencies).encode("utf-8")
            f.write(pip_content)

        if self._setup_sh:
            setup_sh_file = os.path.join(path, "setup.sh")
            with open(setup_sh_file, "wb") as f:
                f.write(self._setup_sh)

            # chmod +x setup.sh
            st = os.stat(setup_sh_file)
            os.chmod(setup_sh_file, st.st_mode | stat.S_IEXEC)
Exemplo n.º 2
0
 def check_dependency(dependency):
     name, version = parse_requirement_string(dependency)
     code = verify_pkg(name, version)
     if code == EPP_PKG_NOT_EXIST:
         logger.warning(
             '%s package does not exist in the current python '
             'session', name)
     elif code == EPP_PKG_VERSION_MISMATCH:
         logger.warning(
             '%s package version is different from the version '
             'being used in the current python session',
             name,
         )