Let RequirementSource::Path.editable be bool, not Option<bool> (#3693)

Small refactoring of the internal representation. This does not change
`tool.uv.sources`.
This commit is contained in:
konsti
2024-05-21 16:34:43 +02:00
committed by GitHub
parent f396c6c33e
commit 95af1db0bb
6 changed files with 12 additions and 13 deletions

View File

@@ -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,
@@ -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,

View File

@@ -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(
@@ -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 {

View File

@@ -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);

View File

@@ -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 => {
@@ -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.
@@ -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);

View File

@@ -184,7 +184,7 @@ impl RequirementsSpecification {
.partition_map(|requirement| {
if let RequirementSource::Path {
path,
editable: Some(true),
editable: true,
url,
} = requirement.source
{

View File

@@ -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(),
};