Django Sphinx编译错误:未找到index.rst,警告:未知指令



我面临一个奇怪的错误。这里我有一个Django项目,它在本地运行得很好,我甚至生成了文档,一切都很顺利。问题是当我在中导入项目时https://readthedocs.org/编译失败了,我几乎什么都试过了,但总是遇到同样的问题。

我使用Django==2.2Python==3.7.8

我的项目结构:

- Myproject
-- docs
-- build
-- source
- conf.py
- index.rst
- file.rst
- another_file.rst
make.bat
Makefile
requirements.txt
-- MyprojectDir
-- MyappDir

源目录中的conf.py文件如下所示:

# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

# -- Project information -----------------------------------------------------
import os
import sys
import django
cwd = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.abspath(os.path.join(cwd, '../../')))
os.environ['DJANGO_SETTINGS_MODULE'] = 'vtcvlp.settings'
django.setup()
from sphinx.ext.autosummary import Autosummary
from sphinx.ext.autosummary import get_documenter
from docutils.parsers.rst import directives
from sphinx.util.inspect import safe_getattr
import re

class AutoAutoSummary(Autosummary):
option_spec = {
'methods': directives.unchanged,
'attributes': directives.unchanged
}
required_arguments = 1
@staticmethod
def get_members(obj, typ, include_public=None):
if not include_public:
include_public = []
items = []
for name in dir(obj):
try:
documenter = get_documenter(safe_getattr(obj, name), obj)
except AttributeError:
continue
if documenter.objtype == typ:
items.append(name)
public = [x for x in items if x in include_public or not x.startswith('_')]
return public, items
def run(self):
clazz = str(self.arguments[0])
try:
(module_name, class_name) = clazz.rsplit('.', 1)
m = __import__(module_name, globals(), locals(), [class_name])
c = getattr(m, class_name)
if 'methods' in self.options:
_, methods = self.get_members(c, 'method', ['__init__'])
self.content = ["~%s.%s" % (clazz, method) for method in methods if not method.startswith('_')]
if 'attributes' in self.options:
_, attribs = self.get_members(c, 'attribute')
self.content = ["~%s.%s" % (clazz, attrib) for attrib in attribs if not attrib.startswith('_')]
finally:
return super(AutoAutoSummary, self).run()

def setup(app):
app.add_directive('autoautosummary', AutoAutoSummary)

project = 'vtc-video-link-post'
copyright = '2020, MBAMBA FABRICE DAMIEN'
author = 'MBAMBA FABRICE DAMIEN'
# The full version, including alpha/beta/rc tags
release = '1.0'
master_doc = 'index'
autosummary_generate = True
source_suffix = [".rst", ".md"]
pygments_style = "sphinx"
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.doctest',
'sphinx.ext.intersphinx', 'sphinx.ext.todo',
'sphinx.ext.ifconfig', 'sphinx.ext.viewcode',
'sphinx.ext.inheritance_diagram',
'sphinx.ext.autosummary',
'recommonmark',
'sphinx.ext.coverage'
'sphinx.ext.ifconfig',
'sphinx_autodoc_typehints',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []

# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages.  See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

在中编译文档时https://readthedocs.org/我收到这个错误,但它安装了所有要求文件

