-
Notifications
You must be signed in to change notification settings - Fork 161
fix(python-uv): take into account dependencies on other workspace members #887
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
base: develop
Are you sure you want to change the base?
Changes from all commits
1a67ec4
fa31e78
c215596
beccbf5
b813ed8
85b30bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,9 +136,9 @@ def install_requirements( | |
| # Add requirements file | ||
| args.extend(["-r", requirements_path]) | ||
|
|
||
| # Resolve --target to an absolute path: UV runs with cwd set to the project directory, so a | ||
| # relative target (e.g. the incremental-build dependencies dir) would otherwise be created | ||
| # under the source directory instead of the build root. | ||
| # Resolve --target to an absolute path: UV runs from the project or workspace directory, | ||
| # so a relative target (e.g. the incremental-build dependencies dir) would otherwise be | ||
| # created under the UV's cwd instead of the build root. | ||
| args.extend(["--target", os.path.abspath(target_dir)]) | ||
|
|
||
| # Add configuration arguments | ||
|
|
@@ -332,6 +332,8 @@ def _build_from_lock_file( | |
| "--no-emit-project", # Don't include the project itself, only dependencies | ||
| "--no-hashes", # Skip hashes for cleaner output (optional) | ||
| "--no-default-groups", # Exclude PEP 735 default groups (e.g. dev/test) from Lambda zips | ||
| # Install package bodies instead of editable .pth links, which break in Lambda zips. | ||
| "--no-editable", | ||
| "--output-file", | ||
| temp_requirements, | ||
| # We want to specify the version because `uv export` might default to using a different one | ||
|
|
@@ -344,6 +346,19 @@ def _build_from_lock_file( | |
| if rc != 0: | ||
| raise LockFileError(reason=f"Failed to export lock file: {stderr}") | ||
|
|
||
| # Get the workspace root (or project directory if no workspace is used) | ||
| # For packages in the workspace, exported paths are relative to the workspace root, | ||
| # regardless of where in the workspace uv export is called | ||
| workspace_args = ["workspace", "dir"] | ||
| rc, stdout, stderr = self._uv_runner._uv.run_uv_command(workspace_args, cwd=project_dir) | ||
| if rc == 0: | ||
| workspace_dir = stdout.strip() | ||
| else: | ||
| # `uv workspace dir` requires uv >= 0.9.9. Fall back to the project directory, | ||
| # which is what that command returns for any non-workspace project anyway. | ||
| LOG.debug("Could not determine workspace root, assuming no workspace: %s", stderr) | ||
| workspace_dir = project_dir | ||
|
|
||
| # Install with platform targeting | ||
| self._uv_runner.install_requirements( | ||
| requirements_path=temp_requirements, | ||
|
|
@@ -352,7 +367,7 @@ def _build_from_lock_file( | |
| config=config, | ||
| python_version=python_version, | ||
| platform="linux", | ||
| cwd=project_dir, | ||
| cwd=workspace_dir, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [BUG] Splitting the two UV invocations across different working directories breaks the relative path they share.
Anchor the shared path so it is independent of which cwd UV runs in: temp_requirements = os.path.abspath(os.path.join(scratch_dir, "lock_requirements.txt"))Absolutizing Note: this was raised in the previous review round at |
||
| architecture=architecture, | ||
| ) | ||
| except LockFileError: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from workspace_lib import message | ||
|
|
||
|
|
||
| def handler(event, context): | ||
| return message() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [project] | ||
| name = "workspace-app" | ||
| version = "0.1.0" | ||
| requires-python = ">=3.9" | ||
| dependencies = ["workspace-lib"] | ||
|
|
||
| [tool.uv.sources] | ||
| workspace-lib = { workspace = true } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| [project] | ||
| name = "workspace-lib" | ||
| version = "0.1.0" | ||
| requires-python = ">=3.9" | ||
|
|
||
| [build-system] | ||
| requires = ["hatchling"] | ||
| build-backend = "hatchling.build" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| def message(): | ||
| return "Hello from the workspace dependency" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [tool.uv.workspace] | ||
| members = ["app", "lib"] |
Uh oh!
There was an error while loading. Please reload this page.