diff --git a/Changelog.md b/Changelog.md index f776a7583..9bc5c606e 100644 --- a/Changelog.md +++ b/Changelog.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Deprecate support for specifying python metadata in `Cargo.toml` in [#1048](https://github.com/PyO3/maturin/pull/1048). Please migrate to [PEP 621](https://peps.python.org/pep-0621/) instead. * Change `python-source` to be relative to the file specifies it in [#1049](https://github.com/PyO3/maturin/pull/1049) +* Change `data` to be relative to the file specifies it in [#1051](https://github.com/PyO3/maturin/pull/1051) ## [0.13.1] - 2022-07-26 diff --git a/src/project_layout.rs b/src/project_layout.rs index d05519a8f..bf90223d4 100644 --- a/src/project_layout.rs +++ b/src/project_layout.rs @@ -99,9 +99,23 @@ impl ProjectResolver { None => project_root.to_path_buf(), }, }; - let data = pyproject - .and_then(|x| x.data()) - .or_else(|| extra_metadata.data.as_ref().map(Path::new)); + let data = match pyproject.and_then(|x| x.data()) { + Some(data) => { + if data.is_absolute() { + Some(data.to_path_buf()) + } else { + Some(project_root.join(data)) + } + } + None => extra_metadata.data.as_ref().map(|data| { + let data = Path::new(data); + if data.is_absolute() { + data.to_path_buf() + } else { + manifest_dir.join(data) + } + }), + }; let project_layout = ProjectLayout::determine(project_root, extension_name, py_root, data)?; Ok(Self { project_layout, @@ -159,7 +173,7 @@ impl ProjectLayout { project_root: impl AsRef, module_name: &str, python_root: PathBuf, - data: Option>, + data: Option, ) -> Result { // A dot in the module name means the extension module goes into the module folder specified by the path let parts: Vec<&str> = module_name.split('.').collect(); @@ -181,11 +195,6 @@ impl ProjectLayout { }; let data = if let Some(data) = data { - let data = if data.as_ref().is_absolute() { - data.as_ref().to_path_buf() - } else { - project_root.join(data) - }; if !data.is_dir() { bail!("No such data directory {}", data.display()); }