mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-03 13:14:41 +00:00
Discard fragments when parsing unnamed URLs (#3940)
## Summary Closes https://github.com/astral-sh/uv/issues/3934.
This commit is contained in:
parent
72b1642232
commit
8c11f99fdf
5 changed files with 67 additions and 6 deletions
|
|
@ -155,6 +155,13 @@ impl VerbatimUrl {
|
||||||
pub fn to_url(&self) -> Url {
|
pub fn to_url(&self) -> Url {
|
||||||
self.url.clone()
|
self.url.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return the underlying [`Path`], if the URL is a file URL.
|
||||||
|
pub fn as_path(&self) -> Result<PathBuf, VerbatimUrlError> {
|
||||||
|
self.url
|
||||||
|
.to_file_path()
|
||||||
|
.map_err(|_| VerbatimUrlError::UrlConversion(self.url.to_file_path().unwrap()))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This impl is written out because the `derive` doesn't seem to get it right.
|
// This impl is written out because the `derive` doesn't seem to get it right.
|
||||||
|
|
|
||||||
|
|
@ -59,8 +59,8 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
|
||||||
) -> Result<Self, Self::Err> {
|
) -> Result<Self, Self::Err> {
|
||||||
let verbatim = VerbatimUrl::parse_path(&path, &working_dir)?;
|
let verbatim = VerbatimUrl::parse_path(&path, &working_dir)?;
|
||||||
let parsed_path_url = ParsedPathUrl {
|
let parsed_path_url = ParsedPathUrl {
|
||||||
|
path: verbatim.as_path()?,
|
||||||
url: verbatim.to_url(),
|
url: verbatim.to_url(),
|
||||||
path: working_dir.as_ref().join(path),
|
|
||||||
editable: false,
|
editable: false,
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
@ -72,8 +72,8 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
|
||||||
fn parse_absolute_path(path: impl AsRef<Path>) -> Result<Self, Self::Err> {
|
fn parse_absolute_path(path: impl AsRef<Path>) -> Result<Self, Self::Err> {
|
||||||
let verbatim = VerbatimUrl::parse_absolute_path(&path)?;
|
let verbatim = VerbatimUrl::parse_absolute_path(&path)?;
|
||||||
let parsed_path_url = ParsedPathUrl {
|
let parsed_path_url = ParsedPathUrl {
|
||||||
|
path: verbatim.as_path()?,
|
||||||
url: verbatim.to_url(),
|
url: verbatim.to_url(),
|
||||||
path: path.as_ref().to_path_buf(),
|
|
||||||
editable: false,
|
editable: false,
|
||||||
};
|
};
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ RequirementsTxt {
|
||||||
query: None,
|
query: None,
|
||||||
fragment: None,
|
fragment: None,
|
||||||
},
|
},
|
||||||
path: "<REQUIREMENTS_DIR>/./scripts/packages/black_editable",
|
path: "<REQUIREMENTS_DIR>/scripts/packages/black_editable",
|
||||||
editable: false,
|
editable: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
@ -70,7 +70,7 @@ RequirementsTxt {
|
||||||
query: None,
|
query: None,
|
||||||
fragment: None,
|
fragment: None,
|
||||||
},
|
},
|
||||||
path: "<REQUIREMENTS_DIR>/./scripts/packages/black_editable",
|
path: "<REQUIREMENTS_DIR>/scripts/packages/black_editable",
|
||||||
editable: false,
|
editable: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ RequirementsTxt {
|
||||||
query: None,
|
query: None,
|
||||||
fragment: None,
|
fragment: None,
|
||||||
},
|
},
|
||||||
path: "<REQUIREMENTS_DIR>/./scripts/packages/black_editable",
|
path: "<REQUIREMENTS_DIR>/scripts/packages/black_editable",
|
||||||
editable: false,
|
editable: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
@ -70,7 +70,7 @@ RequirementsTxt {
|
||||||
query: None,
|
query: None,
|
||||||
fragment: None,
|
fragment: None,
|
||||||
},
|
},
|
||||||
path: "<REQUIREMENTS_DIR>/./scripts/packages/black_editable",
|
path: "<REQUIREMENTS_DIR>/scripts/packages/black_editable",
|
||||||
editable: false,
|
editable: false,
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -3442,6 +3442,60 @@ fn deduplicate_editable() -> Result<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn strip_fragment_unnamed() -> Result<()> {
|
||||||
|
let context = TestContext::new("3.12");
|
||||||
|
let requirements_in = context.temp_dir.child("requirements.in");
|
||||||
|
requirements_in.write_str(indoc! {r"
|
||||||
|
../../scripts/packages/black_editable#egg=black
|
||||||
|
"
|
||||||
|
})?;
|
||||||
|
|
||||||
|
uv_snapshot!(context.filters(), context.compile()
|
||||||
|
.arg(requirements_in.path())
|
||||||
|
.current_dir(current_dir()?), @r###"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
# This file was autogenerated by uv via the following command:
|
||||||
|
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z [TEMP_DIR]/requirements.in
|
||||||
|
../../scripts/packages/black_editable#egg=black
|
||||||
|
# via -r [TEMP_DIR]/requirements.in
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
Resolved 1 package in [TIME]
|
||||||
|
"###);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn strip_fragment_named() -> Result<()> {
|
||||||
|
let context = TestContext::new("3.12");
|
||||||
|
let requirements_in = context.temp_dir.child("requirements.in");
|
||||||
|
requirements_in.write_str(indoc! {r"
|
||||||
|
black @ ../../scripts/packages/black_editable#egg=black
|
||||||
|
"
|
||||||
|
})?;
|
||||||
|
|
||||||
|
uv_snapshot!(context.filters(), context.compile()
|
||||||
|
.arg(requirements_in.path())
|
||||||
|
.current_dir(current_dir()?), @r###"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
# This file was autogenerated by uv via the following command:
|
||||||
|
# uv pip compile --cache-dir [CACHE_DIR] --exclude-newer 2024-03-25T00:00:00Z [TEMP_DIR]/requirements.in
|
||||||
|
../../scripts/packages/black_editable#egg=black
|
||||||
|
# via -r [TEMP_DIR]/requirements.in
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
Resolved 1 package in [TIME]
|
||||||
|
"###);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn recursive_extras_direct_url() -> Result<()> {
|
fn recursive_extras_direct_url() -> Result<()> {
|
||||||
let context = TestContext::new("3.12");
|
let context = TestContext::new("3.12");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue