Skip to content

Commit

Permalink
Merge pull request #1051 from messense/data-relative
Browse files Browse the repository at this point in the history
Change `data` to be relative to the file specifies it
  • Loading branch information
messense authored Aug 9, 2022
2 parents a4440dc + 7223e3e commit c4d2e75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
27 changes: 18 additions & 9 deletions src/project_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -159,7 +173,7 @@ impl ProjectLayout {
project_root: impl AsRef<Path>,
module_name: &str,
python_root: PathBuf,
data: Option<impl AsRef<Path>>,
data: Option<PathBuf>,
) -> Result<ProjectLayout> {
// 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();
Expand All @@ -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());
}
Expand Down

0 comments on commit c4d2e75

Please sign in to comment.