mirror of
https://github.com/astral-sh/uv.git
synced 2025-07-07 21:35:00 +00:00
uv-resolver: refactor Distribution::to_dist
This makes it clear that an actual `sdist` is only required when a distribution is from a registry. In all other cases, a source distribution is manufactured directly from the `source`.
This commit is contained in:
parent
840f61fc2b
commit
4899612619
1 changed files with 85 additions and 85 deletions
|
@ -686,91 +686,91 @@ impl Distribution {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(sdist) = &self.sdist {
|
match &self.id.source {
|
||||||
return match &self.id.source {
|
Source::Path(path) => {
|
||||||
Source::Path(path) => {
|
let path_dist = PathSourceDist {
|
||||||
let path_dist = PathSourceDist {
|
name: self.id.name.clone(),
|
||||||
name: self.id.name.clone(),
|
url: VerbatimUrl::from_path(workspace_root.join(path)).map_err(|err| {
|
||||||
url: VerbatimUrl::from_path(workspace_root.join(path)).map_err(|err| {
|
LockErrorKind::VerbatimUrl {
|
||||||
LockErrorKind::VerbatimUrl {
|
id: self.id.clone(),
|
||||||
id: self.id.clone(),
|
err,
|
||||||
err,
|
}
|
||||||
}
|
})?,
|
||||||
})?,
|
install_path: workspace_root.join(path),
|
||||||
install_path: workspace_root.join(path),
|
lock_path: path.clone(),
|
||||||
lock_path: path.clone(),
|
};
|
||||||
};
|
let source_dist = distribution_types::SourceDist::Path(path_dist);
|
||||||
let source_dist = distribution_types::SourceDist::Path(path_dist);
|
return Ok(Dist::Source(source_dist));
|
||||||
Ok(Dist::Source(source_dist))
|
}
|
||||||
}
|
Source::Directory(path) => {
|
||||||
Source::Directory(path) => {
|
let dir_dist = DirectorySourceDist {
|
||||||
let dir_dist = DirectorySourceDist {
|
name: self.id.name.clone(),
|
||||||
name: self.id.name.clone(),
|
url: VerbatimUrl::from_path(workspace_root.join(path)).map_err(|err| {
|
||||||
url: VerbatimUrl::from_path(workspace_root.join(path)).map_err(|err| {
|
LockErrorKind::VerbatimUrl {
|
||||||
LockErrorKind::VerbatimUrl {
|
id: self.id.clone(),
|
||||||
id: self.id.clone(),
|
err,
|
||||||
err,
|
}
|
||||||
}
|
})?,
|
||||||
})?,
|
install_path: workspace_root.join(path),
|
||||||
install_path: workspace_root.join(path),
|
lock_path: path.clone(),
|
||||||
lock_path: path.clone(),
|
editable: false,
|
||||||
editable: false,
|
};
|
||||||
};
|
let source_dist = distribution_types::SourceDist::Directory(dir_dist);
|
||||||
let source_dist = distribution_types::SourceDist::Directory(dir_dist);
|
return Ok(Dist::Source(source_dist));
|
||||||
Ok(Dist::Source(source_dist))
|
}
|
||||||
}
|
Source::Editable(path) => {
|
||||||
Source::Editable(path) => {
|
let dir_dist = DirectorySourceDist {
|
||||||
let dir_dist = DirectorySourceDist {
|
name: self.id.name.clone(),
|
||||||
name: self.id.name.clone(),
|
url: VerbatimUrl::from_path(workspace_root.join(path)).map_err(|err| {
|
||||||
url: VerbatimUrl::from_path(workspace_root.join(path)).map_err(|err| {
|
LockErrorKind::VerbatimUrl {
|
||||||
LockErrorKind::VerbatimUrl {
|
id: self.id.clone(),
|
||||||
id: self.id.clone(),
|
err,
|
||||||
err,
|
}
|
||||||
}
|
})?,
|
||||||
})?,
|
install_path: workspace_root.join(path),
|
||||||
install_path: workspace_root.join(path),
|
lock_path: path.clone(),
|
||||||
lock_path: path.clone(),
|
editable: true,
|
||||||
editable: true,
|
};
|
||||||
};
|
let source_dist = distribution_types::SourceDist::Directory(dir_dist);
|
||||||
let source_dist = distribution_types::SourceDist::Directory(dir_dist);
|
return Ok(Dist::Source(source_dist));
|
||||||
Ok(Dist::Source(source_dist))
|
}
|
||||||
}
|
Source::Git(url, git) => {
|
||||||
Source::Git(url, git) => {
|
// Reconstruct the `GitUrl` from the `GitSource`.
|
||||||
// Reconstruct the `GitUrl` from the `GitSource`.
|
let git_url =
|
||||||
let git_url =
|
uv_git::GitUrl::new(url.clone(), GitReference::from(git.kind.clone()))
|
||||||
uv_git::GitUrl::new(url.clone(), GitReference::from(git.kind.clone()))
|
.with_precise(git.precise);
|
||||||
.with_precise(git.precise);
|
|
||||||
|
|
||||||
// Reconstruct the PEP 508-compatible URL from the `GitSource`.
|
// Reconstruct the PEP 508-compatible URL from the `GitSource`.
|
||||||
let url = Url::from(ParsedGitUrl {
|
let url = Url::from(ParsedGitUrl {
|
||||||
url: git_url.clone(),
|
url: git_url.clone(),
|
||||||
subdirectory: git.subdirectory.as_ref().map(PathBuf::from),
|
subdirectory: git.subdirectory.as_ref().map(PathBuf::from),
|
||||||
});
|
});
|
||||||
|
|
||||||
let git_dist = GitSourceDist {
|
let git_dist = GitSourceDist {
|
||||||
name: self.id.name.clone(),
|
name: self.id.name.clone(),
|
||||||
url: VerbatimUrl::from_url(url),
|
url: VerbatimUrl::from_url(url),
|
||||||
git: Box::new(git_url),
|
git: Box::new(git_url),
|
||||||
subdirectory: git.subdirectory.as_ref().map(PathBuf::from),
|
subdirectory: git.subdirectory.as_ref().map(PathBuf::from),
|
||||||
};
|
};
|
||||||
let source_dist = distribution_types::SourceDist::Git(git_dist);
|
let source_dist = distribution_types::SourceDist::Git(git_dist);
|
||||||
Ok(Dist::Source(source_dist))
|
return Ok(Dist::Source(source_dist));
|
||||||
}
|
}
|
||||||
Source::Direct(url, direct) => {
|
Source::Direct(url, direct) => {
|
||||||
let url = Url::from(ParsedArchiveUrl {
|
let url = Url::from(ParsedArchiveUrl {
|
||||||
url: url.clone(),
|
url: url.clone(),
|
||||||
subdirectory: direct.subdirectory.as_ref().map(PathBuf::from),
|
subdirectory: direct.subdirectory.as_ref().map(PathBuf::from),
|
||||||
});
|
});
|
||||||
let direct_dist = DirectUrlSourceDist {
|
let direct_dist = DirectUrlSourceDist {
|
||||||
name: self.id.name.clone(),
|
name: self.id.name.clone(),
|
||||||
location: url.clone(),
|
location: url.clone(),
|
||||||
subdirectory: direct.subdirectory.as_ref().map(PathBuf::from),
|
subdirectory: direct.subdirectory.as_ref().map(PathBuf::from),
|
||||||
url: VerbatimUrl::from_url(url),
|
url: VerbatimUrl::from_url(url),
|
||||||
};
|
};
|
||||||
let source_dist = distribution_types::SourceDist::DirectUrl(direct_dist);
|
let source_dist = distribution_types::SourceDist::DirectUrl(direct_dist);
|
||||||
Ok(Dist::Source(source_dist))
|
return Ok(Dist::Source(source_dist));
|
||||||
}
|
}
|
||||||
Source::Registry(url) => {
|
Source::Registry(url) => {
|
||||||
|
if let Some(ref sdist) = self.sdist {
|
||||||
let file_url = sdist.url().ok_or_else(|| LockErrorKind::MissingUrl {
|
let file_url = sdist.url().ok_or_else(|| LockErrorKind::MissingUrl {
|
||||||
id: self.id.clone(),
|
id: self.id.clone(),
|
||||||
})?;
|
})?;
|
||||||
|
@ -799,9 +799,9 @@ impl Distribution {
|
||||||
wheels: vec![],
|
wheels: vec![],
|
||||||
};
|
};
|
||||||
let source_dist = distribution_types::SourceDist::Registry(reg_dist);
|
let source_dist = distribution_types::SourceDist::Registry(reg_dist);
|
||||||
Ok(Dist::Source(source_dist))
|
return Ok(Dist::Source(source_dist));
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Err(LockErrorKind::NeitherSourceDistNorWheel {
|
Err(LockErrorKind::NeitherSourceDistNorWheel {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue