sphinx_Sphinx之谜:如何轻松地编写代码

sphinx

为什么我在这里? (Why Am I Here?)

You, the reader, are here because you wrote some awesome tool in Python, and you want to make it accessible and easy to use.

读者之所以在这里,是因为您使用Python编写了一些很棒的工具,并且希望使其易于使用。

I, the writer, am here because I was right where you are a few months ago. I wanted to use the Sphinx package to make a ReadTheDocs-style documentation for my project.

我(作家)之所以在这里是因为几个月前我就在您所在的位置。 我想使用Sphinx包为我的项目制作ReadTheDocs风格的文档。

I found the onboarding of Sphinx nontrivial, which is why I made this GitHub repo that can be used as a template for your project.

我发现Sphinx的入门很简单,这就是为什么我制作了这个GitHub存储库以用作您的项目模板的原因。

Before we start, some basic assumptions, to make sure we are on the same page:

在开始之前,请先进行一些基本假设,以确保我们位于同一页面上:

  • You are writing in Python.

    您正在用Python编写。
  • You wrote docstrings for the pieces of code you wish to document.

    您为要记录的代码段编写了文档字符串 。

  • Your goal is to make a ReadTheDocs-style documentation that, at least partially, will automagically generate itself.

    您的目标是制作一个ReadTheDocs样式的文档,该文档至少部分将自动生成自身。

  • You are aware that in 10 minutes you could publish the first version of your documentation, that is going to look something like this:

    您知道, 您可以10分钟内发布文档的第一个版本 ,如下所示 :

第1部分-设置舞台 (Part 1 - Setting the Stage)

  • Install Sphinx: pip install sphinx

    安装Sphinx: pip install sphinx

  • Go to github.com/DalyaG/Sphinx185:

    转到github.com/DalyaG/Sphinx185 :

  • Download the folder documentation_template_for_your_next_project

    下载文件夹documentation_template_for_your_next_project

  • Copy to your project

    复制到您的项目
  • Rename the folder documentation

    重命名文件夹documentation

第2部分-个性化 (Part 2 - Personalize)

  • Open the file <your_project>/documentation/conf.py in your favorite editor. Search for the pattern #CHNAGEME# and follow the instructions.

    在您喜欢的编辑器中打开文件<your_project>/documentation/c conf.py。 搜索模式ttern #CHN AGEME#,然后按照说明进行操作。

  • Similarly, edit the file <your_project>/documentation/index.rst and follow the inline instructions.

    同样,编辑文件<your_project>/documentation/ind ex.rst并按照内联说明进行操作。

第3部分-添加您希望记录的内容 (Part 3 - Add the Content You Wish to Document)

  • Let’s say you have a python file called my_amazing_class.py that includes a class you wish to document.

    假设您有一个名为my_amazing_class.py的python文件,其中包含您要记录的类。

  • In the same folder as the conf.py and index.rst files, create a new file called my_amazing_class.rst and copy-paste-personalize this template:

    在与 conf.pyindex.rst文件相同的文件夹中,创建一个名为my_amazing_class.rst的新文件,并将此模板复制粘贴个性化:

This is a template for including classes========================================|.. autoclass:: my_amazing_class.MyAmazingClass|:ref:`Return Home <mastertoc>`

TIP: make sure the folder containing your amazing class is in your PYTHONPATH and that it includes an init file__init__.py

提示:请确保包含惊人类的文件夹位于您的PYTHONPATH ,并且其中包含一个初始化文件__init__.py

  • In the index.rst file, edit the Table Of Contents to include the name of the .rst file:

    index.rst文件中,编辑目录以包括.rst文件的名称:

.. toctree::   :maxdepth: 1   :name: mastertoc
my_amazing_class

第4部分-“编译” (Part 4 - “Compile”)

  • In the terminal, inside the documentation folder, run make clean html.

    在终端的documentation文件夹内,运行make clean html

  • That’s it! You have your first version of your documentation ready to view!

    而已! 您已经准备好查看文档的第一个版本!

  • Open the file documentation/_build/html/index.html in your browser, and see for yourself :)

    在浏览器中打开文件documentation/_build/html/index.html ,亲自看看:)

第5部分-在GitHub Pages上托管 (Part 5 - Host on GitHub Pages)

  • Under the root of your project, open a new folder called docs and copy inside it the content of <your_project>/documentation/_build/html/

    在项目的根目录下,打开一个名为docs的新文件夹,并在其中复制<your_project>/documentation/_build / html /的内容。

  • Inside this new docs folder, create an empty file called .nojekyll

    在这个新的docs文件夹中,创建一个名为.nojekyll的空文件。

    (This tells GitHub Pages to bypass the default

    (这告诉GitHub Pages绕过默认设置

    Jekyll themes and use the HTML and CSS in your project)

    Jekyll主题,并在您的项目中使用HTMLCSS )

  • Push your changes to master branch.

    将您的更改推送到master分支。

  • In your repository on GitHub, go to Settings->GitHub Pages->Source

    在GitHub上的存储库中,转到Settings->GitHub Pages->源”

    and s

    和s

    elect master branch/docs folder

    elect master branch/docs文件夹

