Skip to content

Commit

Permalink
Handle existing environment markers in optional-dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed May 31, 2021
1 parent 099f6bd commit efcaf82
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,15 @@ impl Metadata21 {
for (extra, deps) in dependencies {
self.provides_extra.push(extra.clone());
for dep in deps {
self.requires_dist
.push(format!("{}; extra == '{}'", dep, extra));
let dist = if let Some((dep, marker)) = dep.split_once(';') {
// optional dependency already has environment markers
let new_marker =
format!("({}) and extra == '{}'", marker.trim(), extra);
format!("{}; {}", dep, new_marker)
} else {
format!("{}; extra == '{}'", dep, extra)
};
self.requires_dist.push(dist);
}
}
}
Expand Down Expand Up @@ -711,5 +718,13 @@ mod test {
metadata.gui_scripts["get_42"],
"pyo3_pure:DummyClass.get_42"
);
assert_eq!(metadata.provides_extra, &["test"]);
assert_eq!(
metadata.requires_dist,
&[
"attrs; extra == 'test'",
"boltons; (sys_platform == 'win32') and extra == 'test'"
]
)
}
}
7 changes: 7 additions & 0 deletions test-crates/pyo3-pure/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,12 @@ readme = "Readme.md"
maintainers = [
{name = "messense", email = "messense@icloud.com"}
]

[project.optional-dependencies]
test = [
"attrs",
"boltons; sys_platform == 'win32'"
]

[project.gui-scripts]
get_42 = "pyo3_pure:DummyClass.get_42"

0 comments on commit efcaf82

Please sign in to comment.