|
2 | 2 | # |
3 | 3 | # SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
5 | | -""" |
6 | | -Compose hash calculation module for dstack SDK. |
| 5 | +"""Compose hash calculation module for dstack SDK. |
7 | 6 |
|
8 | 7 | Provides deterministic JSON serialization and SHA256 hashing of AppCompose configurations, |
9 | 8 | compatible with the TypeScript implementation. |
@@ -153,8 +152,7 @@ def from_dict(cls, data: Dict[str, Any]) -> "AppCompose": |
153 | 152 |
|
154 | 153 |
|
155 | 154 | def sort_object(obj: Any) -> Any: |
156 | | - """ |
157 | | - Recursively sort object keys lexicographically. |
| 155 | + """Recursively sort object keys lexicographically. |
158 | 156 |
|
159 | 157 | This is crucial for deterministic JSON.stringify. |
160 | 158 | """ |
@@ -185,8 +183,7 @@ def preprocess_app_compose(app_compose: AppCompose) -> AppCompose: |
185 | 183 |
|
186 | 184 |
|
187 | 185 | def to_deterministic_json(app_compose: AppCompose) -> str: |
188 | | - """ |
189 | | - Serialize to deterministic JSON following cross-language standards. |
| 186 | + """Serialize to deterministic JSON following cross-language standards. |
190 | 187 |
|
191 | 188 | - Recursively sorts object keys lexicographically |
192 | 189 | - Compact output (no spaces) |
@@ -224,15 +221,15 @@ def process_data(obj: Any) -> Any: |
224 | 221 | def get_compose_hash( |
225 | 222 | app_compose: Union[AppCompose, Dict[str, Any]], normalize: bool = False |
226 | 223 | ) -> str: |
227 | | - """ |
228 | | - Calculate SHA256 hash of app compose configuration. |
| 224 | + """Calculate SHA256 hash of app compose configuration. |
229 | 225 |
|
230 | 226 | Args: |
231 | 227 | app_compose: AppCompose object or dictionary |
232 | 228 | normalize: Whether to preprocess the compose (remove conflicting fields) |
233 | 229 |
|
234 | 230 | Returns: |
235 | 231 | str: SHA256 hash as hex string |
| 232 | +
|
236 | 233 | """ |
237 | 234 | if isinstance(app_compose, dict): |
238 | 235 | app_compose = AppCompose.from_dict(app_compose) |
|
0 commit comments