Skip to content

Commit 5f3cc18

Browse files
committed
Support conflicting editable settings across groups
1 parent a82c210 commit 5f3cc18

File tree

22 files changed

+336
-135
lines changed

22 files changed

+336
-135
lines changed

crates/uv-distribution-types/src/buildable.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ impl SourceUrl<'_> {
124124
pub fn is_editable(&self) -> bool {
125125
matches!(
126126
self,
127-
Self::Directory(DirectorySourceUrl { editable: true, .. })
127+
Self::Directory(DirectorySourceUrl {
128+
editable: Some(true),
129+
..
130+
})
128131
)
129132
}
130133

@@ -210,7 +213,7 @@ impl<'a> From<&'a PathSourceDist> for PathSourceUrl<'a> {
210213
pub struct DirectorySourceUrl<'a> {
211214
pub url: &'a DisplaySafeUrl,
212215
pub install_path: Cow<'a, Path>,
213-
pub editable: bool,
216+
pub editable: Option<bool>,
214217
}
215218

216219
impl std::fmt::Display for DirectorySourceUrl<'_> {

crates/uv-distribution-types/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,9 +343,9 @@ pub struct DirectorySourceDist {
343343
/// The absolute path to the distribution which we use for installing.
344344
pub install_path: Box<Path>,
345345
/// Whether the package should be installed in editable mode.
346-
pub editable: bool,
346+
pub editable: Option<bool>,
347347
/// Whether the package should be built and installed.
348-
pub r#virtual: bool,
348+
pub r#virtual: Option<bool>,
349349
/// The URL as it was provided by the user.
350350
pub url: VerbatimUrl,
351351
}
@@ -452,8 +452,8 @@ impl Dist {
452452
name: PackageName,
453453
url: VerbatimUrl,
454454
install_path: &Path,
455-
editable: bool,
456-
r#virtual: bool,
455+
editable: Option<bool>,
456+
r#virtual: Option<bool>,
457457
) -> Result<Dist, Error> {
458458
// Convert to an absolute path.
459459
let install_path = path::absolute(install_path)?;
@@ -655,15 +655,15 @@ impl SourceDist {
655655
/// Returns `true` if the distribution is editable.
656656
pub fn is_editable(&self) -> bool {
657657
match self {
658-
Self::Directory(DirectorySourceDist { editable, .. }) => *editable,
658+
Self::Directory(DirectorySourceDist { editable, .. }) => editable.unwrap_or(false),
659659
_ => false,
660660
}
661661
}
662662

663663
/// Returns `true` if the distribution is virtual.
664664
pub fn is_virtual(&self) -> bool {
665665
match self {
666-
Self::Directory(DirectorySourceDist { r#virtual, .. }) => *r#virtual,
666+
Self::Directory(DirectorySourceDist { r#virtual, .. }) => r#virtual.unwrap_or(false),
667667
_ => false,
668668
}
669669
}

crates/uv-distribution-types/src/requirement.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,9 @@ pub enum RequirementSource {
429429
/// The absolute path to the distribution which we use for installing.
430430
install_path: Box<Path>,
431431
/// For a source tree (a directory), whether to install as an editable.
432-
editable: bool,
432+
editable: Option<bool>,
433433
/// For a source tree (a directory), whether the project should be built and installed.
434-
r#virtual: bool,
434+
r#virtual: Option<bool>,
435435
/// The PEP 508 style URL in the format
436436
/// `file:///<path>#subdirectory=<subdirectory>`.
437437
url: VerbatimUrl,
@@ -545,7 +545,13 @@ impl RequirementSource {
545545

546546
/// Returns `true` if the source is editable.
547547
pub fn is_editable(&self) -> bool {
548-
matches!(self, Self::Directory { editable: true, .. })
548+
matches!(
549+
self,
550+
Self::Directory {
551+
editable: Some(true),
552+
..
553+
}
554+
)
549555
}
550556

551557
/// Returns `true` if the source is empty.
@@ -792,11 +798,11 @@ impl From<RequirementSource> for RequirementSourceWire {
792798
r#virtual,
793799
url: _,
794800
} => {
795-
if editable {
801+
if editable.unwrap_or(false) {
796802
Self::Editable {
797803
editable: PortablePathBuf::from(install_path),
798804
}
799-
} else if r#virtual {
805+
} else if r#virtual.unwrap_or(false) {
800806
Self::Virtual {
801807
r#virtual: PortablePathBuf::from(install_path),
802808
}
@@ -908,8 +914,8 @@ impl TryFrom<RequirementSourceWire> for RequirementSource {
908914
))?;
909915
Ok(Self::Directory {
910916
install_path: directory,
911-
editable: false,
912-
r#virtual: false,
917+
editable: Some(false),
918+
r#virtual: Some(false),
913919
url,
914920
})
915921
}
@@ -920,8 +926,8 @@ impl TryFrom<RequirementSourceWire> for RequirementSource {
920926
))?;
921927
Ok(Self::Directory {
922928
install_path: editable,
923-
editable: true,
924-
r#virtual: false,
929+
editable: Some(true),
930+
r#virtual: Some(false),
925931
url,
926932
})
927933
}
@@ -932,8 +938,8 @@ impl TryFrom<RequirementSourceWire> for RequirementSource {
932938
))?;
933939
Ok(Self::Directory {
934940
install_path: r#virtual,
935-
editable: false,
936-
r#virtual: true,
941+
editable: Some(false),
942+
r#virtual: Some(true),
937943
url,
938944
})
939945
}
@@ -980,8 +986,8 @@ mod tests {
980986
marker: MarkerTree::TRUE,
981987
source: RequirementSource::Directory {
982988
install_path: PathBuf::from(path).into_boxed_path(),
983-
editable: false,
984-
r#virtual: false,
989+
editable: Some(false),
990+
r#virtual: Some(false),
985991
url: VerbatimUrl::from_absolute_path(path).unwrap(),
986992
},
987993
origin: None,

crates/uv-distribution/src/index/built_wheel_index.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl<'a> BuiltWheelIndex<'a> {
119119
) -> Result<Option<CachedWheel>, Error> {
120120
let cache_shard = self.cache.shard(
121121
CacheBucket::SourceDistributions,
122-
if source_dist.editable {
122+
if source_dist.editable.unwrap_or(false) {
123123
WheelCache::Editable(&source_dist.url).root()
124124
} else {
125125
WheelCache::Path(&source_dist.url).root()

crates/uv-distribution/src/metadata/lowering.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,15 @@ impl LoweredRequirement {
310310
RequirementSource::Directory {
311311
install_path: install_path.into_boxed_path(),
312312
url,
313-
editable: true,
314-
r#virtual: false,
313+
editable: Some(true),
314+
r#virtual: Some(false),
315315
}
316316
} else {
317317
RequirementSource::Directory {
318318
install_path: install_path.into_boxed_path(),
319319
url,
320-
editable: false,
321-
r#virtual: true,
320+
editable: Some(false),
321+
r#virtual: Some(true),
322322
}
323323
};
324324
(source, marker)
@@ -718,8 +718,8 @@ fn path_source(
718718
Ok(RequirementSource::Directory {
719719
install_path: install_path.into_boxed_path(),
720720
url,
721-
editable: true,
722-
r#virtual: false,
721+
editable,
722+
r#virtual: Some(false),
723723
})
724724
} else {
725725
// Determine whether the project is a package or virtual.
@@ -735,9 +735,9 @@ fn path_source(
735735
Ok(RequirementSource::Directory {
736736
install_path: install_path.into_boxed_path(),
737737
url,
738-
editable: false,
738+
editable,
739739
// If a project is not a package, treat it as a virtual dependency.
740-
r#virtual: !is_package,
740+
r#virtual: Some(!is_package),
741741
})
742742
}
743743
} else {

crates/uv-distribution/src/source/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
10701070

10711071
let cache_shard = self.build_context.cache().shard(
10721072
CacheBucket::SourceDistributions,
1073-
if resource.editable {
1073+
if resource.editable.unwrap_or(false) {
10741074
WheelCache::Editable(resource.url).root()
10751075
} else {
10761076
WheelCache::Path(resource.url).root()
@@ -1183,7 +1183,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
11831183

11841184
let cache_shard = self.build_context.cache().shard(
11851185
CacheBucket::SourceDistributions,
1186-
if resource.editable {
1186+
if resource.editable.unwrap_or(false) {
11871187
WheelCache::Editable(resource.url).root()
11881188
} else {
11891189
WheelCache::Path(resource.url).root()

crates/uv-installer/src/satisfies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl RequirementSatisfaction {
241241
return Self::Mismatch;
242242
};
243243

244-
if *requested_editable != installed_editable.unwrap_or_default() {
244+
if requested_editable != installed_editable {
245245
trace!(
246246
"Editable mismatch: {:?} vs. {:?}",
247247
*requested_editable,

crates/uv-pypi-types/src/parsed_url.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
8686
ParsedUrl::Directory(ParsedDirectoryUrl {
8787
url,
8888
install_path,
89-
editable: false,
90-
r#virtual: false,
89+
editable: None,
90+
r#virtual: None,
9191
})
9292
} else {
9393
ParsedUrl::Path(ParsedPathUrl {
@@ -118,8 +118,8 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
118118
ParsedUrl::Directory(ParsedDirectoryUrl {
119119
url,
120120
install_path,
121-
editable: false,
122-
r#virtual: false,
121+
editable: None,
122+
r#virtual: None,
123123
})
124124
} else {
125125
ParsedUrl::Path(ParsedPathUrl {
@@ -187,7 +187,10 @@ impl ParsedUrl {
187187
pub fn is_editable(&self) -> bool {
188188
matches!(
189189
self,
190-
Self::Directory(ParsedDirectoryUrl { editable: true, .. })
190+
Self::Directory(ParsedDirectoryUrl {
191+
editable: Some(true),
192+
..
193+
})
191194
)
192195
}
193196
}
@@ -226,16 +229,18 @@ pub struct ParsedDirectoryUrl {
226229
pub url: DisplaySafeUrl,
227230
/// The absolute path to the distribution which we use for installing.
228231
pub install_path: Box<Path>,
229-
pub editable: bool,
230-
pub r#virtual: bool,
232+
/// Whether the project at the given URL should be installed in editable mode.
233+
pub editable: Option<bool>,
234+
/// Whether the project at the given URL should be treated as a virtual package.
235+
pub r#virtual: Option<bool>,
231236
}
232237

233238
impl ParsedDirectoryUrl {
234239
/// Construct a [`ParsedDirectoryUrl`] from a path requirement source.
235240
pub fn from_source(
236241
install_path: Box<Path>,
237-
editable: bool,
238-
r#virtual: bool,
242+
editable: Option<bool>,
243+
r#virtual: Option<bool>,
239244
url: DisplaySafeUrl,
240245
) -> Self {
241246
Self {
@@ -399,8 +404,8 @@ impl TryFrom<DisplaySafeUrl> for ParsedUrl {
399404
Ok(Self::Directory(ParsedDirectoryUrl {
400405
url,
401406
install_path: path.into_boxed_path(),
402-
editable: false,
403-
r#virtual: false,
407+
editable: None,
408+
r#virtual: None,
404409
}))
405410
} else {
406411
Ok(Self::Path(ParsedPathUrl {
@@ -445,7 +450,7 @@ impl From<&ParsedDirectoryUrl> for DirectUrl {
445450
Self::LocalDirectory {
446451
url: value.url.to_string(),
447452
dir_info: DirInfo {
448-
editable: value.editable.then_some(true),
453+
editable: value.editable,
449454
},
450455
subdirectory: None,
451456
}

crates/uv-requirements-txt/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2064,8 +2064,10 @@ mod test {
20642064
fragment: None,
20652065
},
20662066
install_path: "/foo/bar",
2067-
editable: true,
2068-
virtual: false,
2067+
editable: Some(
2068+
true,
2069+
),
2070+
virtual: None,
20692071
},
20702072
),
20712073
verbatim: VerbatimUrl {

crates/uv-requirements-txt/src/requirement.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl RequirementsTxtRequirement {
9090
version_or_url: Some(uv_pep508::VersionOrUrl::Url(VerbatimParsedUrl {
9191
verbatim: url.verbatim,
9292
parsed_url: ParsedUrl::Directory(ParsedDirectoryUrl {
93-
editable: true,
93+
editable: Some(true),
9494
..parsed_url
9595
}),
9696
})),
@@ -115,7 +115,7 @@ impl RequirementsTxtRequirement {
115115
url: VerbatimParsedUrl {
116116
verbatim: requirement.url.verbatim,
117117
parsed_url: ParsedUrl::Directory(ParsedDirectoryUrl {
118-
editable: true,
118+
editable: Some(true),
119119
..parsed_url
120120
}),
121121
},

0 commit comments

Comments
 (0)