我的工作流程在包的init .py 中嵌入了一个__version__包变量。当使用诗歌(或类似的)更新包版本时,我也希望我的嵌入变量得到更新。poetry version patch__version__
我目前使用预提交挂钩(git),如下所示:
#!/bin/bash
read name version < <(poetry version)
read pversion < <(python -c "from ${name} import __version__;print(__version__)")
init=${name}/__init__.py
if [[ "${pversion}" != "${version}" ]]; then
(
cat <<-UPDATEINIT
""" ${name} package"""
__version__ = "${version}"
UPDATEINIT
) >$init
git add $init
fi
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法我错过了,因为那个钩子看起来有点“笨重”。