Support locking relative paths (#4205)

By splitting `path` into a lockable, relative (or absolute) and an
absolute installable path and by splitting between urls and paths by
dist type, we can store relative paths in the lockfile.
This commit is contained in:
konsti 2024-06-11 13:58:03 +02:00 committed by GitHub
parent 33cf47182f
commit 44833801b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 533 additions and 364 deletions

View file

@ -59,8 +59,9 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
) -> Result<Self, Self::Err> {
let verbatim = VerbatimUrl::parse_path(&path, &working_dir)?;
let parsed_path_url = ParsedPathUrl {
path: verbatim.as_path()?,
url: verbatim.to_url(),
install_path: verbatim.as_path()?,
lock_path: path.as_ref().to_path_buf(),
editable: false,
};
Ok(Self {
@ -72,8 +73,9 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
fn parse_absolute_path(path: impl AsRef<Path>) -> Result<Self, Self::Err> {
let verbatim = VerbatimUrl::parse_absolute_path(&path)?;
let parsed_path_url = ParsedPathUrl {
path: verbatim.as_path()?,
url: verbatim.to_url(),
install_path: verbatim.as_path()?,
lock_path: path.as_ref().to_path_buf(),
editable: false,
};
Ok(Self {
@ -171,16 +173,27 @@ impl ParsedUrl {
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Hash, Ord)]
pub struct ParsedPathUrl {
pub url: Url,
pub path: PathBuf,
/// The resolved, absolute path to the distribution which we use for installing.
pub install_path: PathBuf,
/// The absolute path or path relative to the workspace root pointing to the distribution
/// which we use for locking. Unlike `given` on the verbatim URL all environment variables
/// are resolved, and unlike the install path, we did not yet join it on the base directory.
pub lock_path: PathBuf,
pub editable: bool,
}
impl ParsedPathUrl {
/// Construct a [`ParsedPathUrl`] from a path requirement source.
pub fn from_source(path: PathBuf, editable: bool, url: Url) -> Self {
pub fn from_source(
install_path: PathBuf,
lock_path: PathBuf,
editable: bool,
url: Url,
) -> Self {
Self {
url,
path,
install_path,
lock_path,
editable,
}
}
@ -311,7 +324,8 @@ impl TryFrom<Url> for ParsedUrl {
.map_err(|()| ParsedUrlError::InvalidFileUrl(url.clone()))?;
Ok(Self::Path(ParsedPathUrl {
url,
path,
install_path: path.clone(),
lock_path: path,
editable: false,
}))
} else {

View file

@ -170,7 +170,12 @@ pub enum RequirementSource {
/// `.tag.gz` file) or a source tree (a directory with a pyproject.toml in, or a legacy
/// source distribution with only a setup.py but non pyproject.toml in it).
Path {
path: PathBuf,
/// The resolved, absolute path to the distribution which we use for installing.
install_path: PathBuf,
/// The absolute path or path relative to the workspace root pointing to the distribution
/// which we use for locking. Unlike `given` on the verbatim URL all environment variables
/// are resolved, and unlike the install path, we did not yet join it on the base directory.
lock_path: PathBuf,
/// For a source tree (a directory), whether to install as an editable.
editable: bool,
/// The PEP 508 style URL in the format
@ -185,7 +190,8 @@ impl RequirementSource {
pub fn from_parsed_url(parsed_url: ParsedUrl, url: VerbatimUrl) -> Self {
match parsed_url {
ParsedUrl::Path(local_file) => RequirementSource::Path {
path: local_file.path,
install_path: local_file.install_path.clone(),
lock_path: local_file.lock_path.clone(),
url,
editable: local_file.editable,
},