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

Add uv run --package #3864

Merged
merged 7 commits into from
Jun 2, 2024
Merged

Conversation

konstin
Copy link
Member

@konstin konstin commented May 27, 2024

Add a --package option that allows switching the current project in the workspace. Wherever you are in a workspace, you should be able to run with any other project as root. This is the uv equivalent of cargo run -p.

I don't love the --package name, esp. since -p is already taken and in general to many things start with p already.

Part of this change is moving the workspace discovery of ProjectWorkspace to Workspace itself.

Usage

In albatross-virtual-workspace:

$ uv venv
$ uv run --preview --package bird-feeder python -c "import albatross"
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/bird-feeder
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/seeds
Built 2 editables in 167ms
Resolved 5 packages in 4ms
Installed 5 packages in 1ms
 + anyio==4.4.0
 + bird-feeder==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/bird-feeder)
 + idna==3.6
 + seeds==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/seeds)
 + sniffio==1.3.1
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'albatross'
$ uv venv
$ uv run --preview --package albatross python -c "import albatross"
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/albatross
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/bird-feeder
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/seeds
Built 3 editables in 173ms
Resolved 7 packages in 6ms
Installed 7 packages in 1ms
 + albatross==0.1.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/albatross)
 + anyio==4.4.0
 + bird-feeder==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/bird-feeder)
 + idna==3.6
 + seeds==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/seeds)
 + sniffio==1.3.1
 + tqdm==4.66.4

In albatross-root-workspace:

$ uv venv
$ uv run --preview --package bird-feeder python -c "import albatross"
  Using Python 3.12.3 interpreter at: /home/konsti/.local/bin/python3
  Creating virtualenv at: .venv
  Activate with: source .venv/bin/activate
      Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
       Running `/home/konsti/projects/uv/target/debug/uv run --preview --package bird-feeder python -c 'import albatross'`
     Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/bird-feeder
     Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/seeds                                              Built 2 editables in 161ms
  Resolved 5 packages in 4ms
  Installed 5 packages in 1ms
   + anyio==4.4.0
   + bird-feeder==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/bird-feeder)
   + idna==3.6
   + seeds==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/seeds)
   + sniffio==1.3.1
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  ModuleNotFoundError: No module named 'albatross'
$ uv venv
$ cargo run run --preview --package albatross python -c "import albatross"
Using Python 3.12.3 interpreter at: /home/konsti/.local/bin/python3
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s
     Running `/home/konsti/projects/uv/target/debug/uv run --preview --package albatross python -c 'import albatross'`
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/bird-feeder
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/seeds
Built 3 editables in 168ms
Resolved 7 packages in 5ms
Installed 7 packages in 1ms
 + albatross==0.1.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace)
 + anyio==4.4.0
 + bird-feeder==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/bird-feeder)
 + idna==3.6
 + seeds==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/seeds)
 + sniffio==1.3.1
 + tqdm==4.66.4

@konstin konstin added the preview Experimental behavior label May 27, 2024
Copy link

codspeed-hq bot commented May 27, 2024

CodSpeed Performance Report

Merging #3864 will improve performances by 6.72%

Comparing konsti/workspaces-run-in-different-package (742440e) with main (0d0308c)

Summary

⚡ 1 improvements
✅ 12 untouched benchmarks

Benchmarks breakdown

Benchmark main konsti/workspaces-run-in-different-package Change
wheelname_tag_compatibility[flyte-short-incompatible] 926.7 ns 868.3 ns +6.72%

Base automatically changed from konsti/workspaces to main May 28, 2024 07:41
@konstin konstin force-pushed the konsti/workspaces-run-in-different-package branch from 0630666 to f5fd323 Compare May 28, 2024 08:57
@konstin konstin marked this pull request as ready for review May 28, 2024 09:11
crates/uv/tests/workspace.rs Outdated Show resolved Hide resolved
@konstin konstin force-pushed the konsti/workspaces-run-in-different-package branch from 69ab0fc to eac4c00 Compare May 31, 2024 13:29
Add a `--package` option that allows switching the current project in the workspace. Wherever you are in a workspace, you should be able to run with any other project as root. This is the uv equivalent of `cargo run -p`.

I don't love the `--package` name, esp. since `-p` is already taken and in general to many things start with p already.

## Usage

In albatross-virtual-workspace:

```console
$ uv venv
$ uv run --preview --package bird-feeder python -c "import albatross"
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/bird-feeder
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/seeds
Built 2 editables in 167ms
Resolved 5 packages in 4ms
Installed 5 packages in 1ms
 + anyio==4.4.0
 + bird-feeder==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/bird-feeder)
 + idna==3.6
 + seeds==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/seeds)
 + sniffio==1.3.1
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'albatross'
$ uv venv
$ uv run --preview --package albatross python -c "import albatross"
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/albatross
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/bird-feeder
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/seeds
Built 3 editables in 173ms
Resolved 7 packages in 6ms
Installed 7 packages in 1ms
 + albatross==0.1.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/albatross)
 + anyio==4.4.0
 + bird-feeder==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/bird-feeder)
 + idna==3.6
 + seeds==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-virtual-workspace/packages/seeds)
 + sniffio==1.3.1
 + tqdm==4.66.4
```

