我可以使用 conf.py 在 sphinx 文档中显示版本历史记录 table 吗?
Can I display a version history table in sphinx documentation using conf.py?
我需要在每次编译时增加版本计数并显示当前日期并以 table.
的形式显示
没有自动增加版本号的 sphinx 固有方法。但是由于 conf.py 是一个 python 文件,您可以实现 conf.py 中包含的一个小函数,它从非易失性存储器(例如 json 文件)中读取版本,输出你的日期 table 并更新非易失性存储器中递增的版本号。也许像这样(如果 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()
我需要在每次编译时增加版本计数并显示当前日期并以 table.
的形式显示没有自动增加版本号的 sphinx 固有方法。但是由于 conf.py 是一个 python 文件,您可以实现 conf.py 中包含的一个小函数,它从非易失性存储器(例如 json 文件)中读取版本,输出你的日期 table 并更新非易失性存储器中递增的版本号。也许像这样(如果 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()