doctor: suggest config documentation in case of ImportError from config

doesn't help in all cases but perhaps helpful anyway

relevant: https://github.com/karlicoss/HPI/issues/109
This commit is contained in:
Dima Gerasimov 2022-02-02 23:17:07 +00:00 committed by karlicoss
parent d1f791dee8
commit 0e891a267f

View file

@ -2,6 +2,7 @@ import functools
import importlib
import inspect
import os
import re
import sys
import traceback
from typing import Optional, Sequence, Iterable, List, Type, Any, Callable
@ -242,6 +243,14 @@ def modules_check(*, verbose: bool, list_all: bool, quick: bool, for_modules: Li
except Exception as e:
# todo more specific command?
error(f'{click.style("FAIL", fg="red")}: {m:<50} loading failed{vw}')
if isinstance(e, ImportError):
em = re.match(r"cannot import name '(\w+)' from 'my.config'", str(e))
if em is not None:
section_name = em.group(1)
eprint(click.style(f"""\
You're likely missing '{section_name}' section from your config.
See https://github.com/karlicoss/HPI/blob/master/doc/SETUP.org#private-configuration-myconfig\
""", fg='yellow'))
if verbose:
tb(e)
continue