mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 19:08:04 +00:00
Merge 82aab8e265
into c3f13d2505
This commit is contained in:
commit
5c58f8dea8
16 changed files with 891 additions and 25 deletions
|
@ -239,7 +239,7 @@ pub(crate) async fn add(
|
|||
.with_context(|| format!("Package `{package}` not found in workspace"))?,
|
||||
)
|
||||
} else {
|
||||
VirtualProject::discover(
|
||||
VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&WorkspaceCache::default(),
|
||||
|
|
|
@ -87,7 +87,7 @@ pub(crate) async fn export(
|
|||
ExportTarget::Script(script)
|
||||
} else {
|
||||
let project = if frozen {
|
||||
VirtualProject::discover(
|
||||
VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions {
|
||||
members: MemberDiscovery::None,
|
||||
|
@ -104,8 +104,12 @@ pub(crate) async fn export(
|
|||
.with_context(|| format!("Package `{package}` not found in workspace"))?,
|
||||
)
|
||||
} else {
|
||||
VirtualProject::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache)
|
||||
.await?
|
||||
VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&workspace_cache,
|
||||
)
|
||||
.await?
|
||||
};
|
||||
ExportTarget::Project(project)
|
||||
};
|
||||
|
|
|
@ -100,7 +100,7 @@ pub(crate) async fn remove(
|
|||
.with_context(|| format!("Package `{package}` not found in workspace"))?,
|
||||
)
|
||||
} else {
|
||||
VirtualProject::discover(
|
||||
VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&WorkspaceCache::default(),
|
||||
|
|
|
@ -526,7 +526,7 @@ hint: If you are running a script with `{}` in the shebang, you may need to incl
|
|||
.with_context(|| format!("Package `{package}` not found in workspace"))?,
|
||||
))
|
||||
} else {
|
||||
match VirtualProject::discover(
|
||||
match VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&workspace_cache,
|
||||
|
|
|
@ -83,7 +83,7 @@ pub(crate) async fn sync(
|
|||
} else {
|
||||
// Identify the project.
|
||||
let project = if frozen {
|
||||
VirtualProject::discover(
|
||||
VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions {
|
||||
members: MemberDiscovery::None,
|
||||
|
@ -100,8 +100,12 @@ pub(crate) async fn sync(
|
|||
.with_context(|| format!("Package `{package}` not found in workspace"))?,
|
||||
)
|
||||
} else {
|
||||
VirtualProject::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache)
|
||||
.await?
|
||||
VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&workspace_cache,
|
||||
)
|
||||
.await?
|
||||
};
|
||||
|
||||
// TODO(lucab): improve warning content
|
||||
|
|
|
@ -231,7 +231,7 @@ async fn find_target(project_dir: &Path, package: Option<&PackageName>) -> Resul
|
|||
.with_context(|| format!("Package `{package}` not found in workspace"))?,
|
||||
)
|
||||
} else {
|
||||
VirtualProject::discover(
|
||||
VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&WorkspaceCache::default(),
|
||||
|
|
|
@ -44,8 +44,12 @@ pub(crate) async fn find(
|
|||
let project = if no_project {
|
||||
None
|
||||
} else {
|
||||
match VirtualProject::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache)
|
||||
.await
|
||||
match VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&workspace_cache,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(project) => Some(project),
|
||||
Err(WorkspaceError::MissingProject(_)) => None,
|
||||
|
|
|
@ -46,8 +46,12 @@ pub(crate) async fn pin(
|
|||
let virtual_project = if no_project {
|
||||
None
|
||||
} else {
|
||||
match VirtualProject::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache)
|
||||
.await
|
||||
match VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&workspace_cache,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(virtual_project) => Some(virtual_project),
|
||||
Err(err) => {
|
||||
|
|
|
@ -157,8 +157,12 @@ async fn venv_impl(
|
|||
let project = if no_project {
|
||||
None
|
||||
} else {
|
||||
match VirtualProject::discover(project_dir, &DiscoveryOptions::default(), &workspace_cache)
|
||||
.await
|
||||
match VirtualProject::discover_defaulted(
|
||||
project_dir,
|
||||
&DiscoveryOptions::default(),
|
||||
&workspace_cache,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(project) => Some(project),
|
||||
Err(WorkspaceError::MissingProject(_)) => None,
|
||||
|
|
|
@ -4525,6 +4525,306 @@ fn add_non_project() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_virtual_empty() -> Result<()> {
|
||||
// testing how `uv add` reacts to a pyproject with no `[project]` and nothing useful to it
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#})?;
|
||||
|
||||
// Add normal dep (doesn't make sense)
|
||||
uv_snapshot!(context.filters(), context.add()
|
||||
.arg("sortedcontainers"), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Project is missing a `[project]` table; add a `[project]` table to use production dependencies, or run `uv add --dev` instead
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
// Add dependency-group (can make sense!)
|
||||
uv_snapshot!(context.filters(), context.add()
|
||||
.arg("sortedcontainers")
|
||||
.arg("--group").arg("dev"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 1 package in [TIME]
|
||||
Prepared 1 package in [TIME]
|
||||
Installed 1 package in [TIME]
|
||||
+ sortedcontainers==2.4.0
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
|
||||
[dependency-groups]
|
||||
dev = [
|
||||
"sortedcontainers>=2.4.0",
|
||||
]
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_virtual_dependency_group() -> Result<()> {
|
||||
// testing basic `uv add --group` functionality
|
||||
// when the pyproject.toml is fully virtual (no `[project]`)
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#})?;
|
||||
|
||||
// Add to existing group
|
||||
uv_snapshot!(context.filters(), context.add()
|
||||
.arg("sortedcontainers")
|
||||
.arg("--group").arg("dev"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 3 packages in [TIME]
|
||||
Prepared 2 packages in [TIME]
|
||||
Installed 2 packages in [TIME]
|
||||
+ sniffio==1.3.1
|
||||
+ sortedcontainers==2.4.0
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = [
|
||||
"sniffio",
|
||||
"sortedcontainers>=2.4.0",
|
||||
]
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
// Add to new group
|
||||
uv_snapshot!(context.filters(), context.add()
|
||||
.arg("sortedcontainers")
|
||||
.arg("--group").arg("baz"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 3 packages in [TIME]
|
||||
Audited 2 packages in [TIME]
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = [
|
||||
"sniffio",
|
||||
"sortedcontainers>=2.4.0",
|
||||
]
|
||||
baz = [
|
||||
"sortedcontainers>=2.4.0",
|
||||
]
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_virtual_empty() -> Result<()> {
|
||||
// testing how `uv remove` reacts to a pyproject with no `[project]` and nothing useful to it
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(
|
||||
r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
|
||||
"#,
|
||||
)?;
|
||||
|
||||
// Remove normal dep (doesn't make sense)
|
||||
uv_snapshot!(context.filters(), context.remove()
|
||||
.arg("sortedcontainers"), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: The dependency `sortedcontainers` could not be found in `project.dependencies`
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
// Remove dependency-group (can make sense, but nothing there!)
|
||||
uv_snapshot!(context.filters(), context.remove()
|
||||
.arg("sortedcontainers")
|
||||
.arg("--group").arg("dev"), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: The dependency `sortedcontainers` could not be found in `tool.uv.dev-dependencies` or `tool.uv.dependency-groups.dev`
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn remove_virtual_dependency_group() -> Result<()> {
|
||||
// testing basic `uv remove --group` functionality
|
||||
// when the pyproject.toml is fully virtual (no `[project]`)
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#})?;
|
||||
|
||||
// Remove from group
|
||||
uv_snapshot!(context.filters(), context.remove()
|
||||
.arg("sortedcontainers")
|
||||
.arg("--group").arg("foo"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 2 packages in [TIME]
|
||||
Prepared 1 package in [TIME]
|
||||
Installed 1 package in [TIME]
|
||||
+ sniffio==1.3.1
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[dependency-groups]
|
||||
foo = []
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
// Remove from non-existent group
|
||||
uv_snapshot!(context.filters(), context.remove()
|
||||
.arg("sortedcontainers")
|
||||
.arg("--group").arg("baz"), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: The dependency `sortedcontainers` could not be found in `dependency-groups.baz`
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[dependency-groups]
|
||||
foo = []
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Add the same requirement multiple times.
|
||||
#[test]
|
||||
fn add_repeat() -> Result<()> {
|
||||
|
|
|
@ -1143,6 +1143,102 @@ fn requirements_txt_non_project() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_empty() -> Result<()> {
|
||||
// testing how `uv export` reacts to a pyproject with no `[project]` and nothing useful to it
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#})?;
|
||||
|
||||
uv_snapshot!(context.filters(), context.export(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
# This file was autogenerated by uv via the following command:
|
||||
# uv export --cache-dir [CACHE_DIR]
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved in [TIME]
|
||||
");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_dependency_group() -> Result<()> {
|
||||
// testing basic `uv export --group` functionality
|
||||
// when the pyproject.toml is fully virtual (no `[project]`)
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#})?;
|
||||
|
||||
// default groups
|
||||
uv_snapshot!(context.filters(), context.export(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
# This file was autogenerated by uv via the following command:
|
||||
# uv export --cache-dir [CACHE_DIR]
|
||||
sniffio==1.3.1 \
|
||||
--hash=sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2 \
|
||||
--hash=sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 3 packages in [TIME]
|
||||
");
|
||||
|
||||
// explicit --group
|
||||
uv_snapshot!(context.filters(), context.export()
|
||||
.arg("--group").arg("bar"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
# This file was autogenerated by uv via the following command:
|
||||
# uv export --cache-dir [CACHE_DIR] --group bar
|
||||
iniconfig==2.0.0 \
|
||||
--hash=sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3 \
|
||||
--hash=sha256:b6a85871a79d2e3b22d2d1b94ac2824226a63c6b741c88f7ae975f18b6778374
|
||||
sniffio==1.3.1 \
|
||||
--hash=sha256:2f6da418d1f1e0fddd844478f41680e794e6051915791a034ff65e5f100525a2 \
|
||||
--hash=sha256:f4324edc670a0f49750a81b895f35c3adb843cca46f0530f79fc1babb23789dc
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 3 packages in [TIME]
|
||||
");
|
||||
|
||||
// explicit --only-group
|
||||
uv_snapshot!(context.filters(), context.export()
|
||||
.arg("--only-group").arg("foo"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
# This file was autogenerated by uv via the following command:
|
||||
# uv export --cache-dir [CACHE_DIR] --only-group foo
|
||||
sortedcontainers==2.4.0 \
|
||||
--hash=sha256:25caa5a06cc30b6b83d11423433f65d1f9d76c4c6a0c90e3379eaa43b9bfdb88 \
|
||||
--hash=sha256:a163dcaede0f1c021485e957a39245190e74249897e2ae4b2aa38595db237ee0
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 3 packages in [TIME]
|
||||
");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "git")]
|
||||
#[test]
|
||||
fn requirements_txt_https_git_credentials() -> Result<()> {
|
||||
|
|
|
@ -403,6 +403,180 @@ fn python_find_project() {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_empty() {
|
||||
// testing how `uv python find` reacts to a pyproject with no `[project]` and nothing useful to it
|
||||
let context = TestContext::new_with_versions(&["3.10", "3.11", "3.12"]);
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml
|
||||
.write_str(indoc! {r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#})
|
||||
.unwrap();
|
||||
|
||||
// Ask for the python
|
||||
uv_snapshot!(context.filters(), context.python_find(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.10]
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Ask for the python (--no-project)
|
||||
uv_snapshot!(context.filters(), context.python_find()
|
||||
.arg("--no-project"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.10]
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Ask for specific python (3.11)
|
||||
uv_snapshot!(context.filters(), context.python_find().arg("3.11"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.11]
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Create a pin
|
||||
uv_snapshot!(context.filters(), context.python_pin().arg("3.12"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
Pinned `.python-version` to `3.12`
|
||||
|
||||
----- stderr -----
|
||||
"###);
|
||||
|
||||
// Ask for the python
|
||||
uv_snapshot!(context.filters(), context.python_find(), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.12]
|
||||
|
||||
----- stderr -----
|
||||
"###);
|
||||
|
||||
// Ask for specific python (3.11)
|
||||
uv_snapshot!(context.filters(), context.python_find().arg("3.11"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.11]
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Ask for the python (--no-project)
|
||||
uv_snapshot!(context.filters(), context.python_find(), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.12]
|
||||
|
||||
----- stderr -----
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_dependency_group() {
|
||||
// testing basic `uv python find` functionality
|
||||
// when the pyproject.toml is fully virtual (no `[project]`, but `[dependency-groups]` defined,
|
||||
// which really shouldn't matter)
|
||||
let context = TestContext::new_with_versions(&["3.10", "3.11", "3.12"]);
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml
|
||||
.write_str(indoc! {r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#})
|
||||
.unwrap();
|
||||
|
||||
// Ask for the python
|
||||
uv_snapshot!(context.filters(), context.python_find(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.10]
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Ask for the python (--no-project)
|
||||
uv_snapshot!(context.filters(), context.python_find()
|
||||
.arg("--no-project"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.10]
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Ask for specific python (3.11)
|
||||
uv_snapshot!(context.filters(), context.python_find().arg("3.11"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.11]
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Create a pin
|
||||
uv_snapshot!(context.filters(), context.python_pin().arg("3.12"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
Pinned `.python-version` to `3.12`
|
||||
|
||||
----- stderr -----
|
||||
"###);
|
||||
|
||||
// Ask for the python
|
||||
uv_snapshot!(context.filters(), context.python_find(), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.12]
|
||||
|
||||
----- stderr -----
|
||||
"###);
|
||||
|
||||
// Ask for specific python (3.11)
|
||||
uv_snapshot!(context.filters(), context.python_find().arg("3.11"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.11]
|
||||
|
||||
----- stderr -----
|
||||
");
|
||||
|
||||
// Ask for the python (--no-project)
|
||||
uv_snapshot!(context.filters(), context.python_find(), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[PYTHON-3.12]
|
||||
|
||||
----- stderr -----
|
||||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn python_find_venv() {
|
||||
let context: TestContext = TestContext::new_with_versions(&["3.11", "3.12"])
|
||||
|
|
|
@ -3063,9 +3063,9 @@ fn run_module_stdin() {
|
|||
"###);
|
||||
}
|
||||
|
||||
/// When the `pyproject.toml` file is invalid.
|
||||
/// Test for how run reacts to a pyproject.toml without a `[project]`
|
||||
#[test]
|
||||
fn run_project_toml_error() -> Result<()> {
|
||||
fn virtual_empty() -> Result<()> {
|
||||
let context = TestContext::new("3.12")
|
||||
.with_filtered_python_names()
|
||||
.with_filtered_virtualenv_bin()
|
||||
|
@ -3081,17 +3081,20 @@ fn run_project_toml_error() -> Result<()> {
|
|||
let init = src.child("__init__.py");
|
||||
init.touch()?;
|
||||
|
||||
// `run` should fail
|
||||
uv_snapshot!(context.filters(), context.run().arg("python").arg("-c").arg("import sys; print(sys.executable)"), @r###"
|
||||
success: false
|
||||
exit_code: 2
|
||||
// `run` should work fine
|
||||
uv_snapshot!(context.filters(), context.run().arg("python").arg("-c").arg("import sys; print(sys.executable)"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
[VENV]/[BIN]/python
|
||||
|
||||
----- stderr -----
|
||||
error: No `project` table found in: `[TEMP_DIR]/pyproject.toml`
|
||||
"###);
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved in [TIME]
|
||||
Audited in [TIME]
|
||||
");
|
||||
|
||||
// `run --no-project` should not
|
||||
// `run --no-project` should also work fine
|
||||
uv_snapshot!(context.filters(), context.run().arg("--no-project").arg("python").arg("-c").arg("import sys; print(sys.executable)"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
|
|
|
@ -3875,6 +3875,95 @@ fn virtual_no_build() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_empty() -> Result<()> {
|
||||
// testing how `uv sync` reacts to a pyproject with no `[project]` and nothing useful to it
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#})?;
|
||||
|
||||
uv_snapshot!(context.filters(), context.sync(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved in [TIME]
|
||||
Audited in [TIME]
|
||||
");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_dependency_group() -> Result<()> {
|
||||
// testing basic `uv sync --group` functionality
|
||||
// when the pyproject.toml is fully virtual (no `[project]`)
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#})?;
|
||||
|
||||
// default groups
|
||||
uv_snapshot!(context.filters(), context.sync(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 3 packages in [TIME]
|
||||
Prepared 1 package in [TIME]
|
||||
Installed 1 package in [TIME]
|
||||
+ sniffio==1.3.1
|
||||
");
|
||||
|
||||
// explicit --group
|
||||
uv_snapshot!(context.filters(), context.sync()
|
||||
.arg("--group").arg("bar"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 3 packages in [TIME]
|
||||
Prepared 1 package in [TIME]
|
||||
Installed 1 package in [TIME]
|
||||
+ iniconfig==2.0.0
|
||||
");
|
||||
|
||||
// explicit --only-group
|
||||
uv_snapshot!(context.filters(), context.sync()
|
||||
.arg("--only-group").arg("foo"), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
warning: No `requires-python` value found in the workspace. Defaulting to `>=3.12`.
|
||||
Resolved 3 packages in [TIME]
|
||||
Prepared 1 package in [TIME]
|
||||
Uninstalled 2 packages in [TIME]
|
||||
Installed 1 package in [TIME]
|
||||
- iniconfig==2.0.0
|
||||
- sniffio==1.3.1
|
||||
+ sortedcontainers==2.4.0
|
||||
");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_no_build_dynamic_cached() -> Result<()> {
|
||||
let context = TestContext::new("3.12");
|
||||
|
|
|
@ -189,6 +189,59 @@ fn create_venv_project_environment() -> Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_empty() -> Result<()> {
|
||||
// testing how `uv venv` reacts to a pyproject with no `[project]` and nothing useful to it
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#})?;
|
||||
|
||||
uv_snapshot!(context.filters(), context.venv(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
|
||||
Creating virtual environment at: .venv
|
||||
Activate with: source .venv/[BIN]/activate
|
||||
");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_dependency_group() -> Result<()> {
|
||||
// testing basic `uv venv` functionality
|
||||
// when the pyproject.toml is fully virtual (no `[project]`, but `[dependency-groups]` defined)
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#})?;
|
||||
|
||||
uv_snapshot!(context.filters(), context.venv(), @r"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
|
||||
Creating virtual environment at: .venv
|
||||
Activate with: source .venv/[BIN]/activate
|
||||
");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create_venv_defaults_to_cwd() {
|
||||
let context = TestContext::new_with_versions(&["3.12"]);
|
||||
|
|
|
@ -1958,3 +1958,134 @@ fn version_set_evil_constraints() -> Result<()> {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn virtual_empty() -> Result<()> {
|
||||
// testing how `uv version` reacts to a pyproject with no `[project]` and nothing useful to it
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#})?;
|
||||
|
||||
// Get version (doesn't make sense)
|
||||
uv_snapshot!(context.filters(), context.version()
|
||||
.arg("sortedcontainers"), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Missing `project.name` field in: pyproject.toml
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
// Set version (can make sense, but we should still refuse?)
|
||||
uv_snapshot!(context.filters(), context.version()
|
||||
.arg("1.0.0"), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Missing `project.name` field in: pyproject.toml
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[tool.mycooltool]
|
||||
wow = "someconfig"
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_virtual_dependency_group() -> Result<()> {
|
||||
// testing basic `uv version` functionality
|
||||
// when the pyproject.toml is fully virtual (no `[project]`)
|
||||
// But at least has some dependency-group tables (shouldn't matter to this command)
|
||||
let context = TestContext::new("3.12");
|
||||
|
||||
let pyproject_toml = context.temp_dir.child("pyproject.toml");
|
||||
pyproject_toml.write_str(indoc! {r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#})?;
|
||||
|
||||
// Get the version (doesn't make sense)
|
||||
uv_snapshot!(context.filters(), context.version(), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Missing `project.name` field in: pyproject.toml
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
// Set the version (can make sense, we should refuse?)
|
||||
uv_snapshot!(context.filters(), context.version()
|
||||
.arg("1.0.0"), @r"
|
||||
success: false
|
||||
exit_code: 2
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
error: Missing `project.name` field in: pyproject.toml
|
||||
");
|
||||
|
||||
let pyproject_toml = context.read("pyproject.toml");
|
||||
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject_toml, @r#"
|
||||
[dependency-groups]
|
||||
foo = ["sortedcontainers"]
|
||||
bar = ["iniconfig"]
|
||||
dev = ["sniffio"]
|
||||
"#
|
||||
);
|
||||
});
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue