xref: /aosp_15_r20/external/bazelbuild-rules_python/sphinxdocs/private/readthedocs_install.py (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1*60517a1eSAndroid Build Coastguard Workerimport os
2*60517a1eSAndroid Build Coastguard Workerimport pathlib
3*60517a1eSAndroid Build Coastguard Workerimport shutil
4*60517a1eSAndroid Build Coastguard Workerimport sys
5*60517a1eSAndroid Build Coastguard Worker
6*60517a1eSAndroid Build Coastguard Workerfrom python import runfiles
7*60517a1eSAndroid Build Coastguard Worker
8*60517a1eSAndroid Build Coastguard Worker
9*60517a1eSAndroid Build Coastguard Workerdef main(args):
10*60517a1eSAndroid Build Coastguard Worker    if not args:
11*60517a1eSAndroid Build Coastguard Worker        raise ValueError("Empty args: expected paths to copy")
12*60517a1eSAndroid Build Coastguard Worker
13*60517a1eSAndroid Build Coastguard Worker    if not (install_to := os.environ.get("READTHEDOCS_OUTPUT")):
14*60517a1eSAndroid Build Coastguard Worker        raise ValueError("READTHEDOCS_OUTPUT environment variable not set")
15*60517a1eSAndroid Build Coastguard Worker
16*60517a1eSAndroid Build Coastguard Worker    install_to = pathlib.Path(install_to)
17*60517a1eSAndroid Build Coastguard Worker
18*60517a1eSAndroid Build Coastguard Worker    rf = runfiles.Create()
19*60517a1eSAndroid Build Coastguard Worker    for doc_dir_runfiles_path in args:
20*60517a1eSAndroid Build Coastguard Worker        doc_dir_path = pathlib.Path(rf.Rlocation(doc_dir_runfiles_path))
21*60517a1eSAndroid Build Coastguard Worker        dest = install_to / doc_dir_path.name
22*60517a1eSAndroid Build Coastguard Worker        print(f"Copying {doc_dir_path} to {dest}")
23*60517a1eSAndroid Build Coastguard Worker        shutil.copytree(src=doc_dir_path, dst=dest, dirs_exist_ok=True)
24*60517a1eSAndroid Build Coastguard Worker
25*60517a1eSAndroid Build Coastguard Worker
26*60517a1eSAndroid Build Coastguard Workerif __name__ == "__main__":
27*60517a1eSAndroid Build Coastguard Worker    sys.exit(main(sys.argv[1:]))
28