atomgit 1.0.11__tar.gz → 1.0.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {atomgit-1.0.11 → atomgit-1.0.12}/PKG-INFO +1 -1
- {atomgit-1.0.11 → atomgit-1.0.12}/api.py +6 -1
- {atomgit-1.0.11 → atomgit-1.0.12}/atomgit.egg-info/PKG-INFO +1 -1
- {atomgit-1.0.11 → atomgit-1.0.12}/atomgit_hub.py +39 -1
- {atomgit-1.0.11 → atomgit-1.0.12}/setup.py +1 -1
- {atomgit-1.0.11 → atomgit-1.0.12}/MANIFEST.in +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/README.md +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/__init__.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/__main__.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/atomgit.egg-info/SOURCES.txt +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/atomgit.egg-info/dependency_links.txt +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/atomgit.egg-info/entry_points.txt +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/atomgit.egg-info/requires.txt +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/atomgit.egg-info/top_level.txt +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/cli.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/config.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/rate_limiter.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/requirements.txt +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/setup.cfg +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/tests/test_download_real.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/tests/test_endpoint_config.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/tests/test_repo_id_normalize.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/tests/test_repo_name_validation.py +0 -0
- {atomgit-1.0.11 → atomgit-1.0.12}/utils.py +0 -0
|
@@ -262,7 +262,12 @@ class HuggingFaceAPI:
|
|
|
262
262
|
|
|
263
263
|
# 创建本地目录
|
|
264
264
|
local_path.mkdir(parents=True, exist_ok=True)
|
|
265
|
-
|
|
265
|
+
|
|
266
|
+
# 先探测文件是否存在,给出准确提示(避免把 404 报成网络/缓存故障)
|
|
267
|
+
if atomgit_hub._file_http_status(normalized_repo_id, filename) == 404:
|
|
268
|
+
print(f"文件不存在:{repo_id}/{filename}(revision: main,HTTP 404)。请检查文件路径或版本。")
|
|
269
|
+
return False
|
|
270
|
+
|
|
266
271
|
# 首先尝试不使用token下载(适用于公开仓库)
|
|
267
272
|
try:
|
|
268
273
|
hf_hub_download(
|
|
@@ -161,6 +161,29 @@ def _probe_repo(repo_id: str, token: Optional[str] = None) -> Optional[str]:
|
|
|
161
161
|
return None
|
|
162
162
|
|
|
163
163
|
|
|
164
|
+
def _file_http_status(repo_id: str, filename: str, revision: Optional[str] = None,
|
|
165
|
+
token: Optional[str] = None) -> Optional[int]:
|
|
166
|
+
"""探测单个文件的可访问性,返回 HTTP 状态码;网络异常返回 None。"""
|
|
167
|
+
endpoint = os.environ.get("HF_ENDPOINT", "https://hub.atomgit.com").rstrip("/")
|
|
168
|
+
rev = revision or "main"
|
|
169
|
+
headers = {"User-Agent": "atomgit-cli"}
|
|
170
|
+
if token:
|
|
171
|
+
headers["Authorization"] = f"Bearer {token}"
|
|
172
|
+
# 注意:HF 兼容的 resolve 路由是 /{namespace}/{repo}/resolve/...,不带 /api/models 前缀
|
|
173
|
+
request = urllib.request.Request(
|
|
174
|
+
f"{endpoint}/{repo_id}/resolve/{rev}/{urllib.parse.quote(filename, safe='/')}",
|
|
175
|
+
headers=headers,
|
|
176
|
+
method="HEAD",
|
|
177
|
+
)
|
|
178
|
+
try:
|
|
179
|
+
with urllib.request.urlopen(request, timeout=15):
|
|
180
|
+
return 200
|
|
181
|
+
except urllib.error.HTTPError as e:
|
|
182
|
+
return e.code
|
|
183
|
+
except Exception:
|
|
184
|
+
return None
|
|
185
|
+
|
|
186
|
+
|
|
164
187
|
def snapshot_download(
|
|
165
188
|
repo_id: str,
|
|
166
189
|
revision: Optional[str] = None,
|
|
@@ -360,10 +383,25 @@ def download_file(
|
|
|
360
383
|
return result
|
|
361
384
|
except Exception as e:
|
|
362
385
|
error_msg = str(e)
|
|
386
|
+
rev = revision or "main"
|
|
387
|
+
# huggingface_hub 常把“文件不存在”报成缓存/网络故障(LocalEntryNotFoundError),
|
|
388
|
+
# 这里用一次 HEAD 请求还原真实状态码,给出准确提示
|
|
389
|
+
status = _file_http_status(normalized_repo_id, filename, revision, token)
|
|
390
|
+
if status == 404:
|
|
391
|
+
raise Exception(
|
|
392
|
+
f"文件不存在:{repo_id}/{filename}(revision: {rev},HTTP 404)。请检查文件路径或版本。"
|
|
393
|
+
)
|
|
394
|
+
if status in (401, 403):
|
|
395
|
+
raise Exception(
|
|
396
|
+
f"认证失败:{repo_id}/{filename}(revision: {rev},HTTP {status})。"
|
|
397
|
+
"请检查 token 是否有效,或是否拥有该仓库权限。"
|
|
398
|
+
)
|
|
363
399
|
if "401" in error_msg or "403" in error_msg:
|
|
364
400
|
raise Exception(f"认证失败:{error_msg}")
|
|
365
401
|
elif "404" in error_msg:
|
|
366
|
-
raise Exception(
|
|
402
|
+
raise Exception(
|
|
403
|
+
f"文件不存在:{repo_id}/{filename}(revision: {rev},HTTP 404)。请检查文件路径或版本。"
|
|
404
|
+
)
|
|
367
405
|
else:
|
|
368
406
|
raise Exception(f"下载失败:{error_msg}")
|
|
369
407
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|