File size: 2,673 Bytes
7f9a652
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Zbook step: fetch the 9 ledgers not built in the cloud, build + verify their

questions, add them to the package, rewrite the README, then upload the package

(never the private test answers) to Hugging Face as Lilambd/empire-eval.



usage: python scripts/add_remote_and_upload.py [--no-upload]

Run from the package folder. Uses the saved `huggingface-cli login`.

"""
import glob, json, os, subprocess, sys, datetime
HERE = os.path.dirname(os.path.abspath(__file__))
PKG = os.path.dirname(HERE)
WORK = os.path.join(os.path.dirname(PKG), 'empire_eval_work')
REMOTE = 'world-signals,world-seeds,japan-dpc-hospitals,japan-prefecture-facts,world-biodiversity-cells,machine-economy-daily,security-daily,world-pulse-daily,world-markets'
PY = sys.executable


def run(*args):
    print('>>', ' '.join(args), flush=True)
    r = subprocess.run([PY, *args], cwd=PKG)
    return r.returncode


def main():
    os.makedirs(WORK, exist_ok=True)
    mirror = os.path.join(WORK, 'mirror')
    built = os.path.join(WORK, 'built_remote')
    private = os.path.join(WORK, 'private')
    if run(os.path.join(HERE, 'fetch_hf.py'), '--mirror', mirror, '--only', REMOTE):
        sys.exit('fetch failed')
    roots = os.path.join(mirror, 'roots.json')
    if run(os.path.join(HERE, 'build.py'), '--data-root', roots, '--out', built, '--only', REMOTE):
        sys.exit('build failed')
    rep_b = os.path.join(WORK, 'verify_remote_built.json')
    if run(os.path.join(HERE, 'verify.py'), '--data-root', roots, '--qa', built, '--report', rep_b):
        sys.exit('verify failed: not uploading')
    if run(os.path.join(HERE, 'package.py'), '--built', built, '--pkg', PKG, '--private', private):
        sys.exit('package failed')
    reps = [os.path.join(PKG, 'scripts', 'verify_cloud_dev.json'), os.path.join(PKG, 'scripts', 'verify_cloud_test.json'), rep_b]
    run(os.path.join(HERE, 'make_readme.py'), '--pkg', PKG, '--date', datetime.date.today().isoformat(), '--reports', *[r for r in reps if os.path.exists(r)])
    print('private test answers for the new sets:', os.path.join(private, 'test_answers'), '(do not upload)')
    if '--no-upload' in sys.argv:
        return
    from huggingface_hub import HfApi
    api = HfApi()
    api.create_repo('Lilambd/empire-eval', repo_type='dataset', exist_ok=True, private=False)
    api.upload_folder(repo_id='Lilambd/empire-eval', repo_type='dataset', folder_path=PKG, commit_message='Publish Lilambd Empire Eval',
                      ignore_patterns=['**/__pycache__/**', '*.cmd'])
    print('OK  https://huggingface.co/datasets/Lilambd/empire-eval')


if __name__ == '__main__':
    main()