|
29 | 29 | from pytorch_lightning import Callback, LightningDataModule, LightningModule, seed_everything, Trainer
|
30 | 30 | from pytorch_lightning.utilities.cloud_io import get_filesystem
|
31 | 31 | from pytorch_lightning.utilities.exceptions import MisconfigurationException
|
32 |
| -from pytorch_lightning.utilities.imports import _JSONARGPARSE_AVAILABLE |
| 32 | +from pytorch_lightning.utilities.imports import _DOCSTRING_PARSER_AVAILABLE, _JSONARGPARSE_AVAILABLE |
33 | 33 | from pytorch_lightning.utilities.meta import get_all_subclasses
|
34 | 34 | from pytorch_lightning.utilities.model_helpers import is_overridden
|
35 | 35 | from pytorch_lightning.utilities.rank_zero import _warn, rank_zero_warn
|
36 | 36 | from pytorch_lightning.utilities.types import LRSchedulerType, LRSchedulerTypeTuple, LRSchedulerTypeUnion
|
37 | 37 |
|
38 | 38 | if _JSONARGPARSE_AVAILABLE:
|
39 | 39 | from jsonargparse import ActionConfigFile, ArgumentParser, class_from_function, Namespace, set_config_read_mode
|
40 |
| - from jsonargparse.optionals import import_docstring_parse |
41 | 40 |
|
42 | 41 | set_config_read_mode(fsspec_enabled=True)
|
43 | 42 | else:
|
44 | 43 | locals()["ArgumentParser"] = object
|
45 | 44 | locals()["Namespace"] = object
|
46 | 45 |
|
| 46 | +if _DOCSTRING_PARSER_AVAILABLE: |
| 47 | + import docstring_parser |
| 48 | + |
47 | 49 |
|
48 | 50 | class _Registry(dict):
|
49 | 51 | def __call__(self, cls: Type, key: Optional[str] = None, override: bool = False) -> Type:
|
@@ -888,9 +890,13 @@ def instantiate_class(args: Union[Any, Tuple[Any, ...]], init: Dict[str, Any]) -
|
888 | 890 |
|
889 | 891 |
|
890 | 892 | def _get_short_description(component: object) -> Optional[str]:
|
891 |
| - parse, _ = import_docstring_parse("LightningCLI(run=True)") |
892 |
| - try: |
893 |
| - docstring = parse(component.__doc__) |
894 |
| - return docstring.short_description |
895 |
| - except ValueError: |
896 |
| - rank_zero_warn(f"Failed parsing docstring for {component}") |
| 893 | + if component.__doc__ is None: |
| 894 | + return None |
| 895 | + if not _DOCSTRING_PARSER_AVAILABLE: |
| 896 | + rank_zero_warn(f"Failed parsing docstring for {component}: docstring-parser package is required") |
| 897 | + else: |
| 898 | + try: |
| 899 | + docstring = docstring_parser.parse(component.__doc__) |
| 900 | + return docstring.short_description |
| 901 | + except (ValueError, docstring_parser.ParseError) as ex: |
| 902 | + rank_zero_warn(f"Failed parsing docstring for {component}: {ex}") |
0 commit comments