Skip to content

Commit fe92da8

Browse files
committed
remove formatter for hash
1 parent dc80bca commit fe92da8

File tree

1 file changed

+9
-49
lines changed

1 file changed

+9
-49
lines changed

src/hash.rs

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::collections::{BTreeMap, HashMap};
33

44
use rattler_conda_types::NoArchType;
55
use serde::{Deserialize, Serialize};
6-
use serde_json::ser::Formatter;
76
use sha1::{Digest, Sha1};
87

98
use crate::{normalized_key::NormalizedKey, recipe::variable::Variable};
@@ -28,45 +27,6 @@ use crate::{normalized_key::NormalizedKey, recipe::variable::Variable};
2827
///
2928
/// used variables - anything with a value in conda_build_config.yaml that applies to this
3029
/// recipe. Includes compiler if compiler jinja2 function is used.
31-
///
32-
/// This implements a formatter that uses the same formatting as
33-
/// as the standard lib python `json.dumps()`
34-
#[derive(Clone, Debug)]
35-
struct PythonFormatter {}
36-
37-
impl Formatter for PythonFormatter {
38-
#[inline]
39-
fn begin_array_value<W>(&mut self, writer: &mut W, first: bool) -> std::io::Result<()>
40-
where
41-
W: ?Sized + std::io::Write,
42-
{
43-
if first {
44-
Ok(())
45-
} else {
46-
writer.write_all(b", ")
47-
}
48-
}
49-
50-
#[inline]
51-
fn begin_object_key<W>(&mut self, writer: &mut W, first: bool) -> std::io::Result<()>
52-
where
53-
W: ?Sized + std::io::Write,
54-
{
55-
if first {
56-
Ok(())
57-
} else {
58-
writer.write_all(b", ")
59-
}
60-
}
61-
62-
#[inline]
63-
fn begin_object_value<W>(&mut self, writer: &mut W) -> std::io::Result<()>
64-
where
65-
W: ?Sized + std::io::Write,
66-
{
67-
writer.write_all(b": ")
68-
}
69-
}
7030
7131
// TODO merge with the jinja function that we have for this
7232
fn short_version_from_spec(input: &str, length: u32) -> String {
@@ -97,15 +57,15 @@ pub struct HashInput(String);
9757
impl HashInput {
9858
/// Create a new hash input from a variant
9959
pub fn from_variant(variant: &BTreeMap<NormalizedKey, Variable>) -> Self {
100-
let mut buf = Vec::new();
101-
let mut ser = serde_json::Serializer::with_formatter(&mut buf, PythonFormatter {});
102-
103-
// BTree has sorted keys, which is important for hashing
104-
variant
105-
.serialize(&mut ser)
106-
.expect("Failed to serialize input");
107-
108-
Self(String::from_utf8(buf).expect("Failed to convert to string"))
60+
// Convert the variant into a simple BTreeMap<String, String> to ensure consistent serialization
61+
let mut map = BTreeMap::new();
62+
for (key, value) in variant {
63+
map.insert(key.normalize(), value.to_string());
64+
}
65+
66+
// Use serde_json with default formatting to match Python's json.dumps()
67+
let json = serde_json::to_string(&map).expect("Failed to serialize input");
68+
Self(json)
10969
}
11070

11171
/// Get the hash input as a string

0 commit comments

Comments
 (0)