Skip to content

Commit 1b8cf82

Browse files
build autobuild all languages
1 parent 4ddccd2 commit 1b8cf82

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

conf.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
copyright = f"{current_year}, {organization_name}"
2727
author = "pyOpenSci Community"
2828

29+
language = "en"
30+
languages = ["es", "jp"]
31+
# languages excluding english
32+
# (english is built without a subdirectory to not break already-existing inbound links)
33+
2934
# Get the latest Git tag - there might be a prettier way to do this but...
3035
try:
3136
release_value = (
@@ -117,6 +122,8 @@
117122
"github_user": "pyopensci",
118123
"github_repo": "python-package-guide",
119124
"github_version": "main",
125+
'language': language,
126+
'languages': languages
120127
}
121128

122129
# Add any paths that contain templates here, relative to this directory.

noxfile.py

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import pathlib
33
import shutil
44
import 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

612
nox.options.reuse_existing_virtualenvs = True
713

@@ -43,7 +49,7 @@
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)
4955
RELEASE_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")
7688
def 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")
133173
def clean_dir(session):

0 commit comments

Comments
 (0)