mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-03 15:24:36 +00:00
Remove URL clone in requirements-txt parser (#1020)
This commit is contained in:
parent
b3954f2449
commit
69d2791a43
2 changed files with 14 additions and 5 deletions
|
@ -37,7 +37,7 @@ impl VerbatimUrl {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a URL from a path.
|
/// Parse a URL from a path.
|
||||||
pub fn from_path(path: impl AsRef<str>, working_dir: impl AsRef<Path>, given: String) -> Self {
|
pub fn from_path(path: impl AsRef<str>, working_dir: impl AsRef<Path>) -> Self {
|
||||||
// Expand any environment variables.
|
// Expand any environment variables.
|
||||||
let path = PathBuf::from(expand_env_vars(path.as_ref(), false).as_ref());
|
let path = PathBuf::from(expand_env_vars(path.as_ref(), false).as_ref());
|
||||||
|
|
||||||
|
@ -54,9 +54,15 @@ impl VerbatimUrl {
|
||||||
// Convert to a URL.
|
// Convert to a URL.
|
||||||
let url = Url::from_file_path(path).expect("path is absolute");
|
let url = Url::from_file_path(path).expect("path is absolute");
|
||||||
|
|
||||||
|
Self { url, given: None }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Set the verbatim representation of the URL.
|
||||||
|
#[must_use]
|
||||||
|
pub fn with_given(self, given: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
url,
|
|
||||||
given: Some(given),
|
given: Some(given),
|
||||||
|
..self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -155,10 +155,10 @@ impl ParsedEditableRequirement {
|
||||||
if scheme == "file" {
|
if scheme == "file" {
|
||||||
if let Some(path) = path.strip_prefix("//") {
|
if let Some(path) = path.strip_prefix("//") {
|
||||||
// Ex) `file:///home/ferris/project/scripts/...`
|
// Ex) `file:///home/ferris/project/scripts/...`
|
||||||
VerbatimUrl::from_path(path, working_dir, given.clone())
|
VerbatimUrl::from_path(path, working_dir)
|
||||||
} else {
|
} else {
|
||||||
// Ex) `file:../editable/`
|
// Ex) `file:../editable/`
|
||||||
VerbatimUrl::from_path(path, working_dir, given.clone())
|
VerbatimUrl::from_path(path, working_dir)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Ex) `https://...`
|
// Ex) `https://...`
|
||||||
|
@ -168,7 +168,7 @@ impl ParsedEditableRequirement {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Ex) `../editable/`
|
// Ex) `../editable/`
|
||||||
VerbatimUrl::from_path(&given, working_dir, given.clone())
|
VerbatimUrl::from_path(&given, working_dir)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create a `PathBuf`.
|
// Create a `PathBuf`.
|
||||||
|
@ -176,6 +176,9 @@ impl ParsedEditableRequirement {
|
||||||
.to_file_path()
|
.to_file_path()
|
||||||
.map_err(|()| RequirementsTxtParserError::InvalidEditablePath(given.clone()))?;
|
.map_err(|()| RequirementsTxtParserError::InvalidEditablePath(given.clone()))?;
|
||||||
|
|
||||||
|
// Add the verbatim representation of the URL to the `VerbatimUrl`.
|
||||||
|
let url = url.with_given(given);
|
||||||
|
|
||||||
Ok(EditableRequirement { url, path })
|
Ok(EditableRequirement { url, path })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue