Skip to content

Commit

Permalink
Merge pull request #1046 from messense/pyproject-toml-python-source
Browse files Browse the repository at this point in the history
Add `python-source` option to `[tool.maturin]` section of pyproject.toml
  • Loading branch information
messense authored Aug 8, 2022
2 parents 9eb5103 + a48cde8 commit d68b55d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
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

0 comments on commit d68b55d

Please sign in to comment.