第6部分-分享! (Part 6 - Share!)

Yup. That’s it. Wait a couple of minutes for GitHub to update. Share your beautiful documentation site at

对。 而已。 等待几分钟,以便GitHub更新。 在以下位置分享您漂亮的文档站点

https://<your_git_usrname>.github.io/<project_name>/

https://<your_git_usrname>.github.io/<proje proje ct_name> /

TIP: When updating documentation, you need to delete the docs folder and create it again. See more details here.

提示:更新文档时,您需要删除docs文件夹并重新创建。 在这里查看更多详细信息。

结语 (Epilogue)

This is the part where I say something thoughtful about how wonderful it is to create new content in the world. And what a wonderful person you are for choosing to make your original content available, accessible, and easy to use.

在这一部分,我会说一些有关在世界上创建新内容的美妙之处。 您是一个多么出色的人,可以选择使您的原始内容可用,可访问且易于使用。

But hey, you made it all the way here, so you already know this stuff.

但是,嘿,您已经在这里完成了所有工作,因此您已经知道了这些东西。

So if there is something else that you still feel you don’t know, I invite you to explore the documentation website I made for this tutorial. You can watch the talk I gave about Sphinx. Hopefully these will answer some riddles you have left about Sphinx.

因此,如果您仍然不知道其他内容,我邀请您浏览为该教程制作的文档网站 。 您可以观看我发表的有关狮身人面像的演讲 。 希望这些能够回答您留下的关于狮身人面像的困惑。

翻译自: https://www.freecodecamp.org/news/the-riddle-of-sphinx-how-to-document-your-code-easily-bf09a9a1804c/

sphinx

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/393043.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux贪吃蛇c程序,Linux环境下C语言实现贪吃蛇游戏

Linux环境下C语言实现贪吃蛇游戏[liultest snake]$ more snake.c#include #include #include #include #include #define NUM 60struct direct //用来表示方向的{int cx;int cy;};typedef struct node //链表的结点{int cx;int cy;struct node *back;struct node *next;}node;v…

Java正则表达式的使用和详解(上)

