Skip to content

Commit

Permalink
Merge pull request #1103 from messense/fix-sdist-include
Browse files Browse the repository at this point in the history
Change `sdist-include` paths to be relative to `pyproject.toml`
  • Loading branch information
messense authored Sep 13, 2022
2 parents 42c4953 + a273d11 commit ff20dfb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
3 changes: 2 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add library search paths in Cargo target directory to rpath in editable mode on Linux in [#1094](https://github.com/PyO3/maturin/pull/1094)
* Remove default manifest path for `maturin sdist` command in [#1097](https://github.com/PyO3/maturin/pull/1097)
* Fix sdist when `pyproject.toml` isn't in the same dir of `Cargo.toml` in [#1099](https://github.com/PyO3/maturin/pull/1099)
* Change readme and license paths in `pyproject.toml` to be relative to `pyproject.toml` in [#1100](https://github.com/PyO3/maturin/pull/1100)
* Change readme and license paths in `pyproject.toml` to be relative to `pyproject.toml` in [#1100](https://github.com/PyO3/maturin/pull/1100).
It's technically a **breaking change**, but previously it doesn't work properly.
* Add python source files specified in pyproject.toml to sdist in [#1102](https://github.com/PyO3/maturin/pull/1102)
* Change `sdist-include` paths to be relative to `pyproject.toml` in [#1103](https://github.com/PyO3/maturin/pull/1103)

## [0.13.2] - 2022-08-14

Expand Down
59 changes: 32 additions & 27 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ fn rewrite_cargo_toml(
fn add_crate_to_source_distribution(
writer: &mut SDistWriter,
pyproject_toml_path: impl AsRef<Path>,
pyproject: &PyProjectToml,
manifest_path: impl AsRef<Path>,
prefix: impl AsRef<Path>,
known_path_deps: &HashMap<String, PathBuf>,
Expand Down Expand Up @@ -202,27 +201,6 @@ fn add_crate_to_source_distribution(
PathBuf::from("pyproject.toml"),
pyproject_toml_path.to_path_buf(),
));
// Add readme, license and python source files
if let Some(project) = pyproject.project.as_ref() {
if let Some(pyproject_toml::ReadMe::RelativePath(readme)) = project.readme.as_ref()
{
target_source.push((PathBuf::from(readme), pyproject_dir.join(readme)));
}
if let Some(pyproject_toml::License {
file: Some(license),
text: None,
}) = project.license.as_ref()
{
target_source.push((PathBuf::from(license), pyproject_dir.join(license)));
}
if let Some(python_source) = pyproject.python_source() {
for entry in ignore::Walk::new(pyproject_dir.join(python_source)) {
let path = entry?.into_path();
let relative_path = path.strip_prefix(&pyproject_dir)?;
target_source.push((relative_path.to_path_buf(), path));
}
}
}
} else {
bail!(
"pyproject.toml was not included by `cargo package`. \
Expand Down Expand Up @@ -323,7 +301,6 @@ pub fn source_distribution(
add_crate_to_source_distribution(
&mut writer,
&pyproject_toml_path,
pyproject,
&path_dep,
&root_dir.join(LOCAL_DEPENDENCIES_FOLDER).join(name),
&known_path_deps,
Expand All @@ -340,7 +317,6 @@ pub fn source_distribution(
add_crate_to_source_distribution(
&mut writer,
&pyproject_toml_path,
pyproject,
&manifest_path,
&root_dir,
&known_path_deps,
Expand All @@ -356,15 +332,44 @@ pub fn source_distribution(
writer.add_file(&target, &cargo_lock_path)?;
}

// Add readme, license and python source files
let pyproject_dir = pyproject_toml_path.parent().unwrap();
if let Some(project) = pyproject.project.as_ref() {
if let Some(pyproject_toml::ReadMe::RelativePath(readme)) = project.readme.as_ref() {
writer.add_file(root_dir.join(readme), pyproject_dir.join(readme))?;
}
if let Some(pyproject_toml::License {
file: Some(license),
text: None,
}) = project.license.as_ref()
{
writer.add_file(root_dir.join(license), pyproject_dir.join(license))?;
}
if let Some(python_source) = pyproject.python_source() {
for entry in ignore::Walk::new(pyproject_dir.join(python_source)) {
let source = entry?.into_path();
let target = root_dir.join(source.strip_prefix(&pyproject_dir)?);
if source.is_dir() {
writer.add_directory(target)?;
} else {
writer.add_file(target, &source)?;
}
}
}
}
if let Some(include_targets) = pyproject.sdist_include() {
for pattern in include_targets {
println!("📦 Including files matching \"{}\"", pattern);
for source in glob::glob(&manifest_dir.join(pattern).to_string_lossy())
for source in glob::glob(&pyproject_dir.join(pattern).to_string_lossy())
.expect("No files found for pattern")
.filter_map(Result::ok)
{
let target = root_dir.join(&source.strip_prefix(manifest_dir)?);
writer.add_file(target, source)?;
let target = root_dir.join(&source.strip_prefix(pyproject_dir)?);
if source.is_dir() {
writer.add_directory(target)?;
} else {
writer.add_file(target, source)?;
}
}
}
}
Expand Down

0 comments on commit ff20dfb

Please sign in to comment.