首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以在构建时使用read-the-docs生成图像和.rst文件?

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

Stack Overflow用户
提问于 2020-01-11 00:55:30
回答 1查看 68关注 0票数 0

我有一个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,看起来像这样(伪代码可以吗,或者我应该添加完整代码?)。

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-17 23:11:05

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59685898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档