In albatross-root-workspace:

```console
$ uv venv
$ uv run --preview --package bird-feeder python -c "import albatross"
  Using Python 3.12.3 interpreter at: /home/konsti/.local/bin/python3
  Creating virtualenv at: .venv
  Activate with: source .venv/bin/activate
      Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.10s
       Running `/home/konsti/projects/uv/target/debug/uv run --preview --package bird-feeder python -c 'import albatross'`
     Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/bird-feeder
     Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/seeds                                              Built 2 editables in 161ms
  Resolved 5 packages in 4ms
  Installed 5 packages in 1ms
   + anyio==4.4.0
   + bird-feeder==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/bird-feeder)
   + idna==3.6
   + seeds==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/seeds)
   + sniffio==1.3.1
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
  ModuleNotFoundError: No module named 'albatross'
$ uv venv
$ cargo run run --preview --package albatross python -c "import albatross"
Using Python 3.12.3 interpreter at: /home/konsti/.local/bin/python3
Creating virtualenv at: .venv
Activate with: source .venv/bin/activate
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.13s
     Running `/home/konsti/projects/uv/target/debug/uv run --preview --package albatross python -c 'import albatross'`
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/bird-feeder
   Built file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/seeds
Built 3 editables in 168ms
Resolved 7 packages in 5ms
Installed 7 packages in 1ms
 + albatross==0.1.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace)
 + anyio==4.4.0
 + bird-feeder==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/bird-feeder)
 + idna==3.6
 + seeds==1.0.0 (from file:///home/konsti/projects/uv/scripts/workspaces/albatross-root-workspace/packages/seeds)
 + sniffio==1.3.1
 + tqdm==4.66.4
```
@konstin konstin force-pushed the konsti/workspaces-run-in-different-package branch from eac4c00 to 82e22c7 Compare May 31, 2024 13:32
@charliermarsh charliermarsh enabled auto-merge (squash) June 1, 2024 20:12
@charliermarsh
Copy link
Member

Not sure what's up with the Windows failure.

@charliermarsh charliermarsh force-pushed the konsti/workspaces-run-in-different-package branch from 69e18d9 to b9d2295 Compare June 1, 2024 20:32
@charliermarsh
Copy link
Member

It passes without error on my Windows machine.

@charliermarsh charliermarsh force-pushed the konsti/workspaces-run-in-different-package branch 4 times, most recently from cadb7f3 to 3c3037c Compare June 1, 2024 23:32
@charliermarsh
Copy link
Member

Some bad bug here because Windows is getting the following members (the names don't match the contents):

Found members: `{PackageName("albatross"): WorkspaceMember { root: "C:\/Users\/RUNNER~1\/AppData\/Local\/Temp\/[TMP]/seeds", pyproject_toml: PyProjectToml { project: Some(Project { name: PackageName("seeds"), optional_dependencies: None }), tool: None } }}`

@charliermarsh charliermarsh force-pushed the konsti/workspaces-run-in-different-package branch 2 times, most recently from 2d1469f to b12b95c Compare June 2, 2024 20:12
@charliermarsh charliermarsh force-pushed the konsti/workspaces-run-in-different-package branch from b12b95c to 44c6e80 Compare June 2, 2024 20:38
@charliermarsh
Copy link
Member

Sorry, I think I was being misled by the filters. I suspect the bug is in comparing the installed vs. requested path or something.

@charliermarsh
Copy link
Member

Like we're using absolute vs. canonical paths either when defining the requirement or installing, but not being consistent between them.

@charliermarsh
Copy link
Member

Okay yeah, the installed distribution has: /C:/Users/RUNNER~1/AppData/Local/Temp/.tmpJTJbWC/albatross-root-workspace/packages/bird-feeder

But the requirement is: C:\/Users\/runneradmin\/AppData\/Local\/Temp\\.tmpJTJbWC\/albatross-root-workspace\/packages\/bird-feeder

@charliermarsh charliermarsh force-pushed the konsti/workspaces-run-in-different-package branch 2 times, most recently from 825c97c to 5658838 Compare June 2, 2024 21:17
@charliermarsh charliermarsh force-pushed the konsti/workspaces-run-in-different-package branch from 5658838 to 94b195e Compare June 2, 2024 21:19
@charliermarsh
Copy link
Member

I hopefully fixed it by respecting symlinks in RequirementSatisfaction::check. I should look at what pip does with symlinks though, whether it records them under the canonical path, etc.

@charliermarsh charliermarsh force-pushed the konsti/workspaces-run-in-different-package branch from e00d444 to 742440e Compare June 2, 2024 21:33
@charliermarsh charliermarsh enabled auto-merge (squash) June 2, 2024 21:33
@charliermarsh charliermarsh merged commit 01d1a39 into main Jun 2, 2024
46 checks passed
@charliermarsh charliermarsh deleted the konsti/workspaces-run-in-different-package branch June 2, 2024 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants