Repository navigation
Conversation
Signed-off-by: atharv0o <missionblood2@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR address?
Fixes #5575
Adds support for
uvworkspaces inbentoml build.The problem
When a project uses a
uvworkspace and declares a dependency viatool.uv.sources = { workspace = true },bentoml buildcurrently failsduring
uv pip compilewith:This happens because BentoML resolves dependencies from an isolated
temporary directory (
env/python) that has no visibility into the parentworkspace's
pyproject.tomlor member layout.The fix
This PR translates workspace-member dependencies into absolute local
filesystem paths before compilation, so
uvcan resolve and build themnatively from their real location — without needing to reconstruct
workspace discovery inside a temp build context.
Why this approach, and not running
uvfrom the workspace rootdirectly: that fails on Windows. Passing the root
pyproject.tomlcauses
uv/Rust to canonicalize the path to a long UNC path (\\?\...),while glob-expanded workspace members from that same file resolve as
standard Windows paths — the string comparison mismatches, producing
bird-feeder references a workspace in tool.uv.sources, but is not a workspace membereven on a valid config. Translating members to absolutepaths sidesteps this entirely, since
uvnever needs workspace discoveryfrom inside the temp directory.
We also considered generating a temporary
pyproject.tomlmappingworkspace sources, but rejected it — it introduces a second, drift-prone
source of truth for workspace metadata.
Scope
This PR intentionally covers only dependencies explicitly marked
workspace = trueintool.uv.sources. Arbitrary/non-workspace localpath dependencies (e.g. a manually declared
{ path = "../ext" }outsidea workspace) are explicitly out of scope — see "Future work" below. This
was a deliberate choice to keep the review surface small.
Changes
src/bentoml/_internal/bento/build_config.pyfind_workspace_root()— locates the workspace root by walking up fora
pyproject.tomlcontaining[tool.uv.workspace].get_workspace_members()— resolves member packages to absolute paths,honoring
tool.uv.workspace.exclude.rewrite_if_workspace_member()— rewrites a workspace memberrequirement to its absolute path using
packaging.requirements.Requirement, preserving extras and environmentmarkers.
PythonOptions.write_to_bento()— discovers the workspace root/membersfrom
build_ctxand applies the rewrite when generatingrequirements.txt.PythonOptions.fix_dep_urls()— detects local directory dependencies,validates each resolved path (via
os.path.realpath, closing asymlink-escape gap) stays within the workspace root — raising
BentoMLExceptionotherwise — then delegates tobuild_local_dep().src/bentoml/_internal/bento/bentoml_builder.pybuild_local_dep()— builds a workspace member viauv build --sdist --out-dir <temp_dir>inside atempfile.TemporaryDirectory, so nobuild artifacts are written into the user's source tree. Raises
BentoMLExceptionwith the captured command, exit code, and stderr onbuild failure.
Security
against the workspace root using resolved (
realpath) paths on bothsides, closing a gap where a symlink inside the workspace could point
outside it.
actual project directory.
Backward compatibility
No behavior change for projects not using
uvworkspaces. The new logiconly activates when a workspace root is discovered and a dependency
name matches a registered workspace member.
Testing
tool.uv.workspace.excludeis honoredBentoMLExceptionBentoMLException(skipped on Windows without Developer Mode)workspace member is built and packaged
Future work (not in this PR)
Before submitting:
pre-commit run -ascript has passed?