Skip to content

Commit

Permalink
fix: handle subdirectory in git ssh url (#4719)
Browse files Browse the repository at this point in the history
* fix: handle subdirectory in git ssh url

Signed-off-by: Frost Ming <me@frostming.com>
  • Loading branch information
frostming committed May 9, 2024
1 parent 66321b8 commit 6e9b64d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/bentoml/_internal/bento/build_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ def _fix_dep_urls(self, requirements_txt: str, wheels_folder: str) -> None:
filename = link.filename
elif link.url.startswith("git+ssh://"):
# We are only able to handle SSH Git URLs
url, ref = link.url[4:], ""
if url.count("@") > 1:
url, ref = link.url_without_fragment[4:], ""
if url.count("@") > 1: # ssh://git@owner/repo@ref
url, _, ref = url.rpartition("@")
filename = download_and_zip_git_repo(
url, ref, link.subdirectory_fragment, wheels_folder
Expand Down
5 changes: 4 additions & 1 deletion src/bentoml/_internal/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,10 @@ def download_and_zip_git_repo(
raise BentoMLException(
f"Failed to clone git repository {url}: {e.stderr}"
) from e
zipball = os.path.join(dst_path, subdirectory or name)
zipball = os.path.join(
dst_path,
name + (f"-{subdirectory.replace('/', '-')}" if subdirectory else ""),
)
shutil.rmtree(os.path.join(dest_dir, ".git"), ignore_errors=True)
source_dir = os.path.join(dest_dir, subdirectory) if subdirectory else dest_dir
result = shutil.make_archive(zipball, "zip", source_dir)
Expand Down

0 comments on commit 6e9b64d

Please sign in to comment.