|
| 1 | +import glob |
| 2 | +from pathlib import Path |
| 3 | +import shutil |
| 4 | +import subprocess |
| 5 | +import os |
| 6 | +import time |
| 7 | +from get_files_to_run import remove_other_files, compute_files_to_keep, calculate_shards, get_all_files |
| 8 | +from validate_tutorials_built import NOT_RUN |
| 9 | + |
| 10 | +def print_files(files): |
| 11 | + print(f"Files to run ({len(files)}):") |
| 12 | + for file in files: |
| 13 | + print(f"- {file}") |
| 14 | + |
| 15 | + |
| 16 | +def main() -> None: |
| 17 | + all_files = get_all_files() |
| 18 | + files_to_run = calculate_shards(all_files, num_shards=15)[int(os.environ.get("WORKER_ID", "1")) - 1] |
| 19 | + files_to_run = [x for x in files_to_run if x not in [f"{f}.py" for f in NOT_RUN]] |
| 20 | + |
| 21 | + os.makedirs("/tmp/docs_to_zip", exist_ok=True) |
| 22 | + |
| 23 | + env = os.environ.copy() |
| 24 | + for file in files_to_run: |
| 25 | + print(f"Running {file}") |
| 26 | + start = time.time() |
| 27 | + remove_other_files(all_files, compute_files_to_keep([file])) |
| 28 | + stem = Path(file).stem |
| 29 | + env["RUNTHIS"] = stem |
| 30 | + env["FILES_TO_RUN"] = stem |
| 31 | + |
| 32 | + subprocess.check_output(["make", "download"], env=env) |
| 33 | + result = subprocess.check_output(["make", "html"], env=env) |
| 34 | + print(result.decode("utf-8")) |
| 35 | + subprocess.check_output(["make", "postprocess"], env=env) |
| 36 | + print("Done running") |
| 37 | + for file in glob.glob(f"docs/**/*", recursive=True): |
| 38 | + if stem in file: |
| 39 | + relative_path = Path(os.path.relpath(file, "docs")) |
| 40 | + print(relative_path) |
| 41 | + print(relative_path.parent) |
| 42 | + os.makedirs(os.path.dirname(f"/tmp/docs_to_zip/{relative_path}"), exist_ok=True) |
| 43 | + shutil.copy(file, f"/tmp/docs_to_zip/{relative_path}") |
| 44 | + subprocess.check_output(["git", "reset", "--hard", "HEAD"]) |
| 45 | + subprocess.check_output(["git", "clean", "-f", "-d"]) |
| 46 | + print(f"Done with {file} in {time.time() - start:.2f} seconds") |
| 47 | + |
| 48 | + shutil.rmtree("_build") |
| 49 | + os.makedirs("_build", exist_ok=True) |
| 50 | + shutil.move("/tmp/docs_to_zip", "_build/html") |
| 51 | + |
| 52 | +if __name__ == "__main__": |
| 53 | + main() |
0 commit comments