Skip to content

Commit

Permalink
Respect extras and markers on virtual dev dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Aug 25, 2024
1 parent 2bfc450 commit 4c39996
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
19 changes: 14 additions & 5 deletions crates/uv-resolver/src/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,20 @@ impl Lock {
// dependencies in virtual workspaces).
for group in dev {
for dependency in project.group(group) {
let root = self
.find_by_name(dependency)
.expect("found too many packages matching root")
.expect("could not find root");
queue.push_back((root, None));
if dependency.marker.evaluate(marker_env, &[]) {
let root = self
.find_by_name(&dependency.name)
.expect("found too many packages matching root")
.expect("could not find root");

// Add the base package.
queue.push_back((root, None));

// Add any extras.
for extra in &dependency.extras {
queue.push_back((root, Some(extra)));
}
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions crates/uv-workspace/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hash::FxHashSet;
use tracing::{debug, trace, warn};

use pep508_rs::{MarkerTree, RequirementOrigin, VerbatimUrl};
use pypi_types::{Requirement, RequirementSource};
use pypi_types::{Requirement, RequirementSource, VerbatimParsedUrl};
use uv_fs::Simplified;
use uv_normalize::{GroupName, PackageName, DEV_DEPENDENCIES};
use uv_warnings::warn_user;
Expand Down Expand Up @@ -1309,7 +1309,10 @@ impl VirtualProject {
/// Returns dependencies that apply to the workspace root, but not any of its members. As such,
/// only returns a non-empty iterator for virtual workspaces, which can include dev dependencies
/// on the virtual root.
pub fn group(&self, name: &GroupName) -> impl Iterator<Item = &PackageName> {
pub fn group(
&self,
name: &GroupName,
) -> impl Iterator<Item = &pep508_rs::Requirement<VerbatimParsedUrl>> {
match self {
VirtualProject::Project(_) => {
// For non-virtual projects, dev dependencies are attached to the members.
Expand All @@ -1326,7 +1329,7 @@ impl VirtualProject {
.as_ref()
.and_then(|tool| tool.uv.as_ref())
.and_then(|uv| uv.dev_dependencies.as_ref())
.map(|dev| dev.iter().map(|req| &req.name))
.map(|dev| dev.iter())
.into_iter()
.flatten(),
)
Expand Down
21 changes: 15 additions & 6 deletions crates/uv/tests/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ fn virtual_workspace_dev_dependencies() -> Result<()> {
pyproject_toml.write_str(
r#"
[tool.uv]
dev-dependencies = ["anyio>3"]
dev-dependencies = ["anyio>3", "flask[dotenv]", "pytest ; sys_platform == ''"]
[tool.uv.workspace]
members = ["child"]
Expand Down Expand Up @@ -397,26 +397,35 @@ fn virtual_workspace_dev_dependencies() -> Result<()> {
----- stdout -----
----- stderr -----
Resolved 5 packages in [TIME]
Resolved 17 packages in [TIME]
Prepared 2 packages in [TIME]
Installed 2 packages in [TIME]
+ child==0.1.0 (from file://[TEMP_DIR]/child)
+ iniconfig==2.0.0
"###);

// Syncing without `--no-dev` should include `anyio`.
// Syncing without `--no-dev` should include `anyio`, `flask`, `python-dotenv`, and their
// dependencies, but not `pytest`.
uv_snapshot!(context.filters(), context.sync(), @r###"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 5 packages in [TIME]
Prepared 3 packages in [TIME]
Installed 3 packages in [TIME]
Resolved 17 packages in [TIME]
Prepared 11 packages in [TIME]
Installed 11 packages in [TIME]
+ anyio==4.3.0
+ blinker==1.7.0
+ click==8.1.7
+ flask==3.0.2
+ idna==3.6
+ itsdangerous==2.1.2
+ jinja2==3.1.3
+ markupsafe==2.1.5
+ python-dotenv==1.0.1
+ sniffio==1.3.1
+ werkzeug==3.0.1
"###);

Ok(())
Expand Down

0 comments on commit 4c39996

Please sign in to comment.