Skip to content

Commit

Permalink
Let RequirementSource::Path.editable be bool, not Option<bool> (a…
Browse files Browse the repository at this point in the history
…stral-sh#3693)

Small refactoring of the internal representation. This does not change
`tool.uv.sources`.
  • Loading branch information
konstin authored May 21, 2024
1 parent f396c6c commit 95af1db
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions crates/distribution-types/src/requirement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub enum RequirementSource {
Path {
path: PathBuf,
/// For a source tree (a directory), whether to install as an editable.
editable: Option<bool>,
editable: bool,
/// The PEP 508 style URL in the format
/// `file:///<path>#subdirectory=<subdirectory>`.
url: VerbatimUrl,
Expand All @@ -189,7 +189,7 @@ impl RequirementSource {
ParsedUrl::Path(local_file) => RequirementSource::Path {
path: local_file.path,
url,
editable: None,
editable: false,
},
ParsedUrl::Git(git) => RequirementSource::Git {
url,
Expand Down
6 changes: 3 additions & 3 deletions crates/distribution-types/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl From<&ResolvedDist> for Requirement {
Dist::Built(BuiltDist::Path(wheel)) => RequirementSource::Path {
path: wheel.path.clone(),
url: wheel.url.clone(),
editable: None,
editable: false,
},
Dist::Source(SourceDist::Registry(sdist)) => RequirementSource::Registry {
specifier: pep440_rs::VersionSpecifiers::from(
Expand All @@ -121,12 +121,12 @@ impl From<&ResolvedDist> for Requirement {
Dist::Source(SourceDist::Path(sdist)) => RequirementSource::Path {
path: sdist.path.clone(),
url: sdist.url.clone(),
editable: None,
editable: false,
},
Dist::Source(SourceDist::Directory(sdist)) => RequirementSource::Path {
path: sdist.path.clone(),
url: sdist.url.clone(),
editable: Some(sdist.editable),
editable: sdist.editable,
},
},
ResolvedDist::Installed(dist) => RequirementSource::Registry {
Expand Down
5 changes: 2 additions & 3 deletions crates/uv-installer/src/satisfies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,10 @@ impl RequirementSatisfaction {
return Ok(Self::Mismatch);
};

if requested_editable.unwrap_or_default() != installed_editable.unwrap_or_default()
{
if *requested_editable != installed_editable.unwrap_or_default() {
trace!(
"Editable mismatch: {:?} vs. {:?}",
requested_editable.unwrap_or_default(),
*requested_editable,
installed_editable.unwrap_or_default()
);
return Ok(Self::Mismatch);
Expand Down
6 changes: 3 additions & 3 deletions crates/uv-requirements/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ pub(crate) fn lower_requirement(
if matches!(requirement.version_or_url, Some(VersionOrUrl::Url(_))) {
return Err(LoweringError::ConflictingUrls);
}
path_source(path, project_dir, editable)?
path_source(path, project_dir, editable.unwrap_or(false))?
}
Source::Registry { index } => match requirement.version_or_url {
None => {
Expand Down Expand Up @@ -529,7 +529,7 @@ pub(crate) fn lower_requirement(
.get(&requirement.name)
.ok_or(LoweringError::UndeclaredWorkspacePackage)?
.clone();
path_source(path, project_dir, editable)?
path_source(path, project_dir, editable.unwrap_or(true))?
}
Source::CatchAll { .. } => {
// Emit a dedicated error message, which is an improvement over Serde's default error.
Expand All @@ -549,7 +549,7 @@ pub(crate) fn lower_requirement(
fn path_source(
path: String,
project_dir: &Path,
editable: Option<bool>,
editable: bool,
) -> Result<RequirementSource, LoweringError> {
let url = VerbatimUrl::parse_path(&path, project_dir).with_given(path.clone());
let path_buf = PathBuf::from(&path);
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-requirements/src/specification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl RequirementsSpecification {
.partition_map(|requirement| {
if let RequirementSource::Path {
path,
editable: Some(true),
editable: true,
url,
} = requirement.source
{
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-resolver/src/resolver/urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Urls {
parsed_url: ParsedUrl::Path(ParsedPathUrl {
url: url.to_url(),
path: path.clone(),
editable: (*editable).unwrap_or_default(),
editable: *editable,
}),
verbatim: url.clone(),
};
Expand Down

0 comments on commit 95af1db

Please sign in to comment.