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.
This commit is contained in:
Jay Kamat 2017-10-17 10:36:37 -04:00
parent 5c6a821b1e
commit 95761c5023
No known key found for this signature in database
GPG Key ID: 5D2E399600F4F7B5

View File

@ -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))