Skip to content

Commit

Permalink
feat: Print Tips in serde.inspect
Browse files Browse the repository at this point in the history
If `black` is installed, pyserde is able to prettify the code to print
  • Loading branch information
yukinarit committed Jul 12, 2021
1 parent 7ee53f5 commit 62c74f3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion serde/inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import sys
from typing import Type

from .core import SERDE_SCOPE, SerdeScope, init
from .core import SERDE_SCOPE, SerdeScope, init, logger

init(True)

Expand All @@ -32,6 +32,14 @@ def inspect(cls: Type) -> None:
def main(arg):
if arg.verbose:
logging.basicConfig(level=logging.DEBUG)

try:
import black

assert black
except ImportError:
logger.warning(('Tips: Installing "black" makes the output prettier! Try this command:\n' 'pip install back'))

dir = os.path.dirname(arg.path)
mod = os.path.basename(arg.path)[:-3]
print(f'Loading {mod}.{arg.name} from {dir}/{mod}.py')
Expand Down

0 comments on commit 62c74f3

Please sign in to comment.