Skip to content

Commit 0b64ee3

Browse files
committed
Respect --with versions over base environment versions
1 parent 1ddfcee commit 0b64ee3

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

crates/uv/src/commands/project/run.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1068,8 +1068,8 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
10681068

10691069
ephemeral_env.set_overlay(format!(
10701070
"import site; site.addsitedir(\"{}\"); site.addsitedir(\"{}\");",
1071-
base_site_packages.escape_for_python(),
10721071
requirements_site_packages.escape_for_python(),
1072+
base_site_packages.escape_for_python(),
10731073
))?;
10741074

10751075
// N.B. The order here matters — earlier interpreters take precedence over the

crates/uv/tests/it/run.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,14 +1167,17 @@ fn run_with() -> Result<()> {
11671167
let test_script = context.temp_dir.child("main.py");
11681168
test_script.write_str(indoc! { r"
11691169
import sniffio
1170+
1171+
print(sniffio.__version__)
11701172
"
11711173
})?;
11721174

11731175
// Requesting an unsatisfied requirement should install it.
1174-
uv_snapshot!(context.filters(), context.run().arg("--with").arg("iniconfig").arg("main.py"), @r###"
1176+
uv_snapshot!(context.filters(), context.run().arg("--with").arg("iniconfig").arg("main.py"), @r"
11751177
success: true
11761178
exit_code: 0
11771179
----- stdout -----
1180+
1.3.0
11781181
11791182
----- stderr -----
11801183
Resolved 2 packages in [TIME]
@@ -1186,24 +1189,27 @@ fn run_with() -> Result<()> {
11861189
Prepared 1 package in [TIME]
11871190
Installed 1 package in [TIME]
11881191
+ iniconfig==2.0.0
1189-
"###);
1192+
");
11901193

11911194
// Requesting a satisfied requirement should use the base environment.
1192-
uv_snapshot!(context.filters(), context.run().arg("--with").arg("sniffio").arg("main.py"), @r###"
1195+
uv_snapshot!(context.filters(), context.run().arg("--with").arg("sniffio").arg("main.py"), @r"
11931196
success: true
11941197
exit_code: 0
11951198
----- stdout -----
1199+
1.3.0
11961200
11971201
----- stderr -----
11981202
Resolved 2 packages in [TIME]
11991203
Audited 2 packages in [TIME]
1200-
"###);
1204+
");
12011205

12021206
// Unless the user requests a different version.
1203-
uv_snapshot!(context.filters(), context.run().arg("--with").arg("sniffio<1.3.0").arg("main.py"), @r###"
1207+
// TODO(charlie): This should use `1.2.0`, not `1.3.0`.
1208+
uv_snapshot!(context.filters(), context.run().arg("--with").arg("sniffio<1.3.0").arg("main.py"), @r"
12041209
success: true
12051210
exit_code: 0
12061211
----- stdout -----
1212+
1.2.0
12071213
12081214
----- stderr -----
12091215
Resolved 2 packages in [TIME]
@@ -1212,15 +1218,16 @@ fn run_with() -> Result<()> {
12121218
Prepared 1 package in [TIME]
12131219
Installed 1 package in [TIME]
12141220
+ sniffio==1.2.0
1215-
"###);
1221+
");
12161222

12171223
// If we request a dependency that isn't in the base environment, we should still respect any
12181224
// other dependencies. In this case, `sniffio==1.3.0` is not the latest-compatible version, but
12191225
// we should use it anyway.
1220-
uv_snapshot!(context.filters(), context.run().arg("--with").arg("anyio").arg("main.py"), @r###"
1226+
uv_snapshot!(context.filters(), context.run().arg("--with").arg("anyio").arg("main.py"), @r"
12211227
success: true
12221228
exit_code: 0
12231229
----- stdout -----
1230+
1.3.0
12241231
12251232
----- stderr -----
12261233
Resolved 2 packages in [TIME]
@@ -1231,13 +1238,14 @@ fn run_with() -> Result<()> {
12311238
+ anyio==4.3.0
12321239
+ idna==3.6
12331240
+ sniffio==1.3.0
1234-
"###);
1241+
");
12351242

12361243
// Even if we run with` --no-sync`.
1237-
uv_snapshot!(context.filters(), context.run().arg("--with").arg("anyio==4.2.0").arg("--no-sync").arg("main.py"), @r###"
1244+
uv_snapshot!(context.filters(), context.run().arg("--with").arg("anyio==4.2.0").arg("--no-sync").arg("main.py"), @r"
12381245
success: true
12391246
exit_code: 0
12401247
----- stdout -----
1248+
1.3.0
12411249
12421250
----- stderr -----
12431251
Resolved 3 packages in [TIME]
@@ -1246,7 +1254,7 @@ fn run_with() -> Result<()> {
12461254
+ anyio==4.2.0
12471255
+ idna==3.6
12481256
+ sniffio==1.3.0
1249-
"###);
1257+
");
12501258

12511259
// If the dependencies can't be resolved, we should reference `--with`.
12521260
uv_snapshot!(context.filters(), context.run().arg("--with").arg("add").arg("main.py"), @r###"

0 commit comments

Comments
 (0)