From 54e7cb4d8b6d0955e278fbe6c0bc713d09e1828b Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 6 Feb 2020 15:52:23 +1100 Subject: [PATCH] docs: Require UTF-8 as default encoding to build docs Making everything work for both docs & non-docs builds with Py2 is too fiddly otherwise. --- docs/build_docs.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/build_docs.py b/docs/build_docs.py index cf6ef6ec31..8581231257 100755 --- a/docs/build_docs.py +++ b/docs/build_docs.py @@ -11,6 +11,7 @@ # from __future__ import print_function import argparse +import locale import math import multiprocessing import os @@ -50,6 +51,14 @@ def main(): except subprocess.CalledProcessError: raise SystemExit(2) # stdout will already have these errors + # This is not the only way to make sure that all files opened by Python are treated as UTF-8, but the other way is passing encoding='utf-8' to all open() + # functions and this way makes Python 2 compatibility really tough if there is any code that assumes text files contain strings (kconfiglib assumes this). + # The reason for that is that you need to import io.open() to support the encoding argument on Python 2, and this function always uses Py2's unicode + # type not the str type. + if 'UTF-8' not in locale.getlocale(): + raise RuntimeError("build_docs.py requires the default locale's encoding to be UTF-8. " + + "Setting environment variable LC_ALL=C.UTF-8 when running build_docs.py may be enough to fix this.") + parser = argparse.ArgumentParser(description='build_docs.py: Build IDF docs', prog='build_docs.py') parser.add_argument("--language", "-l", choices=LANGUAGES, required=False)