diff options
Diffstat (limited to '')
-rw-r--r-- | utils/babel_runner.py | 39 | ||||
-rwxr-xr-x | utils/bump_docker.py | 9 | ||||
-rwxr-xr-x | utils/generate_js_fixtures.py | 39 | ||||
-rw-r--r-- | utils/release-checklist.rst | 4 |
4 files changed, 70 insertions, 21 deletions
diff --git a/utils/babel_runner.py b/utils/babel_runner.py index b66425f..4cb3532 100644 --- a/utils/babel_runner.py +++ b/utils/babel_runner.py @@ -31,6 +31,7 @@ from babel.messages.pofile import read_po, write_po from babel.util import pathmatch from jinja2.ext import babel_extract as extract_jinja2 +IS_CI = 'CI' in os.environ ROOT = os.path.realpath(os.path.join(os.path.abspath(__file__), '..', '..')) TEX_DELIMITERS = { 'variable_start_string': '<%=', @@ -42,7 +43,9 @@ METHOD_MAP = [ # Extraction from Python source files ('**.py', extract_python), # Extraction from Jinja2 template files + ('**/templates/latex/**.tex.jinja', extract_jinja2), ('**/templates/latex/**.tex_t', extract_jinja2), + ('**/templates/latex/**.sty.jinja', extract_jinja2), ('**/templates/latex/**.sty_t', extract_jinja2), # Extraction from Jinja2 HTML templates ('**/themes/**.html', extract_jinja2), @@ -50,6 +53,7 @@ METHOD_MAP = [ ('**/themes/**.xml', extract_jinja2), # Extraction from JavaScript files ('**.js', extract_javascript), + ('**.js.jinja', extract_javascript), ('**.js_t', extract_javascript), ] OPTIONS_MAP = { @@ -58,7 +62,9 @@ OPTIONS_MAP = { 'encoding': 'utf-8', }, # Extraction from Jinja2 template files + '**/templates/latex/**.tex.jinja': TEX_DELIMITERS.copy(), '**/templates/latex/**.tex_t': TEX_DELIMITERS.copy(), + '**/templates/latex/**.sty.jinja': TEX_DELIMITERS.copy(), '**/templates/latex/**.sty_t': TEX_DELIMITERS.copy(), # Extraction from Jinja2 HTML templates '**/themes/**.html': { @@ -180,11 +186,10 @@ def run_compile() -> None: log.info('catalog %s is marked as fuzzy, skipping', po_file) continue + locale_errors = 0 for message, errors in catalog.check(): - if locale not in total_errors: - total_errors[locale] = 0 for error in errors: - total_errors[locale] += 1 + locale_errors += 1 log.error( 'error: %s:%d: %s\nerror: in message string: %r', po_file, @@ -193,6 +198,11 @@ def run_compile() -> None: message.string, ) + if locale_errors: + total_errors[locale] = locale_errors + log.info('%d errors encountered in %r locale, skipping', locale_errors, locale) + continue + mo_file = os.path.join(directory, locale, 'LC_MESSAGES', 'sphinx.mo') log.info('compiling catalog %s to %s', po_file, mo_file) with open(mo_file, 'wb') as outfile: @@ -224,17 +234,13 @@ def run_compile() -> None: # to ensure lines end with ``\n`` rather than ``\r\n``: outfile.write(f'Documentation.addTranslations({obj});'.encode()) - if 'ta' in total_errors: - # Tamil is a known failure. - err_count = total_errors.pop('ta') - log.error('%d errors encountered in %r locale.', err_count, 'ta') - - if len(total_errors) > 0: + if total_errors: + _write_pr_body_line('## Babel catalogue errors') + _write_pr_body_line('') for locale, err_count in total_errors.items(): - log.error('%d errors encountered in %r locale.', err_count, locale) - log.error('%d errors encountered.', sum(total_errors.values())) - print('Compiling failed.', file=sys.stderr) - raise SystemExit(2) + log.error('error: %d errors encountered in %r locale.', err_count, locale) + s = 's' if err_count != 1 else '' + _write_pr_body_line(f'* {locale}: {err_count} error{s}') def _get_logger(): @@ -246,6 +252,13 @@ def _get_logger(): return log +def _write_pr_body_line(message: str) -> None: + if not IS_CI: + return + with open('babel_compile.txt', 'a', encoding='utf-8') as f: + f.write(f'{message}\n') + + if __name__ == '__main__': try: action = sys.argv[1].lower() diff --git a/utils/bump_docker.py b/utils/bump_docker.py index 8f385ae..570e5ec 100755 --- a/utils/bump_docker.py +++ b/utils/bump_docker.py @@ -26,8 +26,8 @@ SPHINX_VERSION_PREFIX = 'Sphinx==' for file in DOCKERFILE_BASE, DOCKERFILE_LATEXPDF: content = file.read_text(encoding='utf-8') content = re.sub( - rf'{re.escape(OPENCONTAINERS_VERSION_PREFIX)} = "{VERSION_PATTERN}"', - rf'{OPENCONTAINERS_VERSION_PREFIX} = "{VERSION}"', + rf'{re.escape(OPENCONTAINERS_VERSION_PREFIX)}="{VERSION_PATTERN}"', + rf'{OPENCONTAINERS_VERSION_PREFIX}="{VERSION}"', content, ) content = re.sub( @@ -39,16 +39,13 @@ for file in DOCKERFILE_BASE, DOCKERFILE_LATEXPDF: def git(*args: str) -> None: - ret = subprocess.run( + subprocess.run( ('git', *args), - capture_output=True, cwd=DOCKER_ROOT, check=True, text=True, encoding='utf-8', ) - print(ret.stdout) - print(ret.stderr, file=sys.stderr) git('checkout', 'master') diff --git a/utils/generate_js_fixtures.py b/utils/generate_js_fixtures.py new file mode 100755 index 0000000..4e12689 --- /dev/null +++ b/utils/generate_js_fixtures.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +import shutil +import subprocess +from pathlib import Path + +SPHINX_ROOT = Path(__file__).resolve().parent.parent +TEST_JS_FIXTURES = SPHINX_ROOT / 'tests' / 'js' / 'fixtures' +TEST_JS_ROOTS = [ + directory + for directory in (SPHINX_ROOT / 'tests' / 'js' / 'roots').iterdir() + if (directory / 'conf.py').exists() +] + + +def build(srcdir: Path) -> None: + cmd = ( + 'sphinx-build', + '--fresh-env', + '--quiet', + *('--builder', 'html'), + f'{srcdir}', + f'{srcdir}/_build', + ) + subprocess.run(cmd, check=True, capture_output=True) + + +for directory in TEST_JS_ROOTS: + searchindex = directory / '_build' / 'searchindex.js' + destination = TEST_JS_FIXTURES / directory.name / 'searchindex.js' + + print(f'Building {directory} ... ', end='') + build(directory) + print('done') + + print(f'Copying {searchindex} to {destination} ... ', end='') + destination.parent.mkdir(exist_ok=True, parents=True) + shutil.copy2(searchindex, destination) + print('done') diff --git a/utils/release-checklist.rst b/utils/release-checklist.rst index 5aabbce..2a16966 100644 --- a/utils/release-checklist.rst +++ b/utils/release-checklist.rst @@ -49,12 +49,12 @@ Bump to next development version for stable and major releases ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -* ``python utils/bump_version.py --in-develop X.Y.Z+1b0`` (ex. 1.5.3b0) +* ``python utils/bump_version.py --in-develop X.Y.Z+1b0`` (e.g. 1.5.3b0) for beta releases ~~~~~~~~~~~~~~~~~ -* ``python utils/bump_version.py --in-develop X.Y.0bN+1`` (ex. 1.6.0b2) +* ``python utils/bump_version.py --in-develop X.Y.0bN+1`` (e.g. 1.6.0b2) Commit version bump ------------------- |