Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a switch to opt-out packing git packages #4729

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
bojiang marked this conversation as resolved.
Show resolved Hide resolved
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
Loading