22import pathlib
33import shutil
44import nox
5+ import sys
6+ import subprocess
7+
8+ # for some reason necessary to correctly import conf from cwd
9+ sys .path .insert (0 , str (pathlib .Path (__file__ ).parent .absolute ()))
10+ import conf
511
612nox .options .reuse_existing_virtualenvs = True
713
4349## Localization options (translations)
4450
4551# List of languages for which locales will be generated in (/locales/<lang>)
46- LANGUAGES = [ "es" , "ja" ]
52+ LANGUAGES = conf . languages
4753
4854# List of languages that should be built when releasing the guide (docs or docs-test sessions)
4955RELEASE_LANGUAGES = []
@@ -71,6 +77,12 @@ def docs_test(session):
7177 # with those same parameters.
7278 session .notify ("build-translations" , ['release-build' , * TEST_PARAMETERS ])
7379
80+ def _autobuild_cmd (posargs : list [str ], output_dir = OUTPUT_DIR ) -> list [str ]:
81+ cmd = [SPHINX_AUTO_BUILD , * BUILD_PARAMETERS , str (SOURCE_DIR ), str (output_dir ), * posargs ]
82+ for folder in AUTOBUILD_IGNORE :
83+ cmd .extend (["--ignore" , f"*/{ folder } /*" ])
84+ return cmd
85+
7486
7587@nox .session (name = "docs-live" )
7688def docs_live (session ):
@@ -88,9 +100,7 @@ def docs_live(session):
88100 so they don't need to remember the specific sphinx-build parameters to build a different language.
89101 """
90102 session .install ("-e" , "." )
91- cmd = [SPHINX_AUTO_BUILD , * BUILD_PARAMETERS , SOURCE_DIR , OUTPUT_DIR , * session .posargs ]
92- for folder in AUTOBUILD_IGNORE :
93- cmd .extend (["--ignore" , f"*/{ folder } /*" ])
103+ cmd = _autobuild_cmd (session .posargs )
94104 # This part was commented in the previous version of the nox file, keeping the same here
95105 # for folder in AUTOBUILD_INCLUDE:
96106 # cmd.extend(["--watch", folder])
@@ -128,6 +138,36 @@ def docs_live_lang(session):
128138 f"where LANG is one of: { LANGUAGES } "
129139 )
130140
141+ @nox .session (name = "docs-live-langs" )
142+ def docs_live_langs (session ):
143+ """
144+ Like docs-live but build all languages simultaneously
145+
146+ Requires concurrently to run (npm install -g concurrently)
147+ """
148+ try :
149+ subprocess .check_call (['concurrently' ], stdout = subprocess .DEVNULL , stderr = subprocess .DEVNULL )
150+ except subprocess .CalledProcessError :
151+ # handle errors in the called executable
152+ # (aka, was found)
153+ pass
154+ except OSError :
155+ session .error ('docs-live-langs requires concurrently (npm install -g concurrently)' )
156+
157+ session .install ("-e" , "." )
158+
159+ cmds = ['"' + " " .join (_autobuild_cmd (session .posargs ) + ['--open-browser' ]) + '"' ]
160+ for language in LANGUAGES :
161+ cmds .append (
162+ '"' + " " .join (
163+ _autobuild_cmd (
164+ session .posargs + ["-D" , f"language={ language } " ],
165+ output_dir = OUTPUT_DIR / language
166+ ) + ["--port=0" ]
167+ ) + '"'
168+ )
169+ cmd = ['concurrently' , '--kill-others' , '-n' , ',' .join (['en' ] + LANGUAGES ), '-c' , 'auto' , * cmds ]
170+ session .run (* cmd )
131171
132172@nox .session (name = "docs-clean" )
133173def clean_dir (session ):
0 commit comments