Repository: incubator-airflow Updated Branches: refs/heads/v1-10-test f123cf5f8 -> f4bcc3356
[AIRFLOW-2739] Always read default configuration files as utf-8 Closes #3593 from cjgu/airflow-2739 (cherry picked from commit 78da52fee477b0f7b2ee3481d32a06fca7a9841c) Signed-off-by: Bolke de Bruin <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/f4bcc335 Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/f4bcc335 Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/f4bcc335 Branch: refs/heads/v1-10-test Commit: f4bcc33564d68b2146fb4fbf6a08f20326069306 Parents: f123cf5 Author: Carl Johan Gustavsson <[email protected]> Authored: Fri Jul 13 11:58:39 2018 +0200 Committer: Bolke de Bruin <[email protected]> Committed: Fri Jul 13 11:58:53 2018 +0200 ---------------------------------------------------------------------- airflow/configuration.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/f4bcc335/airflow/configuration.py ---------------------------------------------------------------------- diff --git a/airflow/configuration.py b/airflow/configuration.py index e2089e5..2e05fde 100644 --- a/airflow/configuration.py +++ b/airflow/configuration.py @@ -101,15 +101,20 @@ def run_command(command): return output -_templates_dir = os.path.join(os.path.dirname(__file__), 'config_templates') -with open(os.path.join(_templates_dir, 'default_airflow.cfg')) as f: - DEFAULT_CONFIG = f.read() +def _read_default_config_file(file_name): + templates_dir = os.path.join(os.path.dirname(__file__), 'config_templates') + file_path = os.path.join(templates_dir, file_name) if six.PY2: - DEFAULT_CONFIG = DEFAULT_CONFIG.decode('utf-8') -with open(os.path.join(_templates_dir, 'default_test.cfg')) as f: - TEST_CONFIG = f.read() - if six.PY2: - TEST_CONFIG = TEST_CONFIG.decode('utf-8') + with open(file_path) as f: + config = f.read() + return config.decode('utf-8') + else: + with open(file_path, encoding='utf-8') as f: + return f.read() + + +DEFAULT_CONFIG = _read_default_config_file('default_airflow.cfg') +TEST_CONFIG = _read_default_config_file('default_test.cfg') class AirflowConfigParser(ConfigParser): @@ -502,8 +507,7 @@ conf.read(AIRFLOW_CONFIG) if conf.getboolean('webserver', 'rbac'): - with open(os.path.join(_templates_dir, 'default_webserver_config.py')) as f: - DEFAULT_WEBSERVER_CONFIG = f.read() + DEFAULT_WEBSERVER_CONFIG = _read_default_config_file('default_webserver_config.py') WEBSERVER_CONFIG = AIRFLOW_HOME + '/webserver_config.py'
