-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check existing source by normalized name before add and remove (#8359)
- Loading branch information
Showing
2 changed files
with
187 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2717,6 +2717,175 @@ fn update_source_replace_url() -> Result<()> { | |
); | ||
}); | ||
|
||
// Change the source again. The existing source should be replaced. | ||
uv_snapshot!(context.filters(), context.add().arg("requests @ git+https://github.com/psf/requests").arg("--tag=v2.32.2"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
----- stderr ----- | ||
Resolved 6 packages in [TIME] | ||
Prepared 2 packages in [TIME] | ||
Uninstalled 2 packages in [TIME] | ||
Installed 2 packages in [TIME] | ||
~ project==0.1.0 (from file://[TEMP_DIR]/) | ||
- requests==2.32.3 (from git+https://github.com/psf/requests@0e322af87745eff34caffe4df68456ebc20d9068) | ||
+ requests==2.32.2 (from git+https://github.com/psf/requests@88dce9d854797c05d0ff296b70e0430535ef8aaf) | ||
"###); | ||
|
||
let pyproject_toml = context.read("pyproject.toml"); | ||
|
||
insta::with_settings!({ | ||
filters => context.filters(), | ||
}, { | ||
assert_snapshot!( | ||
pyproject_toml, @r###" | ||
[project] | ||
name = "project" | ||
version = "0.1.0" | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"requests[security]", | ||
] | ||
[build-system] | ||
requires = ["setuptools>=42"] | ||
build-backend = "setuptools.build_meta" | ||
[tool.uv.sources] | ||
requests = { git = "https://github.com/psf/requests", tag = "v2.32.2" } | ||
"### | ||
); | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// If a source defined in `tool.uv.sources` but its name is not normalized, `uv add` should not | ||
/// add the same source again. | ||
#[test] | ||
#[cfg(feature = "git")] | ||
fn add_non_normalized_source() -> Result<()> { | ||
let context = TestContext::new("3.12"); | ||
|
||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str(indoc! {r#" | ||
[project] | ||
name = "project" | ||
version = "0.1.0" | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"uv-public-pypackage" | ||
] | ||
[build-system] | ||
requires = ["setuptools>=42"] | ||
build-backend = "setuptools.build_meta" | ||
[tool.uv.sources] | ||
uv_public_pypackage = { git = "https://github.com/astral-test/uv-public-pypackage", tag = "0.0.1" } | ||
"#})?; | ||
|
||
uv_snapshot!(context.filters(), context.add().arg("uv-public-pypackage @ git+https://github.com/astral-test/[email protected]"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
----- stderr ----- | ||
Resolved 2 packages in [TIME] | ||
Prepared 2 packages in [TIME] | ||
Installed 2 packages in [TIME] | ||
+ project==0.1.0 (from file://[TEMP_DIR]/) | ||
+ uv-public-pypackage==0.1.0 (from git+https://github.com/astral-test/uv-public-pypackage@0dacfd662c64cb4ceb16e6cf65a157a8b715b979) | ||
"###); | ||
|
||
let pyproject_toml = context.read("pyproject.toml"); | ||
|
||
insta::with_settings!({ | ||
filters => context.filters(), | ||
}, { | ||
assert_snapshot!( | ||
pyproject_toml, @r###" | ||
[project] | ||
name = "project" | ||
version = "0.1.0" | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"uv-public-pypackage", | ||
] | ||
[build-system] | ||
requires = ["setuptools>=42"] | ||
build-backend = "setuptools.build_meta" | ||
[tool.uv.sources] | ||
uv-public-pypackage = { git = "https://github.com/astral-test/uv-public-pypackage", rev = "0.0.1" } | ||
"### | ||
); | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
/// If a source defined in `tool.uv.sources` but its name is not normalized, `uv remove` should | ||
/// remove the source. | ||
#[test] | ||
#[cfg(feature = "git")] | ||
fn remove_non_normalized_source() -> Result<()> { | ||
let context = TestContext::new("3.12"); | ||
|
||
let pyproject_toml = context.temp_dir.child("pyproject.toml"); | ||
pyproject_toml.write_str(indoc! {r#" | ||
[project] | ||
name = "project" | ||
version = "0.1.0" | ||
requires-python = ">=3.12" | ||
dependencies = [ | ||
"uv-public-pypackage" | ||
] | ||
[build-system] | ||
requires = ["setuptools>=42"] | ||
build-backend = "setuptools.build_meta" | ||
[tool.uv.sources] | ||
uv_public_pypackage = { git = "https://github.com/astral-test/uv-public-pypackage", tag = "0.0.1" } | ||
"#})?; | ||
|
||
uv_snapshot!(context.filters(), context.remove().arg("uv-public-pypackage"), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
----- stderr ----- | ||
Resolved 1 package in [TIME] | ||
Prepared 1 package in [TIME] | ||
Installed 1 package in [TIME] | ||
+ project==0.1.0 (from file://[TEMP_DIR]/) | ||
"###); | ||
|
||
let pyproject_toml = context.read("pyproject.toml"); | ||
|
||
insta::with_settings!({ | ||
filters => context.filters(), | ||
}, { | ||
assert_snapshot!( | ||
pyproject_toml, @r###" | ||
[project] | ||
name = "project" | ||
version = "0.1.0" | ||
requires-python = ">=3.12" | ||
dependencies = [] | ||
[build-system] | ||
requires = ["setuptools>=42"] | ||
build-backend = "setuptools.build_meta" | ||
[tool.uv.sources] | ||
"### | ||
); | ||
}); | ||
|
||
Ok(()) | ||
} | ||
|
||
|