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

问题描述 投票:0回答:1

我有一个Python软件包,其中包含一个数据模块,该数据模块带有一些.json格式(https://github.com/oemof/tespy/tree/dev/tespy/data)的数据。我想在这样的在线文档中将这些数据记录为图表(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)
python read-the-docs
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.