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.pswp.cn/news/393043.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/393043.shtml
英文地址,請注明出處:http://en.pswp.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 個排列。 說明&…