是否可以使用 read-the-docs 在构建时生成图像和 .rst 文件?

Is it possible to generate images and .rst files on build with read-the-docs?

我有一个 Python 包,其中包含一个数据模块,其中包含一些 .json 格式的数据 (https://github.com/oemof/tespy/tree/dev/tespy/data). I want to document these data as plots in my online documentation like this (https://tespy.readthedocs.io/en/dev/api/tespy.data.html)。

是否可以在 readthedocs 构建中实施 python 脚本并以这种方式自动记录数据?我认为,这会很有用,因为数据的变化会自动记录下来。或者,这是不好的做法吗?

目前,我有 python 脚本在本地创建 .rst 文件 (tespy.data.rst) 以及绘图(.svg 格式)并将它们上传到 github 存储库。我的代码需要 matplotlibpkg_resources 以及 json,看起来像这样(伪代码可以吗,还是我应该添加完整代码?)。

import json
from matplotlib import pyplot as plt
from pkg_resources import resource_filename

def get_data():
    path = resource_filename('tespy.data', 'char_lines.json')

    with open(path) as f:
        data = json.loads(f.read())

    return data

def plot_line(data):
    fig = plt.figure()
    [plotting_code]
    fig.savefig(path + '.svg')

def generate_rst(data):
    [rst code generation here]
    return rst_code

for key, data in get_data().items():
    [data_handling_code_here]
    plot_line(data)
    rst += generate_rst(data)

我能够解决这个问题:我将绘图代码集成到 conf.py 中。此外,我还添加了 matplotlib 的 readthedocs 要求。参见:https://github.com/oemof/tespy/blob/dev/doc/conf.py and https://github.com/oemof/tespy/blob/dev/rtd_requirements.