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:
parent
5c6a821b1e
commit
95761c5023
@ -27,9 +27,11 @@ import yaml
|
|||||||
import astroid
|
import astroid
|
||||||
from pylint import interfaces, checkers
|
from pylint import interfaces, checkers
|
||||||
from pylint.checkers import utils
|
from pylint.checkers import utils
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
OPTIONS = None
|
OPTIONS = None
|
||||||
|
FAILED_LOAD = False
|
||||||
|
|
||||||
|
|
||||||
class ConfigChecker(checkers.BaseChecker):
|
class ConfigChecker(checkers.BaseChecker):
|
||||||
@ -44,6 +46,7 @@ class ConfigChecker(checkers.BaseChecker):
|
|||||||
None),
|
None),
|
||||||
}
|
}
|
||||||
priority = -1
|
priority = -1
|
||||||
|
printed_warning = False
|
||||||
|
|
||||||
@utils.check_messages('bad-config-option')
|
@utils.check_messages('bad-config-option')
|
||||||
def visit_attribute(self, node):
|
def visit_attribute(self, node):
|
||||||
@ -58,6 +61,13 @@ class ConfigChecker(checkers.BaseChecker):
|
|||||||
|
|
||||||
def _check_config(self, node, name):
|
def _check_config(self, node, name):
|
||||||
"""Check that we're accessing proper config options."""
|
"""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:
|
if name not in OPTIONS:
|
||||||
self.add_message('bad-config-option', node=node, args=name)
|
self.add_message('bad-config-option', node=node, args=name)
|
||||||
|
|
||||||
@ -66,6 +76,11 @@ def register(linter):
|
|||||||
"""Register this checker."""
|
"""Register this checker."""
|
||||||
linter.register_checker(ConfigChecker(linter))
|
linter.register_checker(ConfigChecker(linter))
|
||||||
global OPTIONS
|
global OPTIONS
|
||||||
yaml_file = os.path.join('qutebrowser', 'config', 'configdata.yml')
|
global FAILED_LOAD
|
||||||
with open(yaml_file, 'r', encoding='utf-8') as f:
|
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))
|
OPTIONS = list(yaml.load(f))
|
||||||
|
Loading…
Reference in New Issue
Block a user