Skip to content

Commit

Permalink
feat: add a switch to opt-out packing git packages (#4729)
Browse files Browse the repository at this point in the history
* feat: add a switch to opt-out packing git packages

Signed-off-by: Frost Ming <me@frostming.com>

* fix: tests

Signed-off-by: Frost Ming <me@frostming.com>

---------

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed May 16, 2024
1 parent 2cf64ea commit 950f709
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/bentoml/_internal/bento/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,11 @@ class PythonOptions:
default=None,
validator=attr.validators.optional(attr.validators.instance_of(ListStr)),
)
lock_packages: t.Optional[bool] = attr.field(
lock_packages: bool = attr.field(
default=True,
validator=attr.validators.optional(attr.validators.instance_of(bool)),
)
pack_git_packages: bool = attr.field(
default=True,
validator=attr.validators.optional(attr.validators.instance_of(bool)),
)
Expand Down Expand Up @@ -658,6 +662,11 @@ def write_to_bento(self, bento_fs: FS, build_ctx: str) -> None:

def with_defaults(self) -> PythonOptions:
# Convert from user provided options to actual build options with default values
if not self.pack_git_packages and self.lock_packages is not False:
logger.warning(
"Setting 'lock_packages' to False since 'pack_git_packages' is False"
)
return attr.evolve(self, lock_packages=False)
return self

def _fix_dep_urls(self, requirements_txt: str, wheels_folder: str) -> None:
Expand All @@ -677,10 +686,10 @@ def _fix_dep_urls(self, requirements_txt: str, wheels_folder: str) -> None:

if "/env/python/wheels" in link.url:
filename = link.filename
elif link.url.startswith("git+ssh://"):
elif self.pack_git_packages and link.url.startswith("git+"):
# We are only able to handle SSH Git URLs
url, ref = link.url_without_fragment[4:], ""
if url.count("@") > 1: # ssh://git@owner/repo@ref
if "@" in link.path: # ssh://git@owner/repo@ref
url, _, ref = url.rpartition("@")
filename = download_and_zip_git_repo(
url, ref, link.subdirectory_fragment, wheels_folder
Expand Down
1 change: 1 addition & 0 deletions tests/unit/_internal/bento/test_bento.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def test_bento_info(tmpdir: Path):
requirements_txt: null
packages: null
lock_packages: true
pack_git_packages: true
index_url: null
no_index: null
trusted_host: null
Expand Down

0 comments on commit 950f709

Please sign in to comment.