Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove workspace.members in Cargo.toml from sdist if there isn't any path dependency #1227

Merged
merged 2 commits into from
Oct 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ version = "0.14.0-beta.3"
description = "Build and publish crates with pyo3, rust-cpython and cffi bindings as well as rust binaries as python packages"
exclude = ["test-crates/**/*", "sysconfig/*", "test-data/*", "ci/*", "tests/*", "guide/*", ".github/*"]
homepage = "https://github.com/pyo3/maturin"
readme = "Readme.md"
readme = "README.md"
repository = "https://github.com/pyo3/maturin"
license = "MIT OR Apache-2.0"
keywords = ["python", "cffi", "packaging", "pypi", "pyo3"]
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Add `--src` option to generate src layout for mixed Python/Rust projects in [#1189](https://github.com/PyO3/maturin/pull/1189)
* Add Python metadata support for `license-file` field of `Cargo.toml` in [#1195](https://github.com/PyO3/maturin/pull/1195)
* Upgrade to clap 4.0 in [#1197](https://github.com/PyO3/maturin/pull/1197). This bumps MSRV to 1.61.0.
* Remove `workspace.members` in `Cargo.toml` from sdist if there isn't any path dependency in #[1227](https://github.com/PyO3/maturin/pull/1227)

## [0.13.7] - 2022-10-29

2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include Cargo.toml Cargo.lock
include Readme.md
include README.md
include license-apache license-mit
recursive-include src *.rs *.py
recursive-include src/auditwheel *.json
6 changes: 3 additions & 3 deletions Readme.md → README.md
Original file line number Diff line number Diff line change
@@ -103,7 +103,7 @@ my-project
│   ├── __init__.py
│   └── bar.py
├── pyproject.toml
├── Readme.md
├── README.md
└── src
   └── lib.rs
```
@@ -135,7 +135,7 @@ my-project
│ ├── __init__.py
│ └── bar.py
├── pyproject.toml
├── Readme.md
├── README.md
└── src
   └── lib.rs
```
@@ -156,7 +156,7 @@ my-project
│   ├── __init__.py
│   ├── bar.py
│   └── my_project.cpython-36m-x86_64-linux-gnu.so
├── Readme.md
├── README.md
└── src
   └── lib.rs
```
2 changes: 1 addition & 1 deletion ci/build_deb.sh
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ install -Dm755 "target/$TARGET/release/$BINARY_NAME" "$tempdir/usr/bin/$BINARY_N
strip "$tempdir/usr/bin/$BINARY_NAME"

# readme and license
install -Dm644 Readme.md "$tempdir/usr/share/doc/$BINARY_NAME/Readme.md"
install -Dm644 README.md "$tempdir/usr/share/doc/$BINARY_NAME/README.md"
install -Dm644 license-mit "$tempdir/usr/share/doc/$BINARY_NAME/license-mit"
install -Dm644 license-apache "$tempdir/usr/share/doc/$BINARY_NAME/license-apache"

2 changes: 1 addition & 1 deletion guide/src/index.md
Original file line number Diff line number Diff line change
@@ -4,4 +4,4 @@ Welcome to the maturin user guide! It contains examples and documentation to exp

Please choose from the chapters on the left to jump to individual topics, or continue below to start with maturin's README.

{{#include ../../Readme.md}}
{{#include ../../README.md}}
2 changes: 1 addition & 1 deletion guide/src/project_layout.md
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ my-rust-and-python-project
│ ├── __init__.py
│ └── bar.py
├── pyproject.toml
├── Readme.md
├── README.md
└── src
└── lib.rs
```
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -38,7 +38,7 @@ def finalize_options(self):
except ImportError:
bdist_wheel = None

with open("Readme.md", encoding="utf-8", errors="ignore") as fp:
with open("README.md", encoding="utf-8", errors="ignore") as fp:
long_description = fp.read()

with open("Cargo.toml", "rb") as fp:
2 changes: 1 addition & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
@@ -744,7 +744,7 @@ mod test {
);
assert_eq!(
metadata.description,
Some(fs_err::read_to_string("test-crates/pyo3-pure/Readme.md").unwrap())
Some(fs_err::read_to_string("test-crates/pyo3-pure/README.md").unwrap())
);
assert_eq!(metadata.classifiers, &["Programming Language :: Rust"]);
assert_eq!(
2 changes: 1 addition & 1 deletion src/project_layout.rs
Original file line number Diff line number Diff line change
@@ -231,7 +231,7 @@ impl ProjectResolver {
// Detect src layout:
//
// my-project
// ├── Readme.md
// ├── README.md
// ├── pyproject.toml
// ├── src
// │ └── my_project
33 changes: 22 additions & 11 deletions src/source_distribution.rs
Original file line number Diff line number Diff line change
@@ -187,20 +187,31 @@ fn rewrite_cargo_toml(
// Update workspace members
if let Some(workspace) = data.get_mut("workspace").and_then(|x| x.as_table_mut()) {
if let Some(members) = workspace.get_mut("members").and_then(|x| x.as_array_mut()) {
let mut new_members = toml_edit::Array::new();
for member in members.iter() {
if let toml_edit::Value::String(ref s) = member {
let path = Path::new(s.value());
if let Some(name) = path.file_name().and_then(|x| x.to_str()) {
if known_path_deps.contains_key(name) {
new_members.push(format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, name));
if known_path_deps.is_empty() {
// Remove workspace members when there isn't any path dep
workspace.remove("members");
if workspace.is_empty() {
// Remove workspace all together if it's empty
data.remove("workspace");
}
rewritten = true;
} else {
let mut new_members = toml_edit::Array::new();
for member in members.iter() {
if let toml_edit::Value::String(ref s) = member {
let path = Path::new(s.value());
if let Some(name) = path.file_name().and_then(|x| x.to_str()) {
if known_path_deps.contains_key(name) {
new_members
.push(format!("{}/{}", LOCAL_DEPENDENCIES_FOLDER, name));
}
}
}
}
}
if !new_members.is_empty() {
workspace["members"] = toml_edit::value(new_members);
rewritten = true;
if !new_members.is_empty() {
workspace["members"] = toml_edit::value(new_members);
rewritten = true;
}
}
}
}
2 changes: 1 addition & 1 deletion test-crates/hello-world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["konstin <konstin@mailbox.org>"]
edition = "2018"
# Test references to out-of-project files
readme = "../../Readme.md"
readme = "../../README.md"
default-run = "hello-world"

[dependencies]
File renamed without changes.
2 changes: 1 addition & 1 deletion test-crates/pyo3-ffi-pure/pyproject.toml
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ classifiers = [
"Programming Language :: Rust"
]
description = "Tests compilation of packages using pyo3-ffi bindings"
readme = "Readme.md"
readme = "README.md"
maintainers = [
{name = "messense", email = "messense@icloud.com"}
]
2 changes: 1 addition & 1 deletion test-crates/pyo3-mixed-py-subdir/Cargo.toml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ authors = ["konstin <konstin@mailbox.org>"]
name = "pyo3-mixed-py-subdir"
version = "2.1.3"
description = "Implements a dummy function combining rust and python"
readme = "Readme.md"
readme = "README.md"
edition = "2018"

[dependencies]
File renamed without changes.
2 changes: 1 addition & 1 deletion test-crates/pyo3-mixed-submodule/Cargo.toml
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ authors = ["konstin <konstin@mailbox.org>"]
name = "pyo3-mixed-submodule"
version = "2.1.3"
description = "Implements a dummy function combining rust and python"
readme = "Readme.md"
readme = "README.md"
edition = "2018"

[package.metadata.maturin]
File renamed without changes.
12 changes: 8 additions & 4 deletions test-crates/pyo3-pure/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test-crates/pyo3-pure/Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,3 +12,6 @@ pyo3 = { version = "0.17.2", features = ["abi3-py37", "extension-module", "gener
[lib]
name = "pyo3_pure"
crate-type = ["cdylib"]

[workspace]
members = [".", "local-test"]
File renamed without changes.
8 changes: 8 additions & 0 deletions test-crates/pyo3-pure/local-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "local-test"
version = "0.1.0"
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
14 changes: 14 additions & 0 deletions test-crates/pyo3-pure/local-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
}
2 changes: 1 addition & 1 deletion test-crates/pyo3-pure/pyproject.toml
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ classifiers = [
"Programming Language :: Rust"
]
description = "Implements a dummy function in Rust"
readme = "Readme.md"
readme = "README.md"
maintainers = [
{name = "messense", email = "messense@icloud.com"}
]
2 changes: 1 addition & 1 deletion test-crates/update_readme.py
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@


FILES = [
"Readme.md",
"README.md",
"guide/src/develop.md",
"guide/src/tutorial.md",
"guide/src/distribution.md",
19 changes: 17 additions & 2 deletions tests/common/other.rs
Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@ use flate2::read::GzDecoder;
use maturin::{BuildOptions, CargoOptions};
use pretty_assertions::assert_eq;
use std::collections::BTreeSet;
use std::io::Read;
use std::iter::FromIterator;
use std::path::{Path, PathBuf};
use tar::Archive;
@@ -19,7 +20,6 @@ pub fn test_musl() -> Result<bool> {
use fs_err::File;
use goblin::elf::Elf;
use std::io::ErrorKind;
use std::io::Read;
use std::process::Command;

let get_target_list = Command::new("rustup")
@@ -114,6 +114,7 @@ pub fn test_workspace_cargo_lock() -> Result<()> {
pub fn test_source_distribution(
package: impl AsRef<Path>,
expected_files: Vec<&str>,
expected_cargo_toml: Option<(&Path, &str)>,
unique_name: &str,
) -> Result<()> {
let manifest_path = package.as_ref().join("Cargo.toml");
@@ -142,16 +143,30 @@ pub fn test_source_distribution(
let mut archive = Archive::new(tar);
let mut files = BTreeSet::new();
let mut file_count = 0;
let mut cargo_toml = None;
for entry in archive.entries()? {
let entry = entry?;
let mut entry = entry?;
files.insert(format!("{}", entry.path()?.display()));
file_count += 1;
if let Some(cargo_toml_path) = expected_cargo_toml.as_ref().map(|(p, _)| *p) {
if entry.path()? == cargo_toml_path {
let mut contents = String::new();
entry.read_to_string(&mut contents)?;
cargo_toml = Some(contents);
}
}
}
assert_eq!(
files,
BTreeSet::from_iter(expected_files.into_iter().map(ToString::to_string))
);
assert_eq!(file_count, files.len(), "duplicated files found in sdist");

if let Some((cargo_toml_path, expected)) = expected_cargo_toml {
let cargo_toml = cargo_toml
.with_context(|| format!("{} not found in sdist", cargo_toml_path.display()))?;
assert_eq!(cargo_toml, expected);
}
Ok(())
}

47 changes: 46 additions & 1 deletion tests/run.rs
Original file line number Diff line number Diff line change
@@ -4,8 +4,9 @@ use common::{
develop, editable, errors, get_python_implementation, handle_result, integration, other,
test_python_path,
};
use indoc::indoc;
use maturin::Target;
use std::path::PathBuf;
use std::path::{Path, PathBuf};

mod common;

@@ -375,6 +376,46 @@ fn workspace_cargo_lock() {
handle_result(other::test_workspace_cargo_lock())
}

#[test]
fn workspace_members_non_local_dep_sdist() {
let cargo_toml = indoc!(
r#"
[package]
authors = ["konstin <konstin@mailbox.org>"]
name = "pyo3-pure"
version = "2.1.2"
edition = "2018"
description = "Implements a dummy function (get_fortytwo.DummyClass.get_42()) in rust"
license = "MIT"
[dependencies]
pyo3 = { version = "0.17.2", features = ["abi3-py37", "extension-module", "generate-import-lib"] }
[lib]
name = "pyo3_pure"
crate-type = ["cdylib"]
"#
);
handle_result(other::test_source_distribution(
"test-crates/pyo3-pure",
vec![
"pyo3_pure-0.1.0+abc123de/Cargo.lock",
"pyo3_pure-0.1.0+abc123de/Cargo.toml",
"pyo3_pure-0.1.0+abc123de/LICENSE",
"pyo3_pure-0.1.0+abc123de/PKG-INFO",
"pyo3_pure-0.1.0+abc123de/README.md",
"pyo3_pure-0.1.0+abc123de/check_installed/check_installed.py",
"pyo3_pure-0.1.0+abc123de/pyo3_pure.pyi",
"pyo3_pure-0.1.0+abc123de/pyproject.toml",
"pyo3_pure-0.1.0+abc123de/src/lib.rs",
"pyo3_pure-0.1.0+abc123de/tests/test_pyo3_pure.py",
"pyo3_pure-0.1.0+abc123de/tox.ini",
],
Some((Path::new("pyo3_pure-0.1.0+abc123de/Cargo.toml"), cargo_toml)),
"sdist-workspace-members-non-local-dep",
))
}

#[test]
fn lib_with_path_dep_sdist() {
handle_result(other::test_source_distribution(
@@ -390,6 +431,7 @@ fn lib_with_path_dep_sdist() {
"sdist_with_path_dep-0.1.0/src/lib.rs",
"sdist_with_path_dep-0.1.0/PKG-INFO",
],
None,
"sdist-lib-with-path-dep",
))
}
@@ -408,6 +450,7 @@ fn pyo3_mixed_src_layout_sdist() {
"pyo3_mixed_src-2.1.3/rust/src/lib.rs",
"pyo3_mixed_src-2.1.3/PKG-INFO",
],
None,
"sdist-pyo3-mixed-src-layout",
))
}
@@ -426,6 +469,7 @@ fn workspace_with_path_dep_sdist() {
"workspace_with_path_dep-0.1.0/src/lib.rs",
"workspace_with_path_dep-0.1.0/PKG-INFO",
],
None,
"sdist-workspace-with-path-dep",
))
}
@@ -443,6 +487,7 @@ fn workspace_inheritance_sdist() {
"workspace_inheritance-0.1.0/src/lib.rs",
"workspace_inheritance-0.1.0/PKG-INFO",
],
None,
"sdist-workspace-inheritance",
))
}