Spaces:
Running
Running
Download code/run_cleanup2.py from ArthurZ/transformers-triage: direct link, hf CLI and curl.
- Browser
- Download file 1.72 kB
-
https://huggingface.co/spaces/ArthurZ/transformers-triage/resolve/main/code/run_cleanup2.py
- Command line
-
hf download hf://spaces/ArthurZ/transformers-triage/code/run_cleanup2.py
-
curl -L -o run_cleanup2.py https://huggingface.co/spaces/ArthurZ/transformers-triage/resolve/main/code/run_cleanup2.py
1.72 kB
| import json, re, shlex, subprocess, time | |
| html = open('cleanup.html').read() | |
| data = {c['number']: c for c in json.loads(re.search(r'const DATA = (.*);\nconst KEY', html, re.S).group(1).replace('<\\/', '</'))} | |
| toks = shlex.split(open('cleanup_close.sh').read().split('R=huggingface/transformers\n', 1)[1]) | |
| cmds, cur = [], None | |
| for t in toks: | |
| if t == 'gh': cur = []; cmds.append(cur) | |
| else: cur.append(t) | |
| jobs = [(int(c[2]), c[6]) for c in cmds] | |
| V4 = data[next(n for n, c in data.items() if 'based on v4' in c['message'])]['message'] | |
| STALE = {13752, 15773, 18152} | |
| jobs = [(n, V4 if n in STALE else m) for n, m in jobs] | |
| OK = set(int(x) for x in re.findall(r'#(\d+) ok', open('cleanup_run.log').read())) | |
| jobs = [(n, m) for n, m in jobs if n not in OK] | |
| N, t0, fails = len(jobs), time.time(), [] | |
| for i, (n, m) in enumerate(jobs, 1): | |
| for attempt in range(1000): | |
| r = subprocess.run(['gh', 'pr', 'close', str(n), '-R', 'huggingface/transformers', '-c', m], capture_output=True, text=True) | |
| if r.returncode == 0 or 'too quickly' not in (r.stderr + r.stdout): break | |
| print(f'[{i}/{N}] #{n} rate-limited, sleeping 300s (attempt {attempt+1})', flush=True); time.sleep(300) | |
| time.sleep(4) # ponytail: fixed spacing to stay under GitHub's secondary content-creation limit | |
| el = time.time() - t0 | |
| if r.returncode == 0: | |
| print(f'[{i}/{N}] #{n} ok | elapsed {el:.0f}s | eta ~{el/i*(N-i):.0f}s', flush=True) | |
| else: | |
| err = (r.stderr or r.stdout).strip().replace('\n', ' ')[:200] | |
| fails.append((n, err)); print(f'[{i}/{N}] #{n} FAIL: {err}', flush=True) | |
| json.dump(fails, open('cleanup_fail2.json', 'w')) | |
| print(f'done ok={N-len(fails)} fails={len(fails)}', flush=True) | |