️ Build docs for languages in parallel in subprocesses to speed up CI (#2242)

This commit is contained in:
Sebastián Ramírez 2020-10-25 12:59:13 +01:00 committed by GitHub
parent cdf0f8a933
commit f88ffd1a0b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 1 deletions

View File

@ -1,6 +1,7 @@
import os import os
import shutil import shutil
from http.server import HTTPServer, SimpleHTTPRequestHandler from http.server import HTTPServer, SimpleHTTPRequestHandler
from multiprocessing import Pool
from pathlib import Path from pathlib import Path
from typing import Dict, Optional, Tuple from typing import Dict, Optional, Tuple
@ -207,10 +208,15 @@ def build_all():
typer.echo(f"Building docs for: en") typer.echo(f"Building docs for: en")
mkdocs.commands.build.build(mkdocs.config.load_config(site_dir=str(site_path))) mkdocs.commands.build.build(mkdocs.config.load_config(site_dir=str(site_path)))
os.chdir(current_dir) os.chdir(current_dir)
langs = []
for lang in get_lang_paths(): for lang in get_lang_paths():
if lang == en_build_path or not lang.is_dir(): if lang == en_build_path or not lang.is_dir():
continue continue
build_lang(lang.name) langs.append(lang.name)
cpu_count = os.cpu_count() or 1
with Pool(cpu_count * 2) as p:
p.map(build_lang, langs)
typer.echo("Copying en index.md to README.md") typer.echo("Copying en index.md to README.md")
en_index = en_build_path / "docs" / "index.md" en_index = en_build_path / "docs" / "index.md"
shutil.copyfile(en_index, "README.md") shutil.copyfile(en_index, "README.md")