Skip to content

Commit

Permalink
doctor: suggest config documentation in case of ImportError from config
Browse files Browse the repository at this point in the history
doesn't help in all cases but perhaps helpful anyway

relevant: #109
  • Loading branch information
karlicoss committed Feb 2, 2022
1 parent e309531 commit b2a0275
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions my/core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import importlib
import inspect
import os
import re
import sys
import traceback
from typing import Optional, Sequence, Iterable, List, Type, Any, Callable
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b2a0275

Please # to comment.