language-status / scripts /hf_publishing_auth.py
nafisehNik's picture
Translation-resource audit of 325 FineWiki languages (finewiki_audit_20261114T182048Z)
aaee816 verified
Raw History Blame Contribute Delete
806 Bytes
"""Local-only credential lookup; this module is never included in a Hub release."""
import os
import re
import subprocess
import sys
KEYCHAIN_SERVICE = "gilaki-huggingface-project"
KEYCHAIN_ACCOUNT = "sigiranic-gilaki-publishing"
def publishing_token():
token = os.environ.get("HF_TOKEN", "").strip()
if not token and sys.platform == "darwin":
result = subprocess.run(["security", "find-generic-password", "-s", KEYCHAIN_SERVICE,
"-a", KEYCHAIN_ACCOUNT, "-w"], text=True, capture_output=True)
if result.returncode == 0:
token = result.stdout.rstrip("\n")
if not re.fullmatch(r"hf_[A-Za-z0-9]{20,}", token):
raise RuntimeError("No valid project credential found in HF_TOKEN or the project Keychain entry")
return token