From a48cde87beaaf372f74504d745918f5e06f1c74c Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 8 Aug 2022 20:45:47 +0800 Subject: [PATCH] Add `python-source` option to `[tool.maturin]` section of pyproject.toml --- Changelog.md | 1 + src/project_layout.rs | 10 ++++------ src/pyproject_toml.rs | 8 ++++++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Changelog.md b/Changelog.md index 6fd1814f7..0adb136c1 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Find python module next to `pyproject.toml` if `pyproject.toml` exists in [#1044](https://github.com/PyO3/maturin/pull/1044). It's technically a **breaking change**, but previously it doesn't work properly if the directory containing `pyproject.toml` isn't recognized as project root. +* Add `python-source` option to `[tool.maturin]` section of pyproject.toml in [#1046](https://github.com/PyO3/maturin/pull/1046) ## [0.13.1] - 2022-07-26 diff --git a/src/project_layout.rs b/src/project_layout.rs index 6a236a85b..12f442028 100644 --- a/src/project_layout.rs +++ b/src/project_layout.rs @@ -86,6 +86,9 @@ impl ProjectResolver { .filter(|name| name.contains('.')) .unwrap_or(&module_name); + let py_src = pyproject + .and_then(|x| x.python_source()) + .or_else(|| extra_metadata.python_source.as_ref().map(Path::new)); let data = pyproject .and_then(|x| x.data()) .or_else(|| extra_metadata.data.as_ref().map(Path::new)); @@ -94,12 +97,7 @@ impl ProjectResolver { } else { manifest_dir }; - let project_layout = ProjectLayout::determine( - project_root, - extension_name, - extra_metadata.python_source.as_deref(), - data, - )?; + let project_layout = ProjectLayout::determine(project_root, extension_name, py_src, data)?; Ok(Self { project_layout, cargo_toml_path: manifest_file, diff --git a/src/pyproject_toml.rs b/src/pyproject_toml.rs index 58a5dc5e6..524fa235b 100644 --- a/src/pyproject_toml.rs +++ b/src/pyproject_toml.rs @@ -25,6 +25,8 @@ pub struct ToolMaturin { skip_auditwheel: bool, #[serde(default)] strip: bool, + /// The directory with python module, contains `/__init__.py` + python_source: Option, /// Path to the wheel directory, defaults to `.data` data: Option, // Some customizable cargo options @@ -122,6 +124,12 @@ impl PyProjectToml { .unwrap_or_default() } + /// Returns the value of `[tool.maturin.python-source]` in pyproject.toml + pub fn python_source(&self) -> Option<&Path> { + self.maturin() + .and_then(|maturin| maturin.python_source.as_deref()) + } + /// Returns the value of `[tool.maturin.data]` in pyproject.toml pub fn data(&self) -> Option<&Path> { self.maturin().and_then(|maturin| maturin.data.as_deref())