Skip to content

Commit

Permalink
Make sure pyproject.toml is included in the source distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
konstin committed Jun 25, 2019
1 parent 027c33e commit dd712c7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ requires = ["pyo3-pack", "toml"]
build-backend = "pyo3_pack"
```

If a `pyproject.toml` with a `[build-system]` entry is present, pyo3-pack will build a source distribution (sdist) of your package, unless `--no-sdist` is specified.
If a `pyproject.toml` with a `[build-system]` entry is present, pyo3-pack will build a source distribution (sdist) of your package, unless `--no-sdist` is specified. The source distribution will contain the same files as `cargo package`.

You can then e.g. install your package with `pip install .`. With `pip install . -v` you can see the output of cargo and pyo3-pack.

Expand Down
24 changes: 19 additions & 5 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,26 @@ pub fn source_distribution(
.map(Path::new)
.collect();

let target_source: Vec<(&Path, &Path)> = file_list
.iter()
.map(|relative_to_cwd| {
let relative_to_project_root = relative_to_cwd
.strip_prefix(manifest_path.as_ref().parent().unwrap())
.unwrap_or(relative_to_cwd);
(relative_to_project_root, *relative_to_cwd)
})
.collect();

if !target_source.iter().any(|(target, _)| target == &Path::new("pyproject.toml")) {
bail!(
"pyproject.toml was not included by `cargo package`. \
Please make sure pyproject.toml is not excluded or build with `--no-sdist`"
)
}

let mut writer = SDistWriter::new(wheel_dir, &metadata21)?;
for relative_to_cwd in file_list {
let relative_to_project_root = relative_to_cwd
.strip_prefix(manifest_path.as_ref().parent().unwrap())
.unwrap_or(relative_to_cwd);
writer.add_file(relative_to_project_root, relative_to_cwd)?;
for (target, source) in target_source {
writer.add_file(target, source)?;
}

writer.add_bytes("PKG-INFO", metadata21.to_file_contents().as_bytes())?;
Expand Down

0 comments on commit dd712c7

Please sign in to comment.