Skip to content

Commit 666ae61

Browse files
committed
Revert breaking uv add related changes
1 parent 31ca0ea commit 666ae61

2 files changed

Lines changed: 18 additions & 23 deletions

File tree

crates/uv-workspace/src/pyproject.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use tracing::instrument;
2424
use uv_build_backend::BuildBackendSettings;
2525
use uv_configuration::GitLfsSetting;
2626
use uv_distribution_types::{Index, IndexName, RequirementSource};
27-
use uv_fs::{PortablePathBuf, try_relative_to_if};
27+
use uv_fs::{PortablePathBuf, relative_to};
2828
use uv_git_types::GitReference;
2929
use uv_macros::OptionsMetadata;
3030
use uv_normalize::{DefaultGroups, ExtraName, GroupName, PackageName};
@@ -1724,13 +1724,12 @@ impl Source {
17241724
return Ok(None);
17251725
}
17261726
}
1727-
RequirementSource::Path {
1728-
install_path, url, ..
1729-
} => Self::Path {
1727+
RequirementSource::Path { install_path, .. } => Self::Path {
17301728
editable: None,
17311729
package: None,
17321730
path: PortablePathBuf::from(
1733-
try_relative_to_if(&install_path, root, !url.was_given_absolute())
1731+
relative_to(&install_path, root)
1732+
.or_else(|_| std::path::absolute(&install_path))
17341733
.map_err(SourceError::Absolute)?
17351734
.into_boxed_path(),
17361735
),
@@ -1741,13 +1740,13 @@ impl Source {
17411740
RequirementSource::Directory {
17421741
install_path,
17431742
editable: is_editable,
1744-
url,
17451743
..
17461744
} => Self::Path {
17471745
editable: editable.or(is_editable),
17481746
package: None,
17491747
path: PortablePathBuf::from(
1750-
try_relative_to_if(&install_path, root, !url.was_given_absolute())
1748+
relative_to(&install_path, root)
1749+
.or_else(|_| std::path::absolute(&install_path))
17511750
.map_err(SourceError::Absolute)?
17521751
.into_boxed_path(),
17531752
),

crates/uv/tests/it/edit.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3064,7 +3064,7 @@ fn add_path_adjacent_directory() -> Result<()> {
30643064
]
30653065
30663066
[tool.uv.sources]
3067-
dependency = { path = "[TEMP_DIR]/dependency" }
3067+
dependency = { path = "../dependency" }
30683068
"#
30693069
);
30703070
});
@@ -3087,7 +3087,7 @@ fn add_path_adjacent_directory() -> Result<()> {
30873087
[[package]]
30883088
name = "dependency"
30893089
version = "0.1.0"
3090-
source = { directory = "[TEMP_DIR]/dependency" }
3090+
source = { directory = "../dependency" }
30913091
30923092
[[package]]
30933093
name = "project"
@@ -3098,7 +3098,7 @@ fn add_path_adjacent_directory() -> Result<()> {
30983098
]
30993099
31003100
[package.metadata]
3101-
requires-dist = [{ name = "dependency", directory = "[TEMP_DIR]/dependency" }]
3101+
requires-dist = [{ name = "dependency", directory = "../dependency" }]
31023102
"#
31033103
);
31043104
});
@@ -3108,10 +3108,7 @@ fn add_path_adjacent_directory() -> Result<()> {
31083108

31093109
/// Check relative and absolute path handling with `uv add`.
31103110
///
3111-
/// When a user provides an absolute path or `file://` URL, it should be preserved as absolute
3112-
/// in pyproject.toml and uv.lock. Relative paths should remain relative.
3113-
///
3114-
/// See: <https://github.com/astral-sh/uv/issues/17307>
3111+
/// BUG: Currently `uv add` always relativizes paths in `pyproject.toml`
31153112
#[test]
31163113
fn add_relative_and_absolute_paths() -> Result<()> {
31173114
let context = uv_test::test_context!("3.12");
@@ -3224,8 +3221,7 @@ fn add_relative_and_absolute_paths() -> Result<()> {
32243221
+ file-url-dep==0.1.0 (from file://[TEMP_DIR]/file_url_dep)
32253222
");
32263223

3227-
// Check pyproject.toml - relative paths stay relative, absolute paths and file:// URLs
3228-
// stay absolute.
3224+
// Check pyproject.toml.
32293225
let pyproject_toml = fs_err::read_to_string(project.join("pyproject.toml"))?;
32303226

32313227
insta::with_settings!({
@@ -3245,13 +3241,13 @@ fn add_relative_and_absolute_paths() -> Result<()> {
32453241
32463242
[tool.uv.sources]
32473243
relative-dep = { path = "../relative_dep" }
3248-
absolute-dep = { path = "[TEMP_DIR]/absolute_dep" }
3249-
file-url-dep = { path = "[TEMP_DIR]/file_url_dep" }
3244+
absolute-dep = { path = "../absolute_dep" }
3245+
file-url-dep = { path = "../file_url_dep" }
32503246
"#
32513247
);
32523248
});
32533249

3254-
// Check uv.lock - relative paths stay relative, absolute paths stay absolute.
3250+
// Check uv.lock.
32553251
let lock = fs_err::read_to_string(project.join("uv.lock"))?;
32563252

32573253
insta::with_settings!({
@@ -3269,12 +3265,12 @@ fn add_relative_and_absolute_paths() -> Result<()> {
32693265
[[package]]
32703266
name = "absolute-dep"
32713267
version = "0.1.0"
3272-
source = { directory = "[TEMP_DIR]/absolute_dep" }
3268+
source = { directory = "../absolute_dep" }
32733269
32743270
[[package]]
32753271
name = "file-url-dep"
32763272
version = "0.1.0"
3277-
source = { directory = "[TEMP_DIR]/file_url_dep" }
3273+
source = { directory = "../file_url_dep" }
32783274
32793275
[[package]]
32803276
name = "project"
@@ -3288,8 +3284,8 @@ fn add_relative_and_absolute_paths() -> Result<()> {
32883284
32893285
[package.metadata]
32903286
requires-dist = [
3291-
{ name = "absolute-dep", directory = "[TEMP_DIR]/absolute_dep" },
3292-
{ name = "file-url-dep", directory = "[TEMP_DIR]/file_url_dep" },
3287+
{ name = "absolute-dep", directory = "../absolute_dep" },
3288+
{ name = "file-url-dep", directory = "../file_url_dep" },
32933289
{ name = "relative-dep", directory = "../relative_dep" },
32943290
]
32953291

0 commit comments

Comments
 (0)