簡體   English   中英

Python 代碼塊不使用 readthedocs 和 sphinx 呈現

[英]Python code blocks not rendering with readthedocs and sphinx

我正在使用 Sphinx 和 readthedocs 為 python 項目構建文檔。 出於某種原因,構建文檔后代碼塊未呈現,並且內聯代碼(標有反引號)顯示為斜體。 我檢查了原始構建,有一個警告說找不到 exomagpy 模塊,我通過在 conf.py 的 os.path.abspath() 部分將“..”更改為“../”解決了這個問題,這似乎沒有改變文檔中的任何內容。 stackoverflow上有一個類似的問題,我嘗試了解決方案,但沒有改變。

原始版本可以在這里找到: https://readthedocs.org/api/v2/build/17574729.txt

這些文檔是從 github 頁面的“開發”分支構建的(鏈接如下)

這是 github 頁面的鏈接: https://github.com/quasoph/exomagpy/tree/Develop

回購的結構如下:

>.vscode
>build/lib/exomagpy

>docs
   >conf.py
   >rst files (.rst)
   >makefile
   >make.bat

>exomagpy.egg-info

>exomagpy
   >__init__.py
   >module files (.py)

>.readthedocs.yml
>requirements.txt
>setup.py

這是我的文件:

配置文件

import os
import sys
sys.path.insert(0, os.path.abspath("../"))

# project info

project = "exomagpy"
root_doc = "index"
release = "1.3.0"

# general config

extensions = ["sphinx.ext.autodoc","sphinx.ext.napoleon","sphinx.ext.autosummary"
]

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# html options

html_theme = 'sphinx_rtd_theme'
html_static_path = []

.readthedocs.yml

version: 1

build:
  os: ubuntu-20.04
  tools:
    python: "3.8"
  
sphinx:
  configuration: docs/conf.py

python:
  version: 3.8
  install:
    - method: setuptools
      path: .
    - requirements: requirements.txt

dependencies:
  - python=3.8

要求.txt

numpy
matplotlib
pandas
tensorflow
lightkurve
requests
sphinx==5.1.1
sphinx_rtd_theme==1.0.0

安裝程序.py

from setuptools import setup, find_packages

setup(
    name = "exomagpy",
    version = "1.3.0",
    author = "Sophie",
    author_email = "email",
    url = "link",
    description = "description",
    packages = find_packages()
)

非常感謝任何幫助,如果需要更多信息,請告訴我。

正如@mzjn 指出的那樣, code-block指令和應該突出顯示的代碼之間需要一個空行。

https://raw.githubusercontent.com/quasoph/exomagpy/main/docs/tutorials.rst

.. code-block:: python

    import exomagpy.predictExo
    exomagpy.predictExo.tess()
    exomagpy.predictExo.kepler()

此外,對於內聯代碼文字,reStructuredText 中的單個反引號將呈現為斜體,正如您所意識到的,而在 Markdown 及其風格中,它將呈現為內聯代碼文字。 對於 reStructuredText,用雙反引號包圍文字:

``inline_literal``

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM