serde.inspect
pyserde inspection tool.
Usage
$ python -m serde.inspect <PATH> <NAME>
PATH Python script path.
NAME Pyserde class name.
1""" 2pyserde inspection tool. 3 4#### Usage 5 6``` 7$ python -m serde.inspect <PATH> <NAME> 8 9 PATH Python script path. 10 NAME Pyserde class name. 11``` 12 13""" 14 15import argparse 16import importlib 17import logging 18import os 19import sys 20 21from typing import Any 22 23from .core import SERDE_SCOPE, init, logger 24 25init(True) 26 27 28def inspect(cls: type[Any]) -> None: 29 """ 30 Inspect a pyserde class. 31 """ 32 scope = getattr(cls, SERDE_SCOPE, {}) 33 print(scope) 34 35 36def main(arg: Any) -> None: 37 """ 38 Main entrypoint of `serde.inspect`. 39 """ 40 if arg.verbose: 41 logging.basicConfig(level=logging.DEBUG) 42 43 try: 44 import black 45 46 assert black 47 except ImportError: 48 logger.warning( 49 ( 50 'Tips: Installing "black" makes the output prettier! Try this command:\n' 51 "pip install back" 52 ) 53 ) 54 55 dir = os.path.dirname(arg.path) 56 mod = os.path.basename(arg.path)[:-3] 57 print(f"Loading {mod}.{arg.name} from {dir}/{mod}.py") 58 sys.path.append(dir) 59 pkg = importlib.import_module(mod) 60 cls = getattr(pkg, arg.name) 61 inspect(cls) 62 63 64parser = argparse.ArgumentParser(description="pyserde-inspect") 65parser.add_argument("path", type=str, help="Python script path.") 66parser.add_argument("name", type=str, help="Pyserde class name.") 67parser.add_argument("-v", dest="verbose", action="store_true", help="Enable debug logging.") 68 69 70if __name__ == "__main__": 71 args = parser.parse_args() 72 main(args)
def
inspect(cls: type[typing.Any]) -> None:
29def inspect(cls: type[Any]) -> None: 30 """ 31 Inspect a pyserde class. 32 """ 33 scope = getattr(cls, SERDE_SCOPE, {}) 34 print(scope)
Inspect a pyserde class.
def
main(arg: Any) -> None:
37def main(arg: Any) -> None: 38 """ 39 Main entrypoint of `serde.inspect`. 40 """ 41 if arg.verbose: 42 logging.basicConfig(level=logging.DEBUG) 43 44 try: 45 import black 46 47 assert black 48 except ImportError: 49 logger.warning( 50 ( 51 'Tips: Installing "black" makes the output prettier! Try this command:\n' 52 "pip install back" 53 ) 54 ) 55 56 dir = os.path.dirname(arg.path) 57 mod = os.path.basename(arg.path)[:-3] 58 print(f"Loading {mod}.{arg.name} from {dir}/{mod}.py") 59 sys.path.append(dir) 60 pkg = importlib.import_module(mod) 61 cls = getattr(pkg, arg.name) 62 inspect(cls)
Main entrypoint of serde.inspect
.
parser =
ArgumentParser(prog='pdoc', usage=None, description='pyserde-inspect', formatter_class=<class 'argparse.HelpFormatter'>, conflict_handler='error', add_help=True)