Skip to content

Commit

Permalink
(wip) Support path-based dependencies in virtual projects with uv ena…
Browse files Browse the repository at this point in the history
…bled
  • Loading branch information
cnpryer committed Mar 5, 2024
1 parent 2111778 commit 47d904f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
38 changes: 22 additions & 16 deletions rye/src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,23 +468,29 @@ fn resolve_requirements_with_uv(
if let Ok(dt) = env::var("__RYE_UV_EXCLUDE_NEWER") {
cmd.arg("--exclude-newer").arg(dt);
}
let sources = ExpandedSources::from_sources(&pyproject_toml.sources()?)?;
sources.add_as_pip_args(&mut cmd);
let mut child = cmd
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
let child_stdin = child.stdin.as_mut().unwrap();
writeln!(child_stdin, "{}", req)?;

let rv = child.wait_with_output()?;
if !rv.status.success() {
let log = String::from_utf8_lossy(&rv.stderr);
bail!("failed to resolve packages:\n{}", log);
}

let mut new_req: Requirement = String::from_utf8_lossy(&rv.stdout).parse()?;
// we can skip the `uv compile` step for dependencies with direct references (URLs/paths)
let mut new_req = if matches!(req.version_or_url, Some(VersionOrUrl::Url(_))) {
req.clone()
} else {
let sources = ExpandedSources::from_sources(&pyproject_toml.sources()?)?;
sources.add_as_pip_args(&mut cmd);
let mut child = cmd
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
let child_stdin = child.stdin.as_mut().unwrap();
writeln!(child_stdin, "{}", req)?;

let rv = child.wait_with_output()?;
if !rv.status.success() {
let log = String::from_utf8_lossy(&rv.stderr);
bail!("failed to resolve packages:\n{}", log);
}
String::from_utf8_lossy(&rv.stdout).parse()?
};

if let Some(ref mut version_or_url) = new_req.version_or_url {
if let VersionOrUrl::VersionSpecifier(ref mut specs) = version_or_url {
*version_or_url = VersionOrUrl::VersionSpecifier(VersionSpecifiers::from_iter({
Expand Down
28 changes: 28 additions & 0 deletions rye/tests/test_add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,31 @@ fn test_add_flask_wrong_venv_exported() {
"###);
fs::remove_dir_all(&fake_venv).unwrap();
}

#[test]
fn test_add_from_path() {
let space = Space::new();
space.init("my-project");
let fake_venv = space.project_path().join("fake-venv");
fs::create_dir_all(&fake_venv).unwrap();

// TODO(cnpryer)
rye_cmd_snapshot!(space.rye_cmd().arg("add").arg("fixture").arg("--path").arg("TODO").env("VIRTUAL_ENV", fake_venv.as_os_str()), @r###"
"###);
fs::remove_dir_all(&fake_venv).unwrap();
}

#[test]
fn test_add_from_url() {
let space = Space::new();
space.init("my-project");
let fake_venv = space.project_path().join("fake-venv");
fs::create_dir_all(&fake_venv).unwrap();

// TODO(cnpryer)
rye_cmd_snapshot!(space.rye_cmd().arg("add").arg("fixture").arg("--path").arg("TODO").env("VIRTUAL_ENV", fake_venv.as_os_str()), @r###"
"###);
fs::remove_dir_all(&fake_venv).unwrap();
}

0 comments on commit 47d904f

Please sign in to comment.