From a5cd809d4e7d5a630b59e51f8a586d51015fd398 Mon Sep 17 00:00:00 2001 From: Thanh Ha Date: Wed, 24 Jan 2018 19:25:30 -0500 Subject: [PATCH] Update Python linter to lint all docs_conf code Also resolve lint issues. Change-Id: Ifab8d9c3c3cfffab8609cc0740862f2718986aa6 Signed-off-by: Thanh Ha --- .coafile | 2 +- docs_conf/__init__.py | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.coafile b/.coafile index 65c7f3a..413c2e3 100644 --- a/.coafile +++ b/.coafile @@ -21,7 +21,7 @@ bears = BanditBear, PyDocStyleBear, PyFlakesBear, PyImportSortBear -files = conf.py +files = docs_conf/**.py known_first_party_imports = lftools known_third_party_imports = pytest, six pydocstyle_ignore = D203, D213, D301 diff --git a/docs_conf/__init__.py b/docs_conf/__init__.py index d9bda41..6def52a 100644 --- a/docs_conf/__init__.py +++ b/docs_conf/__init__.py @@ -9,22 +9,20 @@ # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-v10.html ############################################################################## -""" -Sphinx Docs Config +"""LF Sphinx Docs Config. -Configure sphinx-doc through an ini file. +Configure sphinx-doc through an YAML file. """ import imp import os.path -import pkg_resources import sphinx_bootstrap_theme import yaml def _merge_yaml(x, y): - """Merges dictionary 'y' into 'x' + """Merge dictionary 'y' into 'x'. This transaction will overwrite existing data values in "y" with values from "x". @@ -35,7 +33,7 @@ def _merge_yaml(x, y): def collect_project_and_config(): - """Pull project and configuration by merging all config sources + """Pull project and configuration by merging all config sources. Order of precedence: @@ -50,7 +48,7 @@ def collect_project_and_config(): raise IOError("No conf.yaml file found at: {}".format(os.getcwd())) with open('conf.yaml', 'r') as f: - local_config = yaml.load(f) + local_config = yaml.safe_load(f) project_cfg = local_config.get('project_cfg', None) @@ -58,18 +56,19 @@ def collect_project_and_config(): default_cfg = os.path.join(docs_path, 'defaults', 'default.yaml') with open(os.path.join(docs_path, default_cfg), 'r') as f: - effective_config = yaml.load(f) + effective_config = yaml.safe_load(f) project_cfg_file = os.path.join(docs_path, 'defaults', '{}.yaml'.format(project_cfg)) if os.path.isfile(project_cfg_file): with open(os.path.join(docs_path, project_cfg_file), 'r') as f: - _project_cfg_data = yaml.load(f) + _project_cfg_data = yaml.safe_load(f) effective_config = _merge_yaml(effective_config, _project_cfg_data) effective_config = _merge_yaml(effective_config, local_config) return effective_config + cfg = collect_project_and_config() # Parse the config and pull in sphinx conf.py settings @@ -92,7 +91,7 @@ todo_include_todos = cfg.get('todo_include_todos', False) html_extra_path = cfg.get('html_extra_path', []) html_favicon = cfg.get('html_favicon', 'favicon.ico') html_logo = cfg.get('html_logo', '_static/logo.png') -html_sidebars = cfg.get('html_sidebars', {'**': ['localtoc.html', 'relations.html'],}) +html_sidebars = cfg.get('html_sidebars', {'**': ['localtoc.html', 'relations.html'], }) html_static_path = cfg.get('html_static_path', ['_static']) html_theme = cfg.get('html_theme', 'bootstrap') html_theme_options = cfg.get('html_theme_options', { -- 2.16.6