From 95761c5023967625b0e4b28bc4b490fbfb7a5604 Mon Sep 17 00:00:00 2001 From: Jay Kamat Date: Tue, 17 Oct 2017 10:36:37 -0400 Subject: [PATCH] Fix crashes on qute_pylint module when not running in the root Useful for editors that run from non-root directories for integrations, but skips some tests. Shouldn't impact tests run normally. --- .../dev/pylint_checkers/qute_pylint/config.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/scripts/dev/pylint_checkers/qute_pylint/config.py b/scripts/dev/pylint_checkers/qute_pylint/config.py index df08e6833..3b29942e3 100644 --- a/scripts/dev/pylint_checkers/qute_pylint/config.py +++ b/scripts/dev/pylint_checkers/qute_pylint/config.py @@ -27,9 +27,11 @@ import yaml import astroid from pylint import interfaces, checkers from pylint.checkers import utils +from pathlib import Path OPTIONS = None +FAILED_LOAD = False class ConfigChecker(checkers.BaseChecker): @@ -44,6 +46,7 @@ class ConfigChecker(checkers.BaseChecker): None), } priority = -1 + printed_warning = False @utils.check_messages('bad-config-option') def visit_attribute(self, node): @@ -58,6 +61,13 @@ class ConfigChecker(checkers.BaseChecker): def _check_config(self, node, name): """Check that we're accessing proper config options.""" + if FAILED_LOAD: + if not ConfigChecker.printed_warning: + print("[WARN] Could not find configdata.yml. Please run " + + "pylint from qutebrowser root.", file=sys.stderr) + print("Skipping some checks...", file=sys.stderr) + ConfigChecker.printed_warning = True + return if name not in OPTIONS: self.add_message('bad-config-option', node=node, args=name) @@ -66,6 +76,11 @@ def register(linter): """Register this checker.""" linter.register_checker(ConfigChecker(linter)) global OPTIONS - yaml_file = os.path.join('qutebrowser', 'config', 'configdata.yml') - with open(yaml_file, 'r', encoding='utf-8') as f: + global FAILED_LOAD + yaml_file = Path('qutebrowser') / 'config' / 'configdata.yml' + if not yaml_file.exists(): + OPTIONS = None + FAILED_LOAD = True + return + with yaml_file.open(mode='r', encoding='utf-8') as f: OPTIONS = list(yaml.load(f))