E585 Refactor Cargo sdist generator to avoid rewriting local dependencies · PyO3/maturin@e32493b · GitHub
[go: up one dir, main page]

Skip to content

Commit e32493b

Browse files
committed
Refactor Cargo sdist generator to avoid rewriting local dependencies
1 parent f8a9398 commit e32493b

File tree

10 files changed

+271
-533
lines changed

10 files changed

+271
-533
lines changed

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ wild = { version = "2.1.0", optional = true }
107107
url = { version = "2.3.1", optional = true }
108108

109109
[dev-dependencies]
110+
expect-test = "1.4.1"
110111
indoc = "2.0.3"
111112
pretty_assertions = "1.3.0"
112113
rustversion = "1.0.9"

src/ci.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,7 @@ jobs:\n",
514514
mod tests {
515515
use super::GenerateCI;
516516
use crate::BridgeModel;
517-
use indoc::indoc;
518-
use pretty_assertions::assert_eq;
517+
use expect_test::expect;
519518

520519
#[test]
521520
fn test_generate_github() {
@@ -530,7 +529,7 @@ mod tests {
530529
.skip(5)
531530
.collect::<Vec<_>>()
532531
.join("\n");
533-
let expected = indoc! {r#"
532+
let expected = expect![[r#"
534533
name: CI
535534
536535
on:
@@ -645,9 +644,8 @@ mod tests {
645644
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
646645
with:
647646
command: upload
648-
args: --non-interactive --skip-existing *
649-
"#};
650-
assert_eq!(conf, expected.trim());
647+
args: --non-interactive --skip-existing *"#]];
648+
expected.assert_eq(&conf);
651649
}
652650

653651
#[test]
@@ -659,7 +657,7 @@ mod tests {
659657
.skip(5)
660658
.collect::<Vec<_>>()
661659
.join("\n");
662-
let expected = indoc! {r#"
660+
let expected = expect![[r#"
663661
name: CI
664662
665663
on:
@@ -759,9 +757,8 @@ mod tests {
759757
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
760758
with:
761759
command: upload
762-
args: --non-interactive --skip-existing *
763-
"#};
764-
assert_eq!(conf, expected.trim());
760+
args: --non-interactive --skip-existing *"#]];
761+
expected.assert_eq(&conf);
765762
}
766763

767764
#[test]
@@ -782,7 +779,7 @@ mod tests {
782779
.skip(5)
783780
.collect::<Vec<_>>()
784781
.join("\n");
785-
let expected = indoc! {r#"
782+
let expected = expect![[r#"
786783
name: CI
787784
788785
on:
@@ -936,9 +933,8 @@ mod tests {
936933
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
937934
with:
938935
command: upload
939-
args: --non-interactive --skip-existing *
940-
"#};
941-
assert_eq!(conf, expected.trim());
936+
args: --non-interactive --skip-existing *"#]];
937+
expected.assert_eq(&conf);
942938
}
943939

944940
#[test]
@@ -950,7 +946,7 @@ mod tests {
950946
.skip(5)
951947
.collect::<Vec<_>>()
952948
.join("\n");
953-
let expected = indoc! {r#"
949+
let expected = expect![[r#"
954950
name: CI
955951
956952
on:
@@ -1055,8 +1051,7 @@ mod tests {
10551051
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
10561052
with:
10571053
command: upload
1058-
args: --non-interactive --skip-existing *
1059-
"#};
1060-
assert_eq!(conf, expected.trim());
1054+
args: --non-interactive --skip-existing *"#]];
1055+
expected.assert_eq(&conf);
10611056
}
10621057
}

src/metadata.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,14 @@ fn fold_header(text: &str) -> String {
582582
mod test {
583583
use super::*;
584584
use cargo_metadata::MetadataCommand;
585+
use expect_test::{expect, Expect};
585586
use indoc::indoc;
586587
use pretty_assertions::assert_eq;
587588

588589
fn assert_metadata_from_cargo_toml(
589590
readme: &str,
590591
cargo_toml: &str,
591-
expected: &str,
592+
expected: Expect,
592593
) -> Metadata21 {
593594
let crate_dir = tempfile::tempdir().unwrap();
594595
let crate_path = crate_dir.path();
@@ -617,13 +618,7 @@ mod test {
617618

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

620-
assert_eq!(
621-
actual.trim(),
622-
expected.trim(),
623-
"Actual metadata differed from expected\nEXPECTED:\n{}\n\nGOT:\n{}",
624-
expected,
625-
actual
626-
);
621+
expected.assert_eq(&actual);
627622

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

665-
let expected = indoc!(
666-
r#"
660+
let expected = expect![[r#"
667661
Metadata-Version: 2.1
668662
Name: info-project
669663
Version: 0.1.0
@@ -677,8 +671,8 @@ mod test {
677671
# Some test package
678672
679673
This is the readme for a test package
680-
"#
681-
);
674+
675+
"#]];
682676

683677
assert_metadata_from_cargo_toml(readme, cargo_toml, expected);
684678
}

src/pyproject_toml.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ mod tests {
350350
pyproject_toml::{Format, Formats, GlobPattern, ToolMaturin},
351351
PyProjectToml,
352352
};
353+
use expect_test::expect;
353354
use fs_err as fs;
354355
use indoc::indoc;
355356
use pretty_assertions::assert_eq;
@@ -521,16 +522,13 @@ mod tests {
521522
let outer_error = PyProjectToml::new(&pyproject_toml).unwrap_err();
522523
let inner_error = outer_error.source().unwrap();
523524

524-
assert_eq!(
525-
inner_error.to_string(),
526-
indoc!(
527-
r#"TOML parse error at line 7, column 17
528-
|
529-
7 | license-files = [ "license.txt",]
530-
| ^^^^^^^^^^^^^^^^^
531-
wanted string or table
532-
"#
533-
)
534-
);
525+
let expected = expect![[r#"
526+
TOML parse error at line 7, column 17
527+
|
528+
7 | license-files = [ "license.txt",]
529+
| ^^^^^^^^^^^^^^^^^
530+
wanted string or table
531+
"#]];
532+
expected.assert_eq(&inner_error.to_string());
535533
}
536534
}

src/python_interpreter/config.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,7 @@ suppress_build_script_link_lines=false"#,
388388
#[cfg(test)]
389389
mod test {
390390
use super::*;
391+
use expect_test::expect;
391392
use pretty_assertions::assert_eq;
392393

393394
#[test]
@@ -712,7 +713,15 @@ mod test {
712713
)
713714
.unwrap();
714715
let config_file = sysconfig.pyo3_config_file();
715-
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");
716+
let expected = expect![[r#"
717+
implementation=CPython
718+
version=3.10
719+
shared=true
720+
abi3=false
721+
build_flags=WITH_THREAD
722+
suppress_build_script_link_lines=false
723+
pointer_width=64"#]];
724+
expected.assert_eq(&config_file);
716725
}
717726

718727
#[test]
@@ -725,6 +734,14 @@ mod test {
725734
.unwrap();
726735
assert_eq!(sysconfig.ext_suffix, ".cpython-311-x86_64-linux-musl.so");
727736
let config_file = sysconfig.pyo3_config_file();
728-
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");
737+
let expected = expect![[r#"
738+
implementation=CPython
739+
version=3.11
740+
shared=true
741+
abi3=false
742+
build_flags=WITH_THREAD
743+
suppress_build_script_link_lines=false
744+
pointer_width=64"#]];
745+
expected.assert_eq(&config_file);
729746
}
730747
}

0 commit comments

Comments
 (0)
0