File size: 1,221 Bytes
cc98837 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | """Preflight permission to upload to the dataset's main branch.
This module imports no Hub SDK until called. The small, already-verified
manifest is checked through the normal preupload API with ``create_pr=False``;
no commit is created. The frozen dataset attributes keep JSON in regular Git,
so this preflight does not upload the large dataset files.
"""
def check_write_access(api, repo_id, checked, network):
"""Check write access even when a prior run already committed provenance."""
from huggingface_hub import CommitOperationAdd
def preflight():
# The SDK mutates additions. Reconstruct on every retry so cached
# upload-mode/uploaded flags cannot accidentally bypass the API check.
addition = CommitOperationAdd(
path_in_repo="upload_manifest.json",
path_or_fileobj=checked["folder"] / "upload_manifest.json",
)
return api.preupload_lfs_files(
repo_id=repo_id,
additions=[addition],
repo_type="dataset",
revision="main",
create_pr=False,
num_threads=1,
free_memory=False,
)
return network.call("Check dataset write access", preflight)
|