File: metadata.rs

package info (click to toggle)
python-maturin 1.9.4-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,424 kB
  • sloc: python: 656; javascript: 93; sh: 55; makefile: 10
file content (88 lines) | stat: -rw-r--r-- 2,611 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use anyhow::Result;
use insta::assert_snapshot;
use maturin::{write_dist_info, BuildOptions, CargoOptions, ModuleWriter};
use std::collections::HashMap;
use std::path::{Path, PathBuf};

#[derive(Default)]
struct MockWriter {
    files: Vec<String>,
    contents: HashMap<String, String>,
}

impl ModuleWriter for MockWriter {
    fn add_directory(&mut self, path: impl AsRef<Path>) -> Result<()> {
        self.files.push(path.as_ref().to_string_lossy().to_string());
        Ok(())
    }

    fn add_bytes_with_permissions(
        &mut self,
        target: impl AsRef<Path>,
        _source: Option<&Path>,
        bytes: &[u8],
        _permissions: u32,
    ) -> Result<()> {
        self.files
            .push(target.as_ref().to_string_lossy().to_string());
        self.contents.insert(
            target.as_ref().to_string_lossy().into(),
            std::str::from_utf8(bytes).unwrap().to_string(),
        );
        Ok(())
    }
}

#[test]
fn metadata_hello_world_pep639() {
    let build_options = BuildOptions {
        cargo: CargoOptions {
            manifest_path: Some(
                PathBuf::from("test-crates")
                    .join("hello-world")
                    .join("Cargo.toml"),
            ),
            ..CargoOptions::default()
        },
        ..BuildOptions::default()
    };
    let context = build_options.into_build_context().build().unwrap();

    let mut writer = MockWriter::default();
    write_dist_info(
        &mut writer,
        &context.project_layout.project_root,
        &context.metadata24,
        &context.tags_from_bridge().unwrap(),
    )
    .unwrap();

    assert_snapshot!(writer.files.join("\n").replace("\\", "/"), @r"
    hello_world-0.1.0.dist-info
    hello_world-0.1.0.dist-info/METADATA
    hello_world-0.1.0.dist-info/WHEEL
    hello_world-0.1.0.dist-info/licenses
    hello_world-0.1.0.dist-info/licenses/LICENSE
    hello_world-0.1.0.dist-info/licenses/licenses/AUTHORS.txt
    ");
    let metadata_path = Path::new("hello_world-0.1.0.dist-info")
        .join("METADATA")
        .to_str()
        .unwrap()
        .to_string();
    // Remove the README in the body of the email
    let metadata = writer.contents[&metadata_path]
        .split_once("\n\n")
        .unwrap()
        .0;
    assert_snapshot!(metadata, @r"
    Metadata-Version: 2.4
    Name: hello-world
    Version: 0.1.0
    License-File: LICENSE
    License-File: licenses/AUTHORS.txt
    Author: konstin <konstin@mailbox.org>
    Author-email: konstin <konstin@mailbox.org>
    Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
    ");
}