1.匹配验证-验证Email是否正确 public static void main(String[] args) {// 要验证的字符串String str "servicexsoftlab.net";// 邮箱验证规则String regEx "[a-zA-Z_]{1,}[0-9]{0,}(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";// 编译正则表达式P…

在组策略中使用脚本为域用户添加网络打印机

使用脚本为用户添加网络打印机 如果你想让培训部门的用户登录后就能添加网络打印机&#xff0c;就可以使用登录脚本来实现。其中DCServer是域控制&#xff0c;MarketPC1是市场部门的计算机&#xff0c;韩立辉用户是培训部门的用户。下面就验证使用组策略为培训部门的用户添加网…

leetcode257. 二叉树的所有路径(回溯算法)

给定一个二叉树&#xff0c;返回所有从根节点到叶子节点的路径。 说明: 叶子节点是指没有子节点的节点。 示例: 输入: 1 / 2 3 5 输出: [“1->2->5”, “1->3”] 解释: 所有根节点到叶子节点的路径为: 1->2->5, 1->3 代码 /*** Definition for a b…

英特尔神经计算棒_如何设置英特尔Movidius神经计算棒

英特尔神经计算棒by Rishal Hurbans由Rishal Hurbans 如何设置英特尔Movidius神经计算棒 (How to set up the Intel Movidius Neural Compute Stick) In 2017 I was approached by Intel to join their Innovator Programme. After a couple interviews I was inducted as an …

linux 脚本中的push,linux shell之pushd、popd和dirs的使用讲解

1 问题我们有时候需要保存多个路径&#xff0c;上下键切换不方便&#xff0c;用cd-只能到上个目录&#xff0c;我们可以用dirs和pushd和popd2 dirs、pushd、popddirs: 这个命令显示栈里面所有的路径&#xff0c;一定会包含当前路径,常用参数如下dirs -v 显示栈里面的所有路径和…

为什么我从 Git Flow 开发模式切换到了 Trunk Based 开发模式?

我已经使用 Git Flow 构建我的 Git 分支有几年了。但是&#xff0c;我遇到了 Git Flow 的一些问题&#xff0c;其中大部分来自长期存在的分支。解决这些问题的方案就是 Trunk Based Development。这是一个非常简单的技术&#xff0c;也是有效的持续交付的基础。在这篇文章中&am…

DedeCMS 提示信息! ----------dede_addonarticle

把数据保存到数据库附加表 dede_addonarticle 时出错&#xff0c;请把相关信息提交给DedeCms官方。Duplicate entry ’2532′ for key ‘PRIMARY’出现这种情况其实是你的主键是不可重复的&#xff0c;现在重复插入值为2532的主键了。可以去掉主键唯一&#xff0c;或是设成自增…

angular 模块构建_通过构建全栈应用程序学习Angular 6

angular 模块构建Angular 6 is out! The new features include better performance, new powerful CLI additions and a new way to inject services.Angular 6出来了&#xff01; 新功能包括更好的性能&#xff0c;新的功能强大的CLI附加功能以及注入服务的新方法。 This tut…

leetcode74. 搜索二维矩阵(二分查找)

编写一个高效的算法来判断 m x n 矩阵中&#xff0c;是否存在一个目标值。该矩阵具有如下特性&#xff1a; 每行中的整数从左到右按升序排列。 每行的第一个整数大于前一行的最后一个整数。 示例 1: 输入: matrix [ [1, 3, 5, 7], [10, 11, 16, 20], [23, 30, 34, 50] ] tar…

搭建基于.NetFrameWork的私有nuget服务端及打包项目发布上传

一、私有Nuget服务端搭建 1.创建一个.NetFramework web项目 2.在nuget管理中 安装 nuget.server包 3.安装完成后修改web.config里面的 apikey 和 packagesPath apikey&#xff1a;推送包到nuget服务端 packpage: 上传上来的包存放的服务器位置 4.发布web项目到IIS中&#xff0c…

linux 网络配置 阮一峰,Vim 配置入门

Vim 是最重要的编辑器之一&#xff0c;主要有下面几个优点。可以不使用鼠标&#xff0c;完全用键盘操作。系统资源占用小&#xff0c;打开大文件毫无压力。键盘命令变成肌肉记忆以后&#xff0c;操作速度极快。服务器默认都安装 Vi 或 Vim。Vim 的配置不太容易&#xff0c;它有…

spring 之 property-placeholder 分析

不难知道&#xff0c; property-placeholder 的解析是 PropertyPlaceholderBeanDefinitionParser 完成的&#xff0c; 但是 它仅仅是个parser &#xff0c; 它仅仅是读取了 location 等配置属性&#xff0c; 并没有完成真正的解析&#xff0c;及 注册。 <context:property-p…

leetcode面试题 10.02. 变位词组

编写一种方法&#xff0c;对字符串数组进行排序&#xff0c;将所有变位词组合在一起。变位词是指字母相同&#xff0c;但排列不同的字符串。 注意&#xff1a;本题相对原题稍作修改 示例: 输入: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”], 输出: [ [“ate”,…

hacktoberfest_我第一次参加Hacktoberfest中学到了什么

hacktoberfestImposter syndrome is something we all struggle with to one degree or another. Imposter syndrome is the fear of exposure as a fraud. If you’re anything like me you have felt like your work was not good enough to show. Or you weren’t far along…

--save 和--save-dev的区别

npm install 在安装 npm 包时&#xff0c;有两种命令参数可以把它们的信息写入 package.json 文件&#xff0c;一个是npm install --save另一个是 npm install --save-dev&#xff0c;他们表面上的区别是--save 会把依赖包名称添加到 package.json 文件 dependencies 键下&…

Linux 文件区块连续吗,关于Linux文件系统的的简单理解和认识

关于Linux文件系统的的简单理解和认识关于文件系统的运作&#xff0c;这与操作系统带的档案数据有关。例如Linux操作系统的档案权限(rwx)与文件属性(拥有者&#xff0c;群组&#xff0c;时间参数等)。文件系统通常会将这两部分的数据分别存放在不同的区块&#xff0c;权限与属性…

服务器性能和活动监视

监视数据库的目的是评估服务器的性能。 有效监视包括定期拍摄当前性能的快照来隔离导致问题的进程&#xff0c;以及连续收集数据来跟踪性能趋势。 Microsoft SQL Server 和 Microsoft 操作系统提供实用工具&#xff0c;使您可以查看数据库的当前状态并跟踪性能的状态变化。 下一…

Microsoft Desktop Virtualization

基本上有两套啦&#xff0c;一是大家较为熟悉的MED-V。另外就是VDI(虚拟桌面基础架构)&#xff0c;也就是以下的组合&#xff1a;1、Windows Server 2008 with Hyper-V 2、System Center Virtual Machine Manager (VMM) 2008 VMM 20083、Windows Vista Enterprise Centralized …

leetcode60. 第k个排列(回溯算法)

给出集合 [1,2,3,…,n]&#xff0c;其所有元素共有 n! 种排列。 按大小顺序列出所有排列情况&#xff0c;并一一标记&#xff0c;当 n 3 时, 所有排列如下&#xff1a; “123” “132” “213” “231” “312” “321” 给定 n 和 k&#xff0c;返回第 k 个排列。 说明&…