Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add python-source option to [tool.maturin] section of pyproject.toml #1046

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 4 additions & 6 deletions src/project_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/pyproject_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct ToolMaturin {
skip_auditwheel: bool,
#[serde(default)]
strip: bool,
/// The directory with python module, contains `<module_name>/__init__.py`
python_source: Option<PathBuf>,
/// Path to the wheel directory, defaults to `<module_name>.data`
data: Option<PathBuf>,
// Some customizable cargo options
Expand Down Expand Up @@ -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())
Expand Down