Skip to content

Commit

Permalink
Add auto documentation of API Reference (PaddlePaddle#197)
Browse files Browse the repository at this point in the history
* add API Reference init configuration

* Update conf.py

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency

* add readthedoc config and dependency
  • Loading branch information
yingyibiao authored Mar 29, 2021
1 parent c8b3cc4 commit fc27ae9
Show file tree
Hide file tree
Showing 121 changed files with 1,589 additions and 142 deletions.
28 changes: 28 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

submodules:
include: all
recursive: true

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF
#formats:
# - pdf

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
install:
- requirements: docs/requirements.txt
- requirements: requirements.txt
- method: setuptools
path: .
system_packages: true
25 changes: 13 additions & 12 deletions docs/api_reference.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
============
API Reference
============
.. automodule:: paddlenlp
:members:
:inherited-members:

.. toctree::
:maxdepth: 1
:maxdepth: 2
:caption: paddlenlp

/api_reference/data.rst
/api_reference/layer.rst
/api_reference/train_evaluate.rst
/api_reference/predict.rst
/api_reference/others.rst


参考:https://www.paddlepaddle.org.cn/documentation/docs/zh/2.0-rc/api/index_cn.html
paddlenlp.data <source/paddlenlp.data>
paddlenlp.datasets <source/paddlenlp.datasets>
paddlenlp.embeddings <source/paddlenlp.embeddings>
paddlenlp.layers <source/paddlenlp.layers>
paddlenlp.metrics <source/paddlenlp.metrics>
paddlenlp.seq2vec <source/paddlenlp.seq2vec>
paddlenlp.transformers <source/paddlenlp.transformers>
paddlenlp.utils <source/paddlenlp.utils>
3 changes: 0 additions & 3 deletions docs/api_reference/data.rst

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api_reference/layer.rst

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api_reference/others.rst

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api_reference/predict.rst

This file was deleted.

3 changes: 0 additions & 3 deletions docs/api_reference/train_evaluate.rst

This file was deleted.

53 changes: 53 additions & 0 deletions docs/clear_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import os
import re


def modify_doc_title_dir(abspath_rstfiles_dir):
"""
rst文件中:有‘========’和‘----------’行的表示其行上一行的文字是标题,
‘=’和‘-’要大于等于标题的长度。
使用sphinx-apidoc -o ./source/rst_files /home/myubuntu/pro/mypro命令将
生成rst文件放在./source/rst_files目录下, 执行sphinx-quickstart命令生成的
index.rst不用放到这个目录中。 或在source目录下新建
rst_files目录然后将rst文件剪切到这个目录下,修改后再剪切出来
生成rst文件后将rst_files/modules.rst文件中的标题去掉,并修改maxdepth字段。
删除和修改使用sphinx-apidoc -o 命令的生成的rst文件中的标题
:param abspath_rstfiles_dir: rst文件所在的文件夹的绝对路径
:return:
"""
rst_files = os.listdir(abspath_rstfiles_dir)
# 要删除的节点(标题目录的节点)
del_nodes = ['Submodules', 'Module contents', 'Subpackages']
# 要删除的标题中的字符串
del_str = [' module', ' package']
for rst_file in rst_files:
f = open(os.path.join(abspath_rstfiles_dir, rst_file), 'r')
file_lines = f.readlines()
f.close()
write_con = []
flag = 0
for file_line in file_lines:
if file_line.strip() in del_nodes:
flag = 1
continue
if flag:
flag = 0
continue
if re.search(del_str[0], file_line):
modify_line = file_line.split('.')[-1].replace(del_str[0], '')
write_con.append(modify_line)
continue
if re.search(del_str[1], file_line):
modify_line = file_line.split('.')[-1].replace(del_str[1], '')
write_con.append(modify_line)
continue
file_line = file_line.replace('undoc-members', 'no-undoc-members')
write_con.append(file_line)
f = open(os.path.join(abspath_rstfiles_dir, rst_file), 'w')
f.writelines(write_con)
f.close()


if __name__ == '__main__':
modify_doc_title_dir('./source')

74 changes: 55 additions & 19 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
Expand All @@ -10,15 +24,25 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

import os
import sys
# sys.path.insert(0, os.path.abspath('../..'))

sys.path.insert(0, os.path.abspath('../paddlenlp/'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/data'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/datasets'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/embeddings'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/layers'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/metrics'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/models'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/seq2vec'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/transformers'))
# sys.path.insert(0, os.path.abspath('../paddlenlp/utils'))

# -- Project information -----------------------------------------------------

project = 'PaddleNLP'
copyright = '2020, nlpers'
copyright = '2021, nlpers'
author = 'nlpers'


Expand All @@ -28,9 +52,25 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'recommonmark'
'sphinx_rtd_theme',
'recommonmark',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.napoleon',
'sphinx_copybutton',
'sphinx_markdown_tables',
'sphinx.ext.viewcode',
'sphinx.ext.coverage',
'sphinx.ext.extlinks',
]

