Skip to content

Commit

Permalink
Refactor Cargo sdist generator to avoid rewriting local dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
messense committed Aug 20, 2023
1 parent f8a9398 commit e32493b
Show file tree
Hide file tree
Showing 10 changed files with 271 additions and 533 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ wild = { version = "2.1.0", optional = true }
url = { version = "2.3.1", optional = true }

[dev-dependencies]
expect-test = "1.4.1"
indoc = "2.0.3"
pretty_assertions = "1.3.0"
rustversion = "1.0.9"
Expand Down
31 changes: 13 additions & 18 deletions src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,7 @@ jobs:\n",
mod tests {
use super::GenerateCI;
use crate::BridgeModel;
use indoc::indoc;
use pretty_assertions::assert_eq;
use expect_test::expect;

#[test]
fn test_generate_github() {
Expand All @@ -530,7 +529,7 @@ mod tests {
.skip(5)
.collect::<Vec<_>>()
.join("\n");
let expected = indoc! {r#"
let expected = expect![[r#"
name: CI
on:
Expand Down Expand Up @@ -645,9 +644,8 @@ mod tests {
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
"#};
assert_eq!(conf, expected.trim());
args: --non-interactive --skip-existing *"#]];
expected.assert_eq(&conf);
}

#[test]
Expand All @@ -659,7 +657,7 @@ mod tests {
.skip(5)
.collect::<Vec<_>>()
.join("\n");
let expected = indoc! {r#"
let expected = expect![[r#"
name: CI
on:
Expand Down Expand Up @@ -759,9 +757,8 @@ mod tests {
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
"#};
assert_eq!(conf, expected.trim());
args: --non-interactive --skip-existing *"#]];
expected.assert_eq(&conf);
}

#[test]
Expand All @@ -782,7 +779,7 @@ mod tests {
.skip(5)
.collect::<Vec<_>>()
.join("\n");
let expected = indoc! {r#"
let expected = expect![[r#"
name: CI
on:
Expand Down Expand Up @@ -936,9 +933,8 @@ mod tests {
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
"#};
assert_eq!(conf, expected.trim());
args: --non-interactive --skip-existing *"#]];
expected.assert_eq(&conf);
}

#[test]
Expand All @@ -950,7 +946,7 @@ mod tests {
.skip(5)
.collect::<Vec<_>>()
.join("\n");
let expected = indoc! {r#"
let expected = expect![[r#"
name: CI
on:
Expand Down Expand Up @@ -1055,8 +1051,7 @@ mod tests {
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing *
"#};
assert_eq!(conf, expected.trim());
args: --non-interactive --skip-existing *"#]];
expected.assert_eq(&conf);
}
}
18 changes: 6 additions & 12 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,14 @@ fn fold_header(text: &str) -> String {
mod test {
use super::*;
use cargo_metadata::MetadataCommand;
use expect_test::{expect, Expect};
use indoc::indoc;
use pretty_assertions::assert_eq;

fn assert_metadata_from_cargo_toml(
readme: &str,
cargo_toml: &str,
expected: &str,
expected: Expect,
) -> Metadata21 {
let crate_dir = tempfile::tempdir().unwrap();
let crate_path = crate_dir.path();
Expand Down Expand Up @@ -617,13 +618,7 @@ mod test {

let actual = metadata.to_file_contents().unwrap();

assert_eq!(
actual.trim(),
expected.trim(),
"Actual metadata differed from expected\nEXPECTED:\n{}\n\nGOT:\n{}",
expected,
actual
);
expected.assert_eq(&actual);

// get_dist_info_dir test checks against hard-coded values - check that they are as expected in the source first
assert!(
Expand Down Expand Up @@ -662,8 +657,7 @@ mod test {
"#
);

let expected = indoc!(
r#"
let expected = expect![[r#"
Metadata-Version: 2.1
Name: info-project
Version: 0.1.0
Expand All @@ -677,8 +671,8 @@ mod test {
# Some test package
This is the readme for a test package
"#
);
"#]];

assert_metadata_from_cargo_toml(readme, cargo_toml, expected);
}
Expand Down
20 changes: 9 additions & 11 deletions src/pyproject_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ mod tests {
pyproject_toml::{Format, Formats, GlobPattern, ToolMaturin},
PyProjectToml,
};
use expect_test::expect;
use fs_err as fs;
use indoc::indoc;
use pretty_assertions::assert_eq;
Expand Down Expand Up @@ -521,16 +522,13 @@ mod tests {
let outer_error = PyProjectToml::new(&pyproject_toml).unwrap_err();
let inner_error = outer_error.source().unwrap();

assert_eq!(
inner_error.to_string(),
indoc!(
r#"TOML parse error at line 7, column 17
|
7 | license-files = [ "license.txt",]
| ^^^^^^^^^^^^^^^^^
wanted string or table
"#
)
);
let expected = expect![[r#"
TOML parse error at line 7, column 17
|
7 | license-files = [ "license.txt",]
| ^^^^^^^^^^^^^^^^^
wanted string or table
"#]];
expected.assert_eq(&inner_error.to_string());
}
}
21 changes: 19 additions & 2 deletions src/python_interpreter/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ suppress_build_script_link_lines=false"#,
#[cfg(test)]
mod test {
use super::*;
use expect_test::expect;
use pretty_assertions::assert_eq;

#[test]
Expand Down Expand Up @@ -712,7 +713,15 @@ mod test {
)
.unwrap();
let config_file = sysconfig.pyo3_config_file();
assert_eq!(config_file, "implementation=CPython\nversion=3.10\nshared=true\nabi3=false\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\npointer_width=64");
let expected = expect![[r#"
implementation=CPython
version=3.10
shared=true
abi3=false
build_flags=WITH_THREAD
suppress_build_script_link_lines=false
pointer_width=64"#]];
expected.assert_eq(&config_file);
}

#[test]
Expand All @@ -725,6 +734,14 @@ mod test {
.unwrap();
assert_eq!(sysconfig.ext_suffix, ".cpython-311-x86_64-linux-musl.so");
let config_file = sysconfig.pyo3_config_file();
assert_eq!(config_file, "implementation=CPython\nversion=3.11\nshared=true\nabi3=false\nbuild_flags=WITH_THREAD\nsuppress_build_script_link_lines=false\npointer_width=64");
let expected = expect![[r#"
implementation=CPython
version=3.11
shared=true
abi3=false
build_flags=WITH_THREAD
suppress_build_script_link_lines=false
pointer_width=64"#]];
expected.assert_eq(&config_file);
}
}
Loading

0 comments on commit e32493b

Please sign in to comment.