5

我将如何使用bump2version(关于它的调用和/或其配置)来增加:

1.0.0.a2.post0 # post-release of a pre-release a2

1.0.0.a3 # pre-release a3

可重现的例子:

$ python3 -m pip install 'bump2version==1.0.*'

__init__.py

__version__ = "1.0.0.a2.post0"

setup.cfg

[bumpversion]
current_version = 1.0.0.a2.post0
parse = ^
    (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)  # minimum major.minor.patch, 1.2.3
    (?:
    \.
    (?P<prerel>a|alpha|b|beta|d|dev|rc)  # pre-release segment
    (?P<prerelversion>\d+)  # pre-release version num
    )?
    (?:\.post(?P<post>\d+))?  # post-release
serialize =
    {major}.{minor}.{patch}.{prerel}{prerelversion}.post{post}
    {major}.{minor}.{patch}.{prerel}{prerelversion}
    {major}.{minor}.{patch}.post{post}
    {major}.{minor}.{patch}

[bumpversion:file:__init__.py]

[bumpversion:part:prerel]
optional_value = dev
values =
    dev
    d
    alpha
    a
    beta
    b
    rc

此方案的有效版本示例,它采用 PEP 440 中的一些但不是全部规则:

1.2.3             # (1) final

1.2.3.dev0        # (2) prerelease
1.2.3.a0
1.2.3.alpha0
1.2.3.b0
1.2.3.beta0
1.2.3.rc0

1.2.3.rc3.post0   # (3) postrelease (of a pre-release version)

1.2.3.post0       # (4) postrelease (of a final version)

例如,我已经尝试过,bump2version --verbose prerelversion或者--new-version=1.0.0.a3明确地尝试过。这两种尝试都保留.post0而不是放弃它。


注意:几周前我在bump2version repo中将此作为一个使用问题问题提出来,但没有运气。

4

1 回答 1

1

我们不得不与那个(而且,在过去,与原来的bumpversion,而不是更好的bump2version)搏斗。

使用下面的配置,您可以使用to bumpversion prego from 。1.0.0.a2.post01.0.0.a3

说明

由于preand posteach 都有一个字符串前缀和一个数字,我认为有必要对它们进行相应的拆分。例如,pre可以将部分拆分为一个prekind(字符串)和一个pre(数字)。然后,好处是您可以独立于问题编号(序列,如往常)递增prekind'dev''alpha''beta'等)。

下面,我将一个完整的配置和一个包含多个调用的示例依次显示,以显示可能的各种突变。我确信下面的设置可以进一步定制,但希望它能让你和其他人在正确的轨道上着陆。

cat > .bumpversion.cfg << "EOF"
[bumpversion]
current_version = 1.0.0.a2.post0
files = __init__.py
commit = False
parse = ^
        (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
        (\.(?P<prekind>a|alpha|b|beta|d|dev|rc)
        (?P<pre>\d+)  # pre-release version num
        )?
        (\.(?P<postkind>post)(?P<post>\d+))?  # post-release
serialize = 
        {major}.{minor}.{patch}.{prekind}{pre}.{postkind}{post}
        {major}.{minor}.{patch}.{prekind}{pre}
        {major}.{minor}.{patch}.{postkind}{post}
        {major}.{minor}.{patch}

[bumpversion:part:prekind]
optional_value = _
values =
    _
    dev
    d
    alpha
    a
    beta
    b
    rc

[bumpversion:part:postkind]
optional_value = _
values =
    _
    post
EOF

echo '__version__ = "1.0.0.a2.post0"' > __init__.py

测试

它们执行一系列颠簸版本操作以演示一些可能的突变。当然,您可以使用--new-version=...来强制设置新版本。

for op in \
    start post post pre pre prekind prekind pre postkind post prekind minor \
    postkind post pre postkind prekind postkind post major prekind postkind post; do
  if [[ $op == 'start' ]]; then
    printf "starting from: %s\n" $(perl -ne 'print "$1\n" if /"(.*)"/' __init__.py)
  else
    bumpversion $op
    printf "%10s --> %s\n" $op $(perl -ne 'print "$1\n" if /"(.*)"/' __init__.py)
  fi
done

输出(评论):

starting from: 1.0.0.a2.post0
      post --> 1.0.0.a2.post1   # no issue incrementing post
      post --> 1.0.0.a2.post2   
       pre --> 1.0.0.a3         # can move to the next 'pre'release
       pre --> 1.0.0.a4 
   prekind --> 1.0.0.beta0      # can upgrade the kind of prerelease
   prekind --> 1.0.0.b0 
       pre --> 1.0.0.b1         # and keep incrementing 
  postkind --> 1.0.0.b1.post0   # bring a post component again  
      post --> 1.0.0.b1.post1   # and incrementing
   prekind --> 1.0.0.rc0        # upgrade pre kind directly
     minor --> 1.1.0            # patch/minor/major cut the optional parts
  postkind --> 1.1.0.post0      # but we can bring a post component (without pre)
      post --> 1.1.0.post1
       pre --> 1.1.0            # BAD & silent: cannot increment a missing part 
  postkind --> 1.1.0.post0
   prekind --> 1.1.0.dev0       # default: pre part starts at 'dev'
  postkind --> 1.1.0.dev0.post0 # can add post part to a pre part
      post --> 1.1.0.dev0.post1 # etc...
     major --> 2.0.0
   prekind --> 2.0.0.dev0
  postkind --> 2.0.0.dev0.post0
      post --> 2.0.0.dev0.post1
于 2020-12-10T04:04:48.953 回答