出于文档目的将文件包含到rst
rst-include的Python项目详细描述
rst_include
由于您不能将文件包含到github和pypi上的rst文件中,因此可以使用此软件替换这些导入。
这意味着您可以在本地编写rst文档(例如使用pycharm)并在其中使用 这个。。include:将其他rst文件或代码段包含到文档中的选项。 然后,您可以运行此软件来创建一个可以在github或pypi上查看的单片readme.rst
您可能还包括来自Jupyter笔记本的文本/代码(抱歉,目前没有图片,但这样做并不困难)
这有许多优点,如:
- 不要重复,创建标准块以包含在文档中
- 将代码文件中经过测试的代码片段包含到文档中,以避免未经测试或过时的文档
- 包括其他RST文件
- 非常简单的用法,在travis构建时抛出退出代码以检测文档中的错误
- 命令行或编程接口,您甚至可以在travis.yml中使用它
- 命令行界面支持shellscript、cmd、pipes、config文件
这个自述文件也是用rst_include创建的,您可以查看./docs/自述模板.rst, 例如build_docs.sh、build_docs.cmd和build_docs.py。(它们都做同样的事,只是版本不同)
yml在每次运行时都会构建文档,因此您可以确保没有错误。 rst_include仅适用于python>;3.6
100%代码覆盖率 ,mypy静态类型检查,在 Linux、OSX、Windows和Wine下测试 ,自动每日生成和监视
- 安装和升级
-
基本用法
< DL> - 示例
> UL> - 示例生成脚本python
- 示例生成脚本dos batch
- 示例生成脚本shellscript
- rst包括示例
- 简单代码包含
- 文本或RST文件包含
- 包括Jupyter笔记本
安装和升级
源代码:
# normal install python setup.py install # test without installing python setup.py test
VIA PIP最新版本:
# latest Release from pypi # under Linux You have to use sudo, or it will not be installed as a commandline application # [sudo] means, that the command "sudo" is optional for Linux if You want to use it from bash commandline [sudo] pip3 install rst_include # test without installing [sudo] pip3 install rst_include --install-option test
VIA PIP最新开发版本:
# upgrade all dependencies regardless of version number (PREFERRED) [sudo] pip3 install --upgrade https://github.com/bitranox/rst_include/archive/master.zip --upgrade-strategy eager # normal install [sudo] pip3 install --upgrade https://github.com/bitranox/rst_include/archive/master.zip # test without installing [sudo] pip3 install https://github.com/bitranox/rst_include/archive/master.zip --install-option test
via requirements.txt:
# Insert following line in Your requirements.txt: # for the latest Release: rst_include # for the latest Development Version : https://github.com/bitranox/rst_include/archive/master.zip # to install and upgrade all modules mentioned in requirements.txt: [sudo] pip3 install --upgrade -r /<path>/requirements.txt
通过Python:
# for the latest Release[sudo]python3-mpipinstallupgraderst_include# for the latest Development Version[sudo]python3-mpipinstallupgradehttps://github.com/bitranox/rst_include/archive/master.zip
基本用法
由于在当前的python解释器中将rst_include注册为控制台脚本命令,因此必须使用命令"rst_include"(而不是"rst_include.py")
- 发出命令:
# issue command on shell or windows commandline $> rst_include [OPTIONS]# or, if python/bin is not in Your python path : # on Windows $> c:\python37\scripts\rst_include [OPTIONS]# on Linux/oSX $> /python37/bin/rst_include [OPTIONS]# issue command with python interpreter $> python -m rst_include [OPTIONS]
- 获取帮助:
# get help on shell or windows commandline
$> rst_include -h
usage: rst_include [-h]{include,replace} ... Process .rst File Includes positional arguments: {include,replace} include include rst includes replace string replace optional arguments: -h, --help show this help message and exit check the documentation on github
# get help on shell or windows commandline for include
$> rst_include include -h
# normal install python setup.py install # test without installing python setup.py test0
# normal install python setup.py install # test without installing python setup.py test1
# normal install python setup.py install # test without installing python setup.py test2
- 替换source.rst中的include语句并通过命令行参数将其保存到target.rst:
# normal install python setup.py install # test without installing python setup.py test3
- 通过config.py: 替换多个文件上的include语句
# normal install python setup.py install # test without installing python setup.py test4
配置文件的结构:
文件按给定顺序处理,这样您甚至可以实现嵌套。包含::块。
您还可以指定源文件和目标文件的编码
# normal install python setup.py install # test without installing python setup.py test5
另外,您可以轻松替换(也可以多行)文本字符串:
# normal install python setup.py install # test without installing python setup.py test6
Linux下的管道:
# normal install python setup.py install # test without installing python setup.py test7