Running Sphinx v3.2.1
loading translations [en]... done
making output directory... done
building [mo]: targets for 0 po files that are out of date
building [readthedocs]: targets for 5 source files that are out of date
updating environment: [new config] 5 added, 0 changed, 0 removed
reading sources... [ 20%] source/index
reading sources... [ 40%] source/intro
reading sources... [ 60%] source/launch
reading sources... [ 80%] source/usage
reading sources... [100%] source/vtcvlp
/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/source/vtcvlp.rst:7: WARNING: Unknown directive type "autoclass".
.. autoclass:: vtcuser.models.CustomUser
:members:
:undoc-members:
:show-inheritance:
.. rubric:: Methods
.. autoautosummary:: vtcuser.models.CustomUser
:methods:
.. rubric:: Attributes
.. autoautosummary:: vtcuser.models.CustomUser
:attributes:
/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/source/vtcvlp.rst:24: WARNING: Unknown directive type "autoclass".
.. autoclass:: vtcuser.models.VideoLink
:members:
:undoc-members:
:show-inheritance:
.. rubric:: Methods
.. autoautosummary:: vtcuser.models.VideoLink
:methods:
.. rubric:: Attributes
.. autoautosummary:: vtcuser.models.VideoLink
:attributes:
/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/source/vtcvlp.rst:41: WARNING: Unknown directive type "autoclass".
.. autoclass:: vtcuser.api.CustomUserViewSet
:members:
:undoc-members:
.. rubric:: Methods
.. autoautosummary:: vtcuser.api.CustomUserViewSet
:methods:
.. rubric:: Attributes
.. autoautosummary:: vtcuser.api.CustomUserViewSet
:attributes:
/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/source/vtcvlp.rst:57: WARNING: Unknown directive type "autoclass".
.. autoclass:: vtcuser.api.VideoLinkViewSet
:members:
:undoc-members:
:show-inheritance:
.. rubric:: Methods
.. autoautosummary:: vtcuser.api.VideoLinkViewSet
:methods:
.. rubric:: Attributes
.. autoautosummary:: vtcuser.api.VideoLinkViewSet
:attributes:
/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/source/vtcvlp.rst:74: WARNING: Unknown directive type "autoclass".
.. autoclass:: vtcuser.serializers.CustomUserSerializer
:members:
:undoc-members:
:show-inheritance:
.. rubric:: Methods
.. autoautosummary:: vtcuser.serializers.CustomUserSerializer
:methods:
.. rubric:: Attributes
.. autoautosummary:: vtcuser.serializers.CustomUserSerializer
:attributes:
/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/source/vtcvlp.rst:91: WARNING: Unknown directive type "autoclass".
.. autoclass:: vtcuser.serializers.VideoLinkSerializer
:members:
:undoc-members:
:show-inheritance:
.. rubric:: Methods
.. autoautosummary:: vtcuser.serializers.VideoLinkSerializer
:methods:
.. rubric:: Attributes
.. autoautosummary:: vtcuser.serializers.VideoLinkSerializer
:attributes:
/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/source/vtcvlp.rst:109: WARNING: Unknown directive type "automodule".
.. automodule:: vtcuser.views
:members:
:undoc-members:
:show-inheritance:
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/envs/latest/lib/python3.7/site-packages/sphinx/cmd/build.py", line 280, in build_main
app.build(args.force_all, filenames)
File "/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/envs/latest/lib/python3.7/site-packages/sphinx/application.py", line 348, in build
self.builder.build_update()
File "/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/envs/latest/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 299, in build_update
len(to_build))
File "/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/envs/latest/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 311, in build
updated_docnames = set(self.read())
File "/home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/envs/latest/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 422, in read
self.env.doc2path(self.config.master_doc))
sphinx.errors.SphinxError: master file /home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/index.rst not found
Sphinx error:
master file /home/docs/checkouts/readthedocs.org/user_builds/vtc-vlp/checkouts/latest/docs/index.rst not found

本地所有工作都很好,看看这个:

Running Sphinx v3.2.1
making output directory... done
[autosummary] generating autosummary for: index.rst, intro.rst, launch.rst, usage.rst, vtcvlp.rst
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 5 source files that are out of date
updating environment: [new config] 5 added, 0 changed, 0 removed
reading sources... [100%] vtcvlp
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] vtcvlp
generating indices...  genindex py-modindexdone
highlighting module code... [100%] vtcuser.views
writing additional pages...  searchdone
copying images... [100%] capture4.png
copying static files... ... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded.
The HTML pages are in buildhtml.

读取文档错误日志详细信息:---->gt>gt构建日志详细信息

我哪里会犯错误

对于那些有同样问题的人,当RTD从我的github-reop构建时,我也有同样的问题。我最终发现原因是.readthedocs.yamlconf.py路径的配置错误。

# File: .readthedocs.yaml
version: 2
# Build from the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py
...

事实上,我的conf.py位于docs/source中,当我如下图所示更改最后一行时,它按预期工作。

configuration: docs/source/conf.py

相关内容

  • 没有找到相关文章

最新更新