Mik*_*ton 9 python makefile pyproject.toml
我有一个带有pyproject.toml文件的 python 项目。通常我将项目的版本号存储为pyproject.toml这样:
% grep version pyproject.toml
version = "0.0.2"
%
Run Code Online (Sandbox Code Playgroud)
我想将该版本号放入Makefile变量中,无论版本术语周围有多少空格。
我应该怎么做才能将pyproject.toml版本字符串提取到Makefile名为 的环境变量中VERSION?
这似乎是最好的...我把它放在我的Makefile
# grep the version from pyproject.toml, squeeze multiple spaces, delete double
# and single quotes, get 3rd val. This command tolerates
# multiple whitespace sequences around the version number
VERSION := $(shell grep -m 1 version pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
Run Code Online (Sandbox Code Playgroud)
特别感谢@charl-botha的-m 1grep 论点...gnu 和 bsd grep-m在这种情况下都支持。
major.minor.patch基于@Mike Pennington的答案的parse 的替代解决方案:
grep -m 1 version pyproject.toml | grep -e '\d.\d.\d' -o
Run Code Online (Sandbox Code Playgroud)