美文网首页
sphinx 基本使用

sphinx 基本使用

作者: 咕嘟咕嘟li | 来源:发表于2019-11-13 14:27 被阅读0次

安装

pip install sphinx

文件完整的结构目录如下:


image.png

在自己的项目目录下建立两个文件夹src和doc
在src下新建一个文件demo1.py,内容如下:

# 使用类和实例
class Car():
    """一次模拟汽车的简单尝试"""
    def __init__(self, make, model, year):
        """初始化描述汽车的属性"""
        self.make = make
        self.model = model
        self.year = year

        # 给属性指定默认值
        self.odometer_reading = 0

    def get_descriptive_name(self):
        """ 返回整洁的描述性信息 """
        long_name = str(self.year) + ' ' + self.make + ' ' + self.model
        return long_name.title()

    def read_odometer(self):
        """ 打印一条指出汽车里程的消息 """
        print('This car has ' + str(self.odometer_reading) + ' miles on it.')

    def update_odometer(self, mileage):
        """ 修改里程的值 """
        if mileage >= self.odometer_reading:
            self.odometer_reading = mileage
        else:
            print("You can't roll back an odometer!")

    def increment_odometer(self, miles):
        """ 将里程表读数增加指定的量 """
        self.odometer_reading += miles


接着执行以下命令

cd doc
sphinx-quickstart

打开doc/source/conf.py文件,取消13-15行的注释
第15行sys.path.insert(0, os.path.abspath('.')) 改为sys.path.insert(0, os.path.abspath('../../src'))

在doc目录下执行

sphinx-apidoc -o source ../src
  • source参数是doc文件夹下的source文件夹
  • ../src 参数是和doc文件夹同级的放Python文件的文件夹

执行后会生成如下文件


image.png

如在编译时遇到错误 Sphinx error: master file [..]/checkouts/latest/contents.rst not found
可以在doc/source/conf.py 中添加master_doc = 'index'

执行make html生成 html 格式的文档,在build/html文件夹下会生成相应的文档
点击index.html页面查看效果:

image.png

再往index.rst里添加好模块的名称


image.png

再去执行make html,刚刚添加的内容就会在首页的导航里出现了

image.png
点击链接后跳转如下:
image.png

相关文章

  • sphinx 基本使用

    安装 文件完整的结构目录如下: 在自己的项目目录下建立两个文件夹src和doc在src下新建一个文件demo1.p...

  • 使用sphinx生成API文档

    使用sphinx生成API文档 1、安装sphinx pip install Sphinx 2、初始化文档: 在项...

  • 用 Sphinx 写文档

    本文记录使用Sphinx 写文档,以及利用Nginx 完成部署的整个过程。 环境 Sphinx 本身是使用Pyth...

  • sphinx-apidoc

    [toc] 一、使用 sphinx-apidoc是一个自动生成Sphinx源的工具,使用该autodoc扩展。MO...

  • Sphinx 环境配置

    Sphinx 环境搭建 配置环境: 1. 安装 使用 pip install Sphinx 安装,如果国内站点访问...

  • sphinx(四)centos7安装sphinx3.3.1

    Sphinx使用的版本我是一点点增高的。 Coreseek3.2是基于sphinx0.9开发的。 Sphinx-f...

  • php操作Sphinx

    使用PHP API操作 Sphinx 1、基础操作 步骤1:复制sphinx\api目录中的接口文件sphinxa...

  • 凌乱

    今天知道了好几个名字记录下,以后方便查: Sphinx http://sphinx-doc.org/ 使用 Sph...

  • 全文搜索引擎-sphinx及xunsearch

    使用全文搜索引擎 站内搜索类型 1、sphinx(斯芬克斯) sphinx不支持中文, coreseek(基于sp...

  • 学习sphinx制作文档、编写书稿

    学习sphinx制作文档 摘要 本篇中的sphinx不是开发搜索功能的软件,而是生成文档的工具。它使用reStru...

网友评论

      本文标题:sphinx 基本使用

      本文链接:https://www.haomeiwen.com/subject/jbmhictx.html