Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions crates/uv-requirements-txt/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,13 @@ impl RequirementsTxt {
let mut s = Scanner::new(content);

let mut data = Self::default();
while let Some(statement) = parse_entry(&mut s, content, working_dir, requirements_txt)? {
while let Some(statement) = parse_entry(
&mut s,
content,
working_dir,
requirements_dir,
requirements_txt,
)? {
match statement {
RequirementsTxtStatement::Requirements {
filename,
Expand Down Expand Up @@ -682,6 +688,7 @@ fn parse_entry(
s: &mut Scanner,
content: &str,
working_dir: &Path,
requirements_dir: &Path,
requirements_txt: &Path,
) -> Result<Option<RequirementsTxtStatement>, RequirementsTxtParserError> {
// Eat all preceding whitespace, this may run us to the end of file
Expand Down Expand Up @@ -826,7 +833,7 @@ fn parse_entry(
.map(Cow::Owned)
.unwrap_or(Cow::Borrowed(given));
let expanded = expand_env_vars(given.as_ref());
let url = if let Some(path) = std::path::absolute(expanded.as_ref())
let url = if let Some(path) = std::path::absolute(requirements_dir.join(expanded.as_ref()))
.ok()
.filter(|path| path.exists())
{
Expand Down
32 changes: 32 additions & 0 deletions crates/uv/tests/pip_install/pip_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7511,6 +7511,38 @@ fn find_links_local_html() -> Result<()> {
Ok(())
}

/// Install from a `--find-links` directory relative to the containing requirements file.
#[test]
fn find_links_relative_to_requirements_file() -> Result<()> {
let context = uv_test::test_context!("3.12");
let requirements_dir = context.temp_dir.child("requirements");
let links_dir = requirements_dir.child("links");
links_dir.create_dir_all()?;
fs::copy(
context
.workspace_root
.join("test/links/ok-1.0.0-py3-none-any.whl"),
links_dir.child("ok-1.0.0-py3-none-any.whl").path(),
)?;
requirements_dir
.child("requirements.txt")
.write_str("--no-index\n--find-links ./links\nok==1.0.0\n")?;

uv_snapshot!(context.filters(), context.pip_install()
.arg("-r")
.arg("requirements/requirements.txt"), @"
exit_code: 0 (success)
----- stderr -----
Resolved 1 package in [TIME]
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ ok==1.0.0
"
);

Ok(())
}

/// Install the latest version across multiple `--find-links` directories.
#[test]
fn find_links_multiple() -> Result<()> {
Expand Down
Loading