Skip to content

Commit a2a73c4

Browse files
committed
Rename translation session in noxfile.py
1 parent 5139bc7 commit a2a73c4

File tree

1 file changed

+47
-44
lines changed

1 file changed

+47
-44
lines changed

noxfile.py

Lines changed: 47 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def docs(session):
5555
session.install("-e", ".")
5656
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, SOURCE_DIR, OUTPUT_DIR, *session.posargs)
5757
# When building the guide, also build the translations in RELEASE_LANGUAGES
58-
session.notify("build-translations", ['release-build'])
58+
session.notify("build-release-languages", session.posargs)
5959

6060

6161
@nox.session(name="docs-test")
@@ -69,7 +69,7 @@ def docs_test(session):
6969
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, *TEST_PARAMETERS, SOURCE_DIR, OUTPUT_DIR, *session.posargs)
7070
# When building the guide with additional parameters, also build the translations in RELEASE_LANGUAGES
7171
# with those same parameters.
72-
session.notify("build-translations", ['release-build', *TEST_PARAMETERS])
72+
session.notify("build-release-languages", [*TEST_PARAMETERS, *session.posargs])
7373

7474

7575
@nox.session(name="docs-live")
@@ -142,8 +142,8 @@ def clean_dir(session):
142142
pathlib.Path(content).unlink()
143143

144144

145-
@nox.session(name="update-translations")
146-
def update_translations(session):
145+
@nox.session(name="update-release-languages")
146+
def update_release_languages(session):
147147
"""
148148
Update the translation files (./locales/*/.po) for languages in RELEASE_LANGUAGES.
149149
@@ -189,60 +189,63 @@ def update_language(session):
189189
f" where LANG is one of: {LANGUAGES}"
190190
)
191191

192-
193-
@nox.session(name="build-languages")
194-
def build_languages(session):
192+
@nox.session(name="build-language")
193+
def build_language(session):
195194
"""
196-
Build the translations of the guide for the specified language.
195+
Build the guide for a specific language translation
197196
198-
Note: This sessions expects a list of languages to build in the first position of the session arguments.
199-
It does not need to be called directly, it is started by build_translations session.
197+
For example: nox -s build-language -- es.
200198
"""
201-
if not session.posargs:
202-
session.error("Please provide the list of languages to build the translation for")
203-
languages_to_build = session.posargs.pop(0)
199+
if session.posargs and (lang := session.posargs.pop(0)):
200+
if lang in LANGUAGES:
201+
session.install("-e", ".")
202+
session.log(f"Building [{lang}] guide")
203+
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, "-D", f"language={lang}", ".", OUTPUT_DIR / lang, *session.posargs)
204+
else:
205+
session.error(f"Language {lang} is not in LANGUAGES list.")
206+
else:
207+
session.error(
208+
"Please provide a language using:\n\n "
209+
"nox -s build-language -- LANG\n\n "
210+
f" where LANG is one of: {LANGUAGES}"
211+
)
204212

213+
214+
@nox.session(name="build-release-languages")
215+
def build_release_languages(session):
216+
"""
217+
Build the translations of the guide for the languages in RELEASE_LANGUAGES.
218+
"""
219+
if not RELEASE_LANGUAGES:
220+
session.warn("No release languages defined in RELEASE_LANGUAGES")
221+
return
205222
session.install("-e", ".")
206-
for lang in languages_to_build:
207-
if lang not in LANGUAGES:
208-
session.warn(f"Language [{lang}] is not available for translation")
209-
continue
223+
for lang in RELEASE_LANGUAGES:
210224
session.log(f"Building [{lang}] guide")
211225
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, "-D", f"language={lang}", ".", OUTPUT_DIR / lang, *session.posargs)
226+
session.log(f"Translations built for {RELEASE_LANGUAGES}")
212227

213-
214-
@nox.session(name="build-translations")
215-
def build_translations(session):
228+
@nox.session(name="build-all-languages")
229+
def build_all_languages(session):
216230
"""
217-
Build translations of the guide.
218-
219-
Note: this session can be called directly to build all available translations (defined in LANGUAGES).
220-
It is also called by the docs and docs-test sessions with 'release-build' as the first positional
221-
argument, to build only the translations defined in RELEASE_LANGUAGES.
231+
Build the translations of the guide for the languages in LANGUAGES.
222232
"""
223-
release_build = False
224-
if session.posargs and session.posargs[0] == 'release-build':
225-
session.posargs.pop(0)
226-
release_build = True
227-
# if running from the docs or docs-test sessions, build only release languages
228-
BUILD_LANGUAGES = RELEASE_LANGUAGES if release_build else LANGUAGES
229-
# only build languages that have a locale folder
230-
BUILD_LANGUAGES = [lang for lang in BUILD_LANGUAGES if (TRANSLATION_LOCALES_DIR / lang).exists()]
231-
session.log(f"Declared languages: {LANGUAGES}")
232-
session.log(f"Release languages: {RELEASE_LANGUAGES}")
233-
session.log(f"Building languages{' for release' if release_build else ''}: {BUILD_LANGUAGES}")
234-
if not BUILD_LANGUAGES:
235-
session.warn("No translations to build")
236-
else:
237-
session.notify("build-languages", [BUILD_LANGUAGES, *session.posargs])
233+
if not LANGUAGES:
234+
session.warn("No languages defined in LANGUAGES")
235+
return
236+
session.install("-e", ".")
237+
for lang in LANGUAGES:
238+
session.log(f"Building [{lang}] guide")
239+
session.run(SPHINX_BUILD, *BUILD_PARAMETERS, "-D", f"language={lang}", ".", OUTPUT_DIR / lang, *session.posargs)
240+
session.log(f"Translations built for {LANGUAGES}")
238241

239242

240-
@nox.session(name="build-translations-test")
241-
def build_translations_test(session):
243+
@nox.session(name="build-all-languages-test")
244+
def build_all_languages_test(session):
242245
"""
243-
Build all translations of the guide with testing parameters.
246+
Build all translations of the guide with the testing parameters.
244247
245248
This is a convenience session to test the build of all translations with the testing parameters
246249
in the same way docs-test does for the English version.
247250
"""
248-
session.notify("build-translations", [*TEST_PARAMETERS])
251+
session.notify("build-all-languages", [*TEST_PARAMETERS])

0 commit comments

Comments
 (0)