# SCons file for Sphinx import sys sys.path.append('./source') import subprocess from pathlib import Path from sphinx.cmd.build import main as sphinx_build import custom doc = Environment( # You can set these variables from the command line. SPHINXOPTS = "", SPHINXBUILD = "sphinx-build", PAPER = "", BUILDDIR = "build") # Internal variables. PAPEROPT_a4 = "-D latex_elements.papersize=a4paper" #PAPEROPT_a4 = "-D latex_paper_size=a4" #PAPEROPT_letter = "-D latex_paper_size=letter" ALLSPHINXOPTS = f"-d {doc['BUILDDIR']}/doctrees {PAPEROPT_a4} {doc['SPHINXOPTS']} source" # the i18n builder cannot share the environment and doctrees with the others I18NSPHINXOPTS = "{PAPEROPT_a4} {SPHINXOPTS} source" # create the banner of the website banner_src = "./source/title_template.svg" banner_tgt = "./source/title.svg" def build_banner(env, target, source): custom.modify_banner(str(source[0]), str(target[0])) banner = doc.Command(banner_tgt, banner_src, Action(build_banner, "Creating the website banner...")) doc.Alias('banner', banner) # convert *.svg and *.gif to *.png # first find all of them src_dir = Path('./source') svg_pictures = list(src_dir.glob('**/*.svg')) gif_pictures = list(src_dir.glob('**/*.gif')) # conversion pictures = [] for f in svg_pictures + banner: pictures += doc.Command(str(f).replace('.svg', '.png'), str(f), Action("convert -background none -density 150 $SOURCE $TARGET", "Converting $SOURCE to PNG...")) for f in gif_pictures: pictures += doc.Command(str(f).replace('.gif', '.png'), str(f), Action("convert -background none -density 150 $SOURCE[0] $TARGET", "Converting $SOURCE to PNG...")) doc.Alias('pictures', pictures) Depends(pictures, banner) # html def html_builder(env, target, source): return sphinx_build(f"-b html {ALLSPHINXOPTS} {doc['BUILDDIR']}/html".split()) html = doc.Command("html.target", [], Action(html_builder, "Building html...")) Depends(html, [banner, pictures]) AlwaysBuild(html) Clean(html, f"{doc['BUILDDIR']}/html") doc.Alias('html', html) # generate sitemap.xml t = f"{doc['BUILDDIR']}/html/sitemap.xml" cmd = f"python source/sitemap-generate.py --url https://msspec.cnrs.fr --path {doc['BUILDDIR']}/html {t}" sitemap = doc.Command(t, [], cmd)#Action(cmd, "Generating sitemap.xml...")) Depends(sitemap, html) doc.Alias('html', sitemap) # install ownership t = f"{doc['BUILDDIR']}/html" s = Glob('source/google*.html') ownership = doc.Install(t, s) Depends(ownership, html) doc.Alias('html', ownership) # LaTeX PDF def latexpdf_builder(env, target, source): rc = sphinx_build(f"-b latex {ALLSPHINXOPTS} {doc['BUILDDIR']}/latex".split()) if rc == 0: subprocess.call(f"make -C {doc['BUILDDIR']}/latex all-pdf".split()) latexpdf = doc.Command("latexpdf.target", [], Action(latexpdf_builder, "Building LaTeX PDF...")) Depends(latexpdf, [banner, pictures]) AlwaysBuild(latexpdf) Clean(latexpdf, f"{doc['BUILDDIR']}/latex") doc.Alias('latexpdf', latexpdf)