Skip to content

Commit 84f7f87

Browse files
committed
Respect [tool.maturin] settings of pyproject.toml
1 parent a37c450 commit 84f7f87

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/build_options.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::python_interpreter::InterpreterKind;
55
use crate::BuildContext;
66
use crate::CargoToml;
77
use crate::Metadata21;
8+
use crate::PyProjectToml;
89
use crate::PythonInterpreter;
910
use crate::Target;
1011
use anyhow::{bail, format_err, Context, Result};
@@ -130,6 +131,11 @@ impl BuildOptions {
130131

131132
let cargo_toml = CargoToml::from_path(&manifest_file)?;
132133
let manifest_dir = manifest_file.parent().unwrap();
134+
let pyproject: Option<PyProjectToml> = if manifest_dir.join("pyproject.toml").is_file() {
135+
Some(PyProjectToml::new(manifest_dir).context("pyproject.toml is invalid")?)
136+
} else {
137+
None
138+
};
133139
let metadata21 = Metadata21::from_cargo_toml(&cargo_toml, &manifest_dir)
134140
.context("Failed to parse Cargo.toml into python metadata")?;
135141
let extra_metadata = cargo_toml.remaining_core_metadata();
@@ -183,7 +189,12 @@ impl BuildOptions {
183189
}
184190
};
185191

186-
let bridge = find_bridge(&cargo_metadata, self.bindings.as_deref())?;
192+
let bridge = find_bridge(
193+
&cargo_metadata,
194+
self.bindings
195+
.as_deref()
196+
.or_else(|| pyproject.as_ref().and_then(|x| x.bindings())),
197+
)?;
187198

188199
if bridge != BridgeModel::Bin && module_name.contains('-') {
189200
bail!(

src/pyproject_toml.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct Tool {
1616
#[serde(rename_all = "kebab-case")]
1717
pub struct ToolMaturin {
1818
sdist_include: Option<Vec<String>>,
19+
bindings: Option<String>,
1920
}
2021

2122
/// A pyproject.toml as specified in PEP 517
@@ -57,11 +58,16 @@ impl PyProjectToml {
5758
Ok(pyproject)
5859
}
5960

60-
/// Returns the value of `[maturin.sdist-include]` in pyproject.toml
61+
/// Returns the value of `[tool.maturin.sdist-include]` in pyproject.toml
6162
pub fn sdist_include(&self) -> Option<&Vec<String>> {
6263
self.tool.as_ref()?.maturin.as_ref()?.sdist_include.as_ref()
6364
}
6465

66+
/// Returns the value of `[tool.maturin.bindings]` in pyproject.toml
67+
pub fn bindings(&self) -> Option<&str> {
68+
self.tool.as_ref()?.maturin.as_ref()?.bindings.as_deref()
69+
}
70+
6571
/// Having a pyproject.toml without a version constraint is a bad idea
6672
/// because at some point we'll have to do breaking changes and then source
6773
/// distributions would break

0 commit comments

Comments
 (0)