简体   繁体   English

pdoc3 或 Sphinx 用于具有嵌套模块的目录

[英]pdoc3 or Sphinx for directory with nested module

My code directory looks like below.我的代码目录如下所示。 I need to generate documentation for all the modules like for sub1,sub2,submoduleA1,submoduleB1 and so on.我需要为 sub1、sub2、submoduleA1、submoduleB1 等所有模块生成文档。 Also as shown for submoduleB2.py: all the modules imports from other modules/submodules也如 submoduleB2.py 所示:所有模块从其他模块/子模块导入

<workspace>
└── toolbox (main folder)
    ├── __init__.py 
    │   
    ├── sub
    │   ├── __init__.py
    │   ├── sub1.py
    │   └── sub2.py     
    │   
    ├── subpackageA
    │   ├── __init__.py
    │   ├── submoduleA1.py
    │   └── submoduleA2.py
    │   
    └── subpackageB
        ├── __init__.py
        ├── submoduleB1.py
        └── submoduleB2.py code[from sub import sub1
                                from subpackageA import submoduleA2 and so on]

code structure for submoduleB2.py submoduleB2.py 的代码结构

from __future__ import absolute_import, division
import copy
import logging
import numpy as np
import pandas as pd
from dc.dc import DataCleaning
from sub.sub1 import ToolboxLogger
from subpackageA import pan

LOGGER = ToolboxLogger(
    "MATH_FUNCTIONS", enableconsolelog=True, enablefilelog=False, loglevel=logging.DEBUG
).logger

"""
Calculations also take into account units of the tags that are passed in

"""
def spread(tag_list):
    """
    Returns the spread of a set of actual tag values

    :param tag_list: List of tag objects
    :type tag_list: list
    :return: Pandas Series of spreads
    :rtype: Pandas Series
    :example:
        >>> tag_list = [tp.RH1_ogt_1,
                    tp.RH1_ogt_2,
                    tp.RH1_ogt_3,
                    tp.RH1_ogt_4,
                    tp.RH1_ogt_5,
                    tp.RH1_ogt_6]
        >>> spread = pan.spread(tag_list)
    """
    # use the same units for everything
    units_to_use = tag_list[0].units
    idxs = tag_list[0].actuals.index
    spread_df = pd.DataFrame(index=idxs)
    spread_series = spread_df.max(axis=1).copy()
    return Q_(spread_series, units_to_use)

I tried to run the pdoc command using anaconda prompt by navigating it to the toolbox folder and executed the below command我尝试使用 anaconda 提示符运行 pdoc 命令,方法是将其导航到工具箱文件夹并执行以下命令

pdoc --html --external-links --all-submodules preprocess/toolbox/subpackageA

after executing this command a "subpackageA" folder was created under toolbox with index.html file but it was all blank执行此命令后,在工具箱下创建了一个带有 index.html 文件的“subpackageA”文件夹,但它都是空白的

Then i tried to generate documentation by providing specific module name然后我尝试通过提供特定的模块名称来生成文档

pdoc --html --external-links --all-submodules preprocess/toolbox/submoduleB2.py

but received this below error: File "C:\Users\preprocess/toolbox/submoduleB2.py", line 16, in from sub import sub1 ImportError: No module named sub.sub1但收到以下错误:文件“C:\Users\preprocess/toolbox/submoduleB2.py”,第 16 行,in from sub import sub1 ImportError: No module named sub.sub1

Can you please tell me how to generate the documentation using pdoc for complete directory?您能告诉我如何使用 pdoc 生成完整目录的文档吗? Or is there any other package which will auto generate the documentation?或者是否还有其他 package 会自动生成文档? I even tried Sphnix, but faced issues in adding the module/submodule paths in config file我什至尝试过 Sphnix,但在配置文件中添加模块/子模块路径时遇到问题

It appears that pdoc3 is throwing that kind of error for a module if it cannot find an import into that module in the python path.如果 pdoc3 无法在 python 路径中找到该模块的导入,它似乎会为模块引发此类错误。 One solution is to put一种解决方案是将

import os, sys
syspath = os.path.dirname(os.path.abspath(__file__))
sys.path.append(path)

into the __init__.py files in each of the subdirectories.进入每个子目录中的__init__.py文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM