我可以使用在sphinx文档中显示版本历史记录表吗conf.py?

2024-04-24 04:38:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要在每次编译时增加版本计数,并显示当前日期并以表的形式显示。在


Tags: 版本形式计数
1条回答
网友
1楼 · 发布于 2024-04-24 04:38:02

sphinx没有自动增加版本号的固有方法。但是自从配置文件是一个python文件,可以实现包含在配置文件它从非易失性内存(例如json文件)读取版本,输出日期表并更新非易失性内存中递增的版本号。可能是这样(如果json内容是“[12,7,1,0]”):

# Read the version number from conf.json
fp = open( 'conf.json', 'r')
rev = json.load( fp ) # rev = [12,7,1,0]
fp.close

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#

# The short X.Y version.
version = '{}.{}'.format(rev[0], rev[1]) # version = "12.7"

# The full version, including alpha/beta/rc tags.
release = '{}.{}.{}.{}'.format(*rev) # release = "12.7.1.0"

# Write the incremented version number to conf.json
fp = open ( 'conf.json', 'w')
rev[0] += 1
json.dump( rev, fp )
fp.close()

相关问题 更多 >