{"id":623,"date":"2022-05-30T11:08:51","date_gmt":"2022-05-30T03:08:51","guid":{"rendered":"https:\/\/cabit.top\/?p=623"},"modified":"2022-05-30T11:08:51","modified_gmt":"2022-05-30T03:08:51","slug":"sphinx%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/cabit.top\/?p=623","title":{"rendered":"sphinx\u5feb\u901f\u5165\u95e8"},"content":{"rendered":"\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/sponsor.segmentfault.com\/lg.php?bannerid=0&amp;campaignid=0&amp;zoneid=25&amp;loc=https%3A%2F%2Fsegmentfault.com%2Fa%2F1190000007233355&amp;cb=07342a5168\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong>\u7b80\u4ecb<\/strong><\/p>\n\n\n\n<p>sphinx\u662f\u4e00\u4e2a\u7528\u4e8e\u5feb\u901f\u751f\u6210\u6587\u6863\u7684\u5de5\u5177\uff0c\u975e\u5e38\u9002\u5408\u751f\u6210Python\u6587\u6863\u3002<\/p>\n\n\n\n<p>\u5b83\u5177\u6709\u4ee5\u4e0b\u4f18\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u652f\u6301\u591a\u79cd\u8f93\u51fa\u683c\u5f0f\uff0c \u5982html\uff0cLatex\uff0cePub\u7b49\u3002<\/li><li>\u4e30\u5bcc\u7684\u6269\u5c55<\/li><li>\u7ed3\u6784\u5316\u6587\u6863<\/li><li>\u81ea\u52a8\u7d22\u5f15<\/li><li>\u652f\u6301\u8bed\u6cd5\u9ad8\u4eae<\/li><\/ul>\n\n\n\n<p>sphinx\u4f7f\u7528reStructuredtext\u4f5c\u4e3a\u5b83\u7684\u6807\u8bb0\u8bed\u8a00\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-2\">\u5b89\u88c5<\/h3>\n\n\n\n<p>\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install sphinx<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-3\">\u8bbe\u7f6e\u6e90\u6587\u4ef6\u76ee\u5f55<\/h3>\n\n\n\n<p>\u5305\u542b.rst\u6587\u4ef6\u7684\u6839\u76ee\u5f55\u79f0\u4e4b\u4e3a\u6e90\u6587\u4ef6\u76ee\u5f55\uff0c\u76ee\u5f55\u4e2d\u8fd8\u5305\u542bsphinx\u7684\u914d\u7f6e\u6587\u4ef6conf.py\u3002<\/p>\n\n\n\n<p>\u8fdb\u5165\u6e90\u6587\u4ef6\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff0c\u4f1a\u6307\u5f15\u7528\u6237\u914d\u7f6e\u6574\u4e2a\u9879\u76ee\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">sphinx-quickstart<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-4\">\u5b9a\u4e49\u6587\u4ef6\u7ed3\u6784<\/h3>\n\n\n\n<p>\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u4e4b\u540e\uff0csphinx\u4f1a\u5728\u6e90\u6587\u4ef6\u76ee\u5f55\u4e2d\u81ea\u52a8\u751f\u6210conf.py\u6587\u4ef6\u4ee5\u53caindex.rst\u3002index.rst\u79f0\u4e4b\u4e3a\u4e3b\u6587\u6863\uff0c\u5b83\u88absphinx\u4f5c\u4e3a\u6b22\u8fce\u9875\u9762\u3002<\/p>\n\n\n\n<p>index.rst\u4e2d\u5305\u542b\u4e86\u76ee\u5f55\u6811\u6307\u4ee4toctree\uff0csphinx\u4f7f\u7528\u5b83\u94fe\u63a5\u5176\u4ed6\u5b50\u6587\u6863\u3002<\/p>\n\n\n\n<p>toctree\u6307\u4ee4\u7684\u521d\u59cb\u503c\u4e3a\u7a7a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.. toctree::\n   :maxdepth: 2<\/pre>\n\n\n\n<p>\u63a5\u4e0b\u6765\u5c31\u53ef\u4ee5\u7ed9\u5b83\u6dfb\u52a0\u5b50\u6587\u6863\u7684\u94fe\u63a5\u4e86\uff0c\u76f4\u63a5\u4f7f\u7528\u6587\u6863\u7684\u540d\u79f0\u5373\u53ef\uff0c\u7701\u7565\u6389\u6587\u4ef6\u540e\u7f00\uff0c\u5982\u679c\u662f\u591a\u7ea7\u76ee\u5f55\uff0c\u5219\u4f7f\u7528\/\u5206\u9694\u5f00\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.. toctree::\n   :maxdepth: 2\n\n   intro\n   tutorial\n   chapter\/doc1\n   ...<\/pre>\n\n\n\n<p>\u63a5\u7740\u6211\u4eec\u5c31\u53ef\u4ee5\u521b\u5efa\u4e0a\u9762\u5217\u51fa\u7684\u6587\u4ef6\u5e76\u6dfb\u52a0\u76f8\u5e94\u5185\u5bb9\u4e86\uff0csphnix\u4f1a\u81ea\u52a8\u5c06\u8fd9\u4e9b\u6587\u6863\u7684\u7ae0\u8282\u6807\u9898\u63d2\u5165\u5230doctree\u6307\u4ee4\u7684\u4f4d\u7f6e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-5\">\u6dfb\u52a0\u5185\u5bb9<\/h3>\n\n\n\n<p>\u5728sphinx\u6e90\u6587\u4ef6\u4e2d\uff0c\u4f7f\u7528reStructuredText\u6807\u8bb0\u8bed\u8a00\u8fdb\u884c\u6587\u6863\u7f16\u5199\uff0c\u9664\u6b64\u4e4b\u5916\uff0csphinx\u8fd8\u683c\u5916\u63d0\u4f9b\u4e86\u4e00\u4e9b\u6307\u4ee4\u3002<\/p>\n\n\n\n<p>\u5177\u4f53\u53ef\u4ee5\u53c2\u8003<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><a href=\"https:\/\/link.segmentfault.com\/?enc=eiZg5tLYGUOP336MZVzf9A%3D%3D.8P9cY0D%2FcRsR%2BKrwsMLtCpskUQQFMWlsvqCE4jwiFVlUKY%2FZO3mnm6k4KOII2MQoA1WmJrWwLsCdRP67s6H3%2Fg%3D%3D\" rel=\"noreferrer noopener\" target=\"_blank\">reStructuredText Primer<\/a>&nbsp;\u4ee5\u53ca<br><a href=\"https:\/\/link.segmentfault.com\/?enc=kLGZllKU4A56oWSgacb%2FCQ%3D%3D.guGL4F3LnIRIZNXFTiAM3yRg5Hrpd5Cg8DMgCGNMoXnfCtxNP1CApH5xCU1u2P63wrJTQca8ZEeBL36oCYLBzfFVJjwYLCMWFaMQ6yE8%2F7o%3D\" rel=\"noreferrer noopener\" target=\"_blank\">Sphinx Markup Constructs<\/a><\/p><\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-6\">\u751f\u6210\u6587\u6863<\/h3>\n\n\n\n<p>\u4f7f\u7528\u4e0b\u9762\u7684\u547d\u4ee4\u751f\u6210\u6587\u6863\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ sphinx-build -b html sourcedir builddir<\/pre>\n\n\n\n<p>sourcedir\u6307\u6e90\u6587\u4ef6\u76ee\u5f55\uff0c\u751f\u6210\u7684\u6587\u6863\u653e\u7f6e\u5728builddir\u6307\u5b9a\u7684\u76ee\u5f55\u4e2d\u3002<\/p>\n\n\n\n<p>\u5b9e\u9645\u4e0a\u8fd8\u6709\u4e00\u4e2a\u66f4\u7b80\u4fbf\u7684\u65b9\u6cd5\uff0csphinx-quickstart\u751f\u6210\u4e86\u4e00\u4e2amake.bat\u6587\u4ef6\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">make html<\/pre>\n\n\n\n<p>\u4e0a\u8ff0\u547d\u4ee4\u4f1a\u76f4\u63a5\u5728\u6e90\u6587\u4ef6\u76ee\u5f55\u4e2d\u751f\u6210\u6587\u6863\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-7\">\u5bf9\u8c61\u6587\u6863<\/h3>\n\n\n\n<p>sphinx\u7684\u8bbe\u8ba1\u521d\u8877\u4e4b\u4e00\u5c31\u662f\u66f4\u5bb9\u6613\u751f\u6210\u4efb\u4f55\u57df\u4e2d\u5bf9\u8c61\u7684\u6587\u6863\uff0c\u57df\u6307\u5f88\u591a\u5bf9\u8c61\u7684\u96c6\u5408\uff0c\u8fd9\u4e9b\u5bf9\u8c61\u4e2d\u8fd8\u5305\u542b\u4e86\u76f8\u5e94\u7684\u6587\u6863\u6ce8\u91ca\u3002<\/p>\n\n\n\n<p>\u6700\u4e3b\u8981\u7684\u57df\u662fPython\u57df\uff0c \u4f8b\u5982python\u5185\u7f6e\u51fd\u6570enumerate()\u7684\u6ce8\u91ca\u6587\u6863\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.. py:function:: enumerate(sequence[, start=0])\n\n   Return an iterator that yields tuples of an index and an item of the\n   *sequence*. (And so on.)<\/pre>\n\n\n\n<p>\u5b83\u5c06\u88ab\u6e32\u67d3\u6210\u5982\u4e0b\u683c\u5f0f\uff1a<\/p>\n\n\n\n<p><strong>enumerate<\/strong>(sequence[, start=0])<\/p>\n\n\n\n<p>\u3000\u3000Return an iterator that yields tuples of an index and an item of the sequence. (And so on.)<br>\u3000\u3000<br>\u6307\u4ee4\u53c2\u6570\u662f\u6211\u4eec\u9700\u8981\u63cf\u8ff0\u7684\u5bf9\u8c61\uff0c\u5185\u5bb9\u662f\u6211\u4eec\u7f16\u5199\u7684\u6587\u6863\u6ce8\u91ca\u3002\u7531\u4e8ePython\u662f\u9ed8\u8ba4\u7684\u57df\uff0c\u6240\u4ee5\u5e76\u4e0d\u9700\u8981\u7279\u522b\u6307\u51fa\u6240\u5c5e\u7684\u57df\u6765\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.. function:: enumerate(sequence[, start=0])\n\n   ...<\/pre>\n\n\n\n<p>sphinx\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u6307\u4ee4\u7528\u4e8e\u751f\u6210\u5176\u4ed6\u5bf9\u8c61\u7c7b\u578b\u7684\u6587\u6863\u3002\u4f8b\u5982<code>py:class<\/code>\u4ee5\u53ca<code>py:method<\/code><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-8\">\u57fa\u672c\u914d\u7f6e<\/h3>\n\n\n\n<p>sphinx\u901a\u8fc7conf.py\u8fdb\u884c\u914d\u7f6e\uff0cconf.py\u4f7f\u7528python\u8bed\u6cd5\uff0c\u9ed8\u8ba4\u4ee5utf-8\u7f16\u7801\u4fdd\u5b58\u3002\u5177\u4f53\u914d\u7f6e\u8bf7\u67e5\u770b<a href=\"https:\/\/link.segmentfault.com\/?enc=9reU76TdlSKwYCchINlArw%3D%3D.90Tmw0faBVraQyLD8ijvFYhzgYGKpV2sqBFrnb0yHz0FCptdS0rOxTgS4qd94fP12WS9C1Exj2c0%2BVK4pJyKZg%3D%3D\" rel=\"noreferrer noopener\" target=\"_blank\">&nbsp;The build configuration file<\/a>\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-9\">\u81ea\u52a8\u751f\u6210\u6587\u6863\u6ce8\u91ca<\/h3>\n\n\n\n<p>sphinx\u652f\u6301\u4ecepython\u6e90\u4ee3\u7801\u4e2d\u63d0\u53d6\u6587\u6863\u6ce8\u91ca\u4fe1\u606f\uff0c\u7136\u540e\u751f\u6210\u6587\u6863\uff0c\u6211\u4eec\u5c06\u8fd9\u79f0\u4e4b\u4e3aautodoc\u3002<\/p>\n\n\n\n<p>\u4e3a\u4e86\u4f7f\u7528autodoc\uff0c\u9996\u5148\u9700\u8981\u5728\u914d\u7f6e\u6587\u4ef6\u7684extensions\u9009\u9879\u4e2d\u6dfb\u52a0&#8217;sphinx.ext.autodoc&#8217;\u3002\u7136\u540e\u6211\u4eec\u5c31\u53ef\u4ee5\u4f7f\u7528autodoc\u7684\u6307\u4ee4\u4e86\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u751f\u6210\u51fd\u6570io.open()\u7684\u6587\u6863\uff0c\u53ea\u9700\u8981\u5728rst\u6587\u4ef6\u4e2d\u6dfb\u52a0\u5982\u4e0b\u8bed\u53e5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.. autofunction:: io.open<\/pre>\n\n\n\n<p>\u4e5f\u53ef\u4ee5\u76f4\u63a5\u751f\u6210\u6574\u4e2a\u7c7b\u7684\u6587\u6863\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.. automodule:: io\n   :members:<\/pre>\n\n\n\n<p>\u4e3a\u4e86\u63d0\u53d6\u6587\u6863\u6ce8\u91ca\uff0cautodoc\u9700\u8981\u5bfc\u5165\u6ce8\u91ca\u6240\u5728\u7684\u6a21\u5757\u3002\u56e0\u6b64\u9700\u8981\u5728sys.path\u4e2d\u8bbe\u7f6e\u597d\u6a21\u5757\u7684\u8def\u5f84\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"item-10\">\u8bbe\u7f6e\u4e3b\u9898<\/h3>\n\n\n\n<p>\u63a8\u8350\u4f7f\u7528readthedoc\u4f7f\u7528\u7684\u4e3b\u9898\uff0c\u7f8e\u89c2\u53c8\u7b80\u6d01\u5927\u65b9\u3002<br>\u9996\u5148\u5b89\u88c5\u4e3b\u9898\u5e93\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">pip install sphinx_rtd_theme<\/pre>\n\n\n\n<p>\u7136\u540e\u914d\u7f6econf.py:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import sphinx_rtd_theme\n\nhtml_theme = \"sphinx_rtd_theme\"\n\nhtml_theme_path = [sphinx_rtd_theme.get_html_theme_path()]\n\n\u539f\u6587\u5730\u5740\uff1ahttps:\/\/segmentfault.com\/a\/1190000007233355<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u4ecb sphinx\u662f\u4e00\u4e2a\u7528\u4e8e\u5feb\u901f&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-623","post","type-post","status-publish","format-standard","hentry","category-softapp"],"_links":{"self":[{"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/posts\/623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/cabit.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=623"}],"version-history":[{"count":1,"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions"}],"predecessor-version":[{"id":624,"href":"https:\/\/cabit.top\/index.php?rest_route=\/wp\/v2\/posts\/623\/revisions\/624"}],"wp:attachment":[{"href":"https:\/\/cabit.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cabit.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cabit.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}