-
Notifications
You must be signed in to change notification settings - Fork 753
/
build_dev_bentoml_whl.py
62 lines (48 loc) · 2.47 KB
/
build_dev_bentoml_whl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations
import os
import logging
from bentoml.exceptions import BentoMLException
from ..utils.pkg import source_locations
from ..configuration import is_pypi_installed_bentoml
logger = logging.getLogger(__name__)
BENTOML_DEV_BUILD = "BENTOML_BUNDLE_LOCAL_BUILD"
def build_bentoml_editable_wheel(target_path: str) -> None:
"""
This is for BentoML developers to create Bentos that contains the local bentoml
build based on their development branch. To enable this behavior, one must
set envar :code:`BENTOML_BUNDLE_LOCAL_BUILD=True` before building a Bento.
"""
if str(os.environ.get(BENTOML_DEV_BUILD, False)).lower() != "true":
return
if is_pypi_installed_bentoml():
# skip this entirely if BentoML is installed from PyPI
return
# Find bentoml module path
module_location = source_locations("bentoml")
if not module_location:
raise BentoMLException("Could not find bentoml module location.")
pyproject = os.path.abspath(os.path.join(module_location, "..", "pyproject.toml"))
# this is for BentoML developer to create Service containing custom development
# branches of BentoML library, it is True only when BentoML module is installed
# in development mode via "pip install --editable ."
if os.path.isfile(pyproject):
logger.info(
"BentoML is installed in `editable` mode; building BentoML distribution with the local BentoML code base. The built wheel file will be included in the target bento."
)
try:
from build.env import IsolatedEnvBuilder
from build import ProjectBuilder
except ModuleNotFoundError:
raise BentoMLException(
f"'{BENTOML_DEV_BUILD}=True', which requires the 'pypa/build' package. Install development dependencies with 'pip install -r requirements/dev-requirements.txt' and try again."
)
with IsolatedEnvBuilder() as env:
builder = ProjectBuilder(os.path.dirname(pyproject))
builder.python_executable = env.executable
builder.scripts_dir = env.scripts_dir
env.install(builder.build_system_requires)
builder.build("wheel", target_path)
else:
logger.info(
"Custom BentoML build is detected. For a Bento to use the same build at serving time, add your custom BentoML build to the pip packages list, e.g. `packages=['git+https://github.com/bentoml/bentoml.git@13dfb36']`"
)