Browse Source

add the auto baseclass doc

tags/v0.4.10
ChenXin 5 years ago
parent
commit
9214cc6e36
2 changed files with 27 additions and 7 deletions
  1. +15
    -7
      fastNLP/__init__.py
  2. +12
    -0
      fastNLP/doc_utils.py

+ 15
- 7
fastNLP/__init__.py View File

@@ -14,7 +14,6 @@ __all__ = [
"Instance",
"FieldArray",
"DataSetIter",
"BatchIter",
"TorchLoaderIter",
@@ -29,10 +28,18 @@ __all__ = [
"Callback",
"GradientClipCallback",
"EarlyStopCallback",
"TensorboardCallback",
"FitlogCallback",
"EvaluateCallback",
"LRScheduler",
"ControlC",
"LRFinder",
"TensorboardCallback",
"WarmupCallback",
'SaveModelCallback',
"EchoCallback",
"TesterCallback",
"CallbackException",
"EarlyStopError",
"Padder",
"AutoPadder",
@@ -46,7 +53,7 @@ __all__ = [
"SGD",
"Adam",
"AdamW",
"Sampler",
"SequentialSampler",
"BucketSampler",
@@ -60,17 +67,18 @@ __all__ = [
"LossInForward",
"cache_results",
'logger'
]
__version__ = '0.4.5'

import sys

from . import embeddings
from . import models
from . import modules
from .core import *
from .doc_utils import doc_process
from .io import loader, pipe

import sys
from .doc_utils import doc_process
doc_process(sys.modules[__name__])
doc_process(sys.modules[__name__])

+ 12
- 0
fastNLP/doc_utils.py View File

@@ -25,3 +25,15 @@ def doc_process(m):
if module_name == m.__name__:
# print(name, ": not found defined doc.")
break
if inspect.isclass(obj):
for base in obj.__bases__:
if base.__module__.startswith("fastNLP"):
parts = base.__module__.split(".") + []
module_name, i = "fastNLP", 1
for i in range(len(parts) - 1):
defined_m = sys.modules[module_name]
if "undocumented" not in defined_m.__doc__ and name in defined_m.__all__:
obj.__doc__ = r"基类 :class:`" + defined_m.__name__ + "." + base.__name__ + "` \n\n" + obj.__doc__
break
module_name += "." + parts[i + 1]

Loading…
Cancel
Save