11#!/usr/bin/env python3
2+ # SPDX-FileCopyrightText: Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+ # SPDX-License-Identifier: Apache-2.0
4+ #
5+ # Licensed under the Apache License, Version 2.0 (the "License");
6+ # you may not use this file except in compliance with the License.
7+ # You may obtain a copy of the License at
8+ #
9+ # http://www.apache.org/licenses/LICENSE-2.0
10+ #
11+ # Unless required by applicable law or agreed to in writing, software
12+ # distributed under the License is distributed on an "AS IS" BASIS,
13+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ # See the License for the specific language governing permissions and
15+ # limitations under the License.
16+
217"""
318Generate artifacts.lock.yaml for hermetic model prefetching.
419
1429import logging
1530import os
1631import sys
17- import tempfile
1832import urllib .request
1933from pathlib import Path
2034from typing import Any
@@ -136,9 +150,7 @@ def build_hf_artifacts(
136150) -> tuple [str , list [dict ]]:
137151 org , repo = model_id .split ("/" , 1 )
138152 commit = get_hf_model_commit (model_id )
139- files = collect_hf_files (
140- model_id , skip_files , skip_extensions , skip_prefixes
141- )
153+ files = collect_hf_files (model_id , skip_files , skip_extensions , skip_prefixes )
142154
143155 artifacts = []
144156 for f in files :
@@ -155,11 +167,13 @@ def build_hf_artifacts(
155167 sha = download_and_hash (download_url )
156168 checksum = f"sha256:{ sha } "
157169
158- artifacts .append ({
159- "download_url" : download_url ,
160- "filename" : filename ,
161- "checksum" : checksum ,
162- })
170+ artifacts .append (
171+ {
172+ "download_url" : download_url ,
173+ "filename" : filename ,
174+ "checksum" : checksum ,
175+ }
176+ )
163177
164178 return commit , artifacts
165179
@@ -170,11 +184,13 @@ def build_nltk_artifacts(resources: set[str]) -> list[dict]:
170184 url = f"{ NLTK_DATA_BASE } /packages/tokenizers/{ resource } .zip"
171185 logging .info (f" { resource } (downloading to compute checksum...)" )
172186 sha = download_and_hash (url )
173- artifacts .append ({
174- "download_url" : url ,
175- "filename" : f"nltk--{ resource } .zip" ,
176- "checksum" : f"sha256:{ sha } " ,
177- })
187+ artifacts .append (
188+ {
189+ "download_url" : url ,
190+ "filename" : f"nltk--{ resource } .zip" ,
191+ "checksum" : f"sha256:{ sha } " ,
192+ }
193+ )
178194 return artifacts
179195
180196
0 commit comments