Datasets:
File size: 806 Bytes
aaee816 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | """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
|