Python 是否可以通过读取文档在构建时生成图像和.rst文件?

Python 是否可以通过读取文档在构建时生成图像和.rst文件?,python,read-the-docs,Python,Read The Docs,我有一个Python包,其中包含一个数据模块,其中包含一些.json格式的数据()。我想在我的在线文档中记录这些数据,如图() 是否可以在readthedocs构建中实现python脚本,并以这种方式自动记录数据?我认为,这将是有用的,因为数据中的更改将自动记录。或者,这是不好的做法吗 目前,我使用python脚本在本地创建.rst文件(tespy.data.rst)以及绘图(.svg格式),并将它们上载到github存储库。我的代码需要matplotlib,pkg_资源以及json,看起来像这

我有一个Python包,其中包含一个数据模块,其中包含一些.json格式的数据()。我想在我的在线文档中记录这些数据,如图()

是否可以在readthedocs构建中实现python脚本,并以这种方式自动记录数据?我认为,这将是有用的,因为数据中的更改将自动记录。或者,这是不好的做法吗

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


我能够解决这个问题:我将绘图代码集成到conf.py中。此外,我还为matplotlib添加了readthedocs要求。见:和

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)