From efcaf827360637dff341f6e16d93e6339a16787f Mon Sep 17 00:00:00 2001 From: messense Date: Sun, 30 May 2021 22:20:40 +0800 Subject: [PATCH] Handle existing environment markers in optional-dependencies --- src/metadata.rs | 19 +++++++++++++++++-- test-crates/pyo3-pure/pyproject.toml | 7 +++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/metadata.rs b/src/metadata.rs index 5f243d2cb..aecc1cd2f 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -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); } } } @@ -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'" + ] + ) } } diff --git a/test-crates/pyo3-pure/pyproject.toml b/test-crates/pyo3-pure/pyproject.toml index f960f79e8..ff0a1b050 100644 --- a/test-crates/pyo3-pure/pyproject.toml +++ b/test-crates/pyo3-pure/pyproject.toml @@ -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"