autodoc_default_options = {
'member-order': 'bysource',
'undoc-members': False,
}

autosummary_generate = True

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

Expand All @@ -39,35 +79,31 @@
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'zh_CN'
language = None
add_module_names = False

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


from recommonmark.parser import CommonMarkParser
source_parsers = {
'.md': CommonMarkParser,
}
# source_parsers = {
# '.md': recommonmark.parser.CommonMarkParser,
# }
source_suffix = ['.rst', '.md']

# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
#html_theme = 'alabaster'

import sphinx_rtd_theme
html_theme = "sphinx_rtd_theme"
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

html_theme_options = {
'collapse_navigation': False,
'display_version': False,
'navigation_depth': 2,
'collapse_navigation': True,
'display_version': True,
'navigation_depth': 5,
'navigation_with_keys': True,
}

# Add any paths that contain custom static files (such as style sheets) here,
Expand Down
60 changes: 35 additions & 25 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -1,32 +1,42 @@
.. nlp-practice documentation master file, created by
sphinx-quickstart on Wed Nov 18 15:57:54 2020.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
欢迎使用PaddleNLP
========================================
PaddleNLP是基于飞桨框架的NLP领域最佳实践,集成了丰富的数据集、网络结构、预训练模型、评价指标、数据处理等通用功能。具备......等特性。
==================
`PaddleNLP <https://github.com/PaddlePaddle/PaddleNLP>`_ 是基于飞桨框架的NLP领域最佳实践,
集成了丰富的数据集、网络结构、预训练模型、评价指标、数据处理等通用功能。具备......等特性。

* 项目GitHub: https://github.com/PaddlePaddle/PaddleNLP
* 官方QQ用户群: 973379845
* GitHub Issue反馈: https://github.com/PaddlePaddle/PaddleNLP/issues
* 官方QQ用户群: 973379845

.. toctree::
:maxdepth: 2
:caption: 快速开始

安装 <get_started/installation>
10分钟完成高精度中文情感分析 <get_started/quick_start>

.. toctree::
:maxdepth: 2

PaddleNLP是什么 <paddlenlp>
快速开始 <get_started>
数据准备 <data_prepare>
模型库 <model_zoo>
实践教程 <tutorials>
进阶指南 <advanced_guide>
API Reference <api_reference>
社区贡献 <community>
FAQ <faq>
版本更新 <version>

.. Indices and tables
.. ==================
.. * :ref:`genindex`
.. * :ref:`modindex`
.. * :ref:`search`
:caption: 数据准备

整体介绍 <data_prepare/overview>
数据集列表 <data_prepare/dataset_list>
加载数据集 <data_prepare/dataset_load>
自定义数据集 <data_prepare/dataset_self_defined>

.. toctree::
:maxdepth: 2
:caption: 实践教程

tutorials

.. toctree::
:maxdepth: 2
:caption: API Reference

api_reference

Indices and tables
====================
* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
10 changes: 10 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Defining the exact version will make sure things don't break

sphinx==3.5.2
sphinx_rtd_theme==0.5.1
readthedocs-sphinx-search==0.1.0

sphinx-copybutton==0.3.1
sphinx-markdown-tables==0.0.15

paddlepaddle >= 2.0.1
7 changes: 7 additions & 0 deletions docs/source/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
paddlenlp
=========

.. toctree::
:maxdepth: 4

paddlenlp
7 changes: 7 additions & 0 deletions docs/source/paddlenlp.data.collate.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
collate
=============================

.. automodule:: paddlenlp.data.collate
:members:
:no-undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/paddlenlp.data.iterator.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
iterator
==============================

.. automodule:: paddlenlp.data.iterator
:members:
:no-undoc-members:
:show-inheritance:
17 changes: 17 additions & 0 deletions docs/source/paddlenlp.data.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
data
======================

.. automodule:: paddlenlp.data
:members:
:no-undoc-members:
:show-inheritance:


.. toctree::
:maxdepth: 4

paddlenlp.data.collate
paddlenlp.data.iterator
paddlenlp.data.sampler
paddlenlp.data.tokenizer
paddlenlp.data.vocab
7 changes: 7 additions & 0 deletions docs/source/paddlenlp.data.sampler.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sampler
=============================

.. automodule:: paddlenlp.data.sampler
:members:
:no-undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/paddlenlp.data.tokenizer.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tokenizer
===============================

.. automodule:: paddlenlp.data.tokenizer
:members:
:no-undoc-members:
:show-inheritance:
7 changes: 7 additions & 0 deletions docs/source/paddlenlp.data.vocab.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
vocab
===========================

.. automodule:: paddlenlp.data.vocab
:members:
:no-undoc-members:
:show-inheritance:
Loading

0 comments on commit fc27ae9

Please sign in to comment.