|
2 | 2 | set -Eeuo pipefail |
3 | 3 |
|
4 | 4 | DEFAULT_BUCKET="BlueSkyXN/librefs-hfs-data" |
| 5 | +EXPECTED_HF_HUB_VERSION="1.5.0" |
| 6 | +EXPECTED_CLICK_VERSION="8.3.1" |
5 | 7 | BUCKET="${HF_BUCKET_ID:-$DEFAULT_BUCKET}" |
6 | 8 | OPS_URL="${OPS_URL:-}" |
7 | 9 | INTERVAL=0 |
@@ -83,13 +85,28 @@ if [[ "$COUNT" == "0" && "$INTERVAL" == "0" ]]; then |
83 | 85 | exit 2 |
84 | 86 | fi |
85 | 87 |
|
86 | | -if ! command -v hf >/dev/null 2>&1; then |
87 | | - echo "hf CLI is required." >&2 |
| 88 | +if ! command -v python3 >/dev/null 2>&1; then |
| 89 | + echo "python3 is required." >&2 |
88 | 90 | exit 1 |
89 | 91 | fi |
90 | 92 |
|
91 | | -if ! command -v python3 >/dev/null 2>&1; then |
92 | | - echo "python3 is required." >&2 |
| 93 | +if ! python3 - "$EXPECTED_HF_HUB_VERSION" "$EXPECTED_CLICK_VERSION" <<'PY' |
| 94 | +import importlib.metadata |
| 95 | +import sys |
| 96 | +
|
| 97 | +expected_hub, expected_click = sys.argv[1:] |
| 98 | +try: |
| 99 | + actual_hub = importlib.metadata.version("huggingface_hub") |
| 100 | + actual_click = importlib.metadata.version("click") |
| 101 | +except importlib.metadata.PackageNotFoundError as exc: |
| 102 | + raise SystemExit(f"required Python package is missing: {exc.name}") from exc |
| 103 | +if actual_hub != expected_hub or actual_click != expected_click: |
| 104 | + raise SystemExit( |
| 105 | + "storage sampler requires " |
| 106 | + f"huggingface_hub=={expected_hub} and click=={expected_click}" |
| 107 | + ) |
| 108 | +PY |
| 109 | +then |
93 | 110 | exit 1 |
94 | 111 | fi |
95 | 112 |
|
@@ -124,8 +141,23 @@ sample_once() { |
124 | 141 | local list_json="$TMP_DIR/list.json" |
125 | 142 | local ops_json="$TMP_DIR/ops.json" |
126 | 143 |
|
127 | | - hf buckets info "$BUCKET" --json >"$info_json" |
128 | | - hf buckets list "$BUCKET" -R --json >"$list_json" |
| 144 | + python3 - "$BUCKET" >"$info_json" <<'PY' |
| 145 | +import json |
| 146 | +import sys |
| 147 | +
|
| 148 | +from huggingface_hub import HfApi |
| 149 | +
|
| 150 | +info = HfApi().bucket_info(sys.argv[1]) |
| 151 | +print(json.dumps({ |
| 152 | + "id": info.id, |
| 153 | + "private": info.private, |
| 154 | + "createdAt": info.created_at.isoformat(), |
| 155 | + "size": info.size, |
| 156 | + "totalFiles": info.total_files, |
| 157 | +}, sort_keys=True)) |
| 158 | +PY |
| 159 | + python3 -m huggingface_hub.cli.hf buckets list \ |
| 160 | + "$BUCKET" --recursive --format json >"$list_json" |
129 | 161 |
|
130 | 162 | if [[ -n "$OPS_URL" ]]; then |
131 | 163 | curl -fsS -H "X-Ops-Token: ${OPS_TOKEN}" "$(ops_endpoint)" >"$ops_json" |
|
0 commit comments