def build_docs()

in scripts/build_docs.py [0:0]


def build_docs(versions, use_yarn):

    for v in versions:
        print(f"Building the docs for version '{v}'...")

        # replace "latest" in redirects to the appropriate version
        if v != "latest":
            for line in fileinput.input("redirects.js", inplace=1):
                print(line.replace("/latest/", f"/{v}/"), end='')

        # set the version in "buildVersion" variable in docusaurus.config.js
        replacement = f'var buildVersion = "{v}";'
        for line in fileinput.input("docusaurus.config.js", inplace=1):
            print(re.sub(r"^var buildVersion.*", replacement, line), end='')

        # build the docs
        if not use_yarn:
            subprocess.run(["npm", "run", "build"])
        else:
            subprocess.run(["yarn", "build"])


        # move output to temporary directory since docusaurus 2
        # overwrites build directory with each build.
        # the "latest" version is built last to maintain
        # all the non-docs content for latest
        source_dir = "build"
        destination_dir = "build__temp"
        if not os.path.isdir(source_dir):
            sys.exit("ERROR: The docs were not built. Check Docusaurus logs.")
        shutil.copytree(source_dir, destination_dir, dirs_exist_ok=True)

        # restore the redirect file back to URLs with "latest"
        #subprocess.run(["git", "restore", "redirects.js"])
        if v != "latest":
            for line in fileinput.input("redirects.js", inplace=1):
                print(line.replace(f"/{v}/", "/latest/"), end='')

    # after all version builds, rename the temp directory back to "build"
    shutil.rmtree(source_dir)
    shutil.move(destination_dir, source_dir)