簡體   English   中英

Sphinx-apidoc django app / models.py的奇怪輸出

[英]Sphinx-apidoc strange output for django app/models.py

我在django項目的生成文檔中得到了一些丟失的信息,例如first_namelast_nameemail也丟失了(盡管它們是在父抽象類中定義的)。 如何控制基於sphinx-apidoc掃描添加到文檔中的內容? 我的目標是根據文檔自動生成文檔,但似乎sphinx-apidoc應該只用於一次初始腳手架

我嘗試使用:inherited-members :,如下所示,但它仍然沒有產生AbstractUser類中存在的first_name,last_name,email

.. automodule:: apps.users.models
    :members:
    :inherited-members:
    :show-inheritance:

我執行以下命令

sphinx-apidoc -f -e -d 2 -M -o docs/code apps '*tests*' '*migrations*'

輸出量

在此處輸入圖片說明

我的應用程序/用戶/models.py

from django.contrib.auth.models import AbstractUser
from django.contrib.postgres.fields import HStoreField
from imagekit import models as imagekitmodels
from imagekit.processors import ResizeToFill

from libs import utils

# Solution to avoid unique_together for email
AbstractUser._meta.get_field('email')._unique = True


def upload_user_media_to(instance, filename):
    """Upload media files to this folder"""
    return '{}/{}/{}'.format(instance.__class__.__name__.lower(), instance.id,
                             utils.get_random_filename(filename))


__all__ = ['AppUser']


class AppUser(AbstractUser):
    """Custom user model.

    Attributes:
        avatar (file): user's avatar, cropeed to fill 300x300 px
        notifications (dict): settings for notifications to user
    """

    avatar = imagekitmodels.ProcessedImageField(
        upload_to=upload_user_media_to,
        processors=[ResizeToFill(300, 300)],
        format='PNG',
        options={'quality': 100},
        editable=False,
        null=True,
        blank=False)

    notifications = HStoreField(null=True)

    # so authentication happens by email instead of username
    # and username becomes sort of nick
    USERNAME_FIELD = 'email'

    # Make sure to exclude email from required fields if authentication
    # is done by email
    REQUIRED_FIELDS = ['username']

    def __str__(self):
        return self.username

    class Meta:
        verbose_name = 'User'
        verbose_name_plural = 'Users'

我的獅身人面像conf.py

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys

import django
import sphinx_py3doc_enhanced_theme

sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath('.'))
os.environ.setdefault(
    "DJANGO_SETTINGS_MODULE", "config.settings.local")
django.setup()

# Extensions
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.napoleon',
    'sphinx.ext.viewcode',
    'sphinxcontrib.blockdiag'
]

napoleon_google_docstring = True
napoleon_use_param = True
napoleon_use_ivar = False
napoleon_use_rtype = True
napoleon_include_special_with_doc = False

# RST support
source_suffix = '.rst'

# Name of master doc
master_doc = 'index'

# General information about the project.
project = 'crm'
copyright = '2017, Company'
author = 'Company'


version = '0.1'

release = '0.1'

language = None

exclude_patterns = []

todo_include_todos = False

# Read the docs theme
html_theme = 'sphinx_py3doc_enhanced_theme'
html_theme_path = [sphinx_py3doc_enhanced_theme.get_html_theme_path()]

html_static_path = []

htmlhelp_basename = 'crmdoc'

latex_elements = {}


# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    (master_doc, 'crm', 'crm Documentation',
     [author], 1)
]

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (master_doc, 'crm', 'crm Documentation',
     author, 'crm', 'One line description of project.',
     'Miscellaneous'),
]

html_theme_options = {
    'githuburl': 'https://github.com/ionelmc/sphinx-py3doc-enhanced-theme/',
    'bodyfont': '"Lucida Grande",Arial,sans-serif',
    'headfont': '"Lucida Grande",Arial,sans-serif',
    'codefont': '"Deja Vu Sans Mono",consolas,monospace,sans-serif',
    'linkcolor': '#0072AA',
    'visitedlinkcolor': '#6363bb',
    'extrastyling': False,
    'sidebarwide': True

}
pygments_style = 'friendly'

html_context = {
    'css_files': ['_static/custom.css'],
}

好的,原來我必須使用:undoc-members:但它造成了混亂。

這是必需的,因為未正確記錄django的AbstractUser類,並且必須強制sphinx顯示僅定義了undoc-members的字段。 但是undoc-members會造成混亂,因此解決方案只是在子類的docstr中添加未在父類中記錄的屬性/方法的文檔,之后我的文檔顯示了這些字段

class AppUser(AbstractUser):
    """Custom user model.

    Attributes:
        avatar (file): user's avatar, cropeed to fill 300x300 px
        notifications (dict): settings for notifications to user
        first_name (str): first name
        last_name (str): last name
    """

在此處輸入圖片說明

暫無
暫無

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

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