【问题标题】:No Pre-Release Tags if Major Version is 0如果主要版本为 0,则没有预发布标签
【发布时间】:2021-04-29 21:05:41
【问题描述】:

我正在使用带有语义版本控制的bump2version。如果主要版本为 0(即快速开发?),有没有办法防止标签的预发布组件出现。就目前而言,我的.bumpversion.cfg 是

[bumpversion]
current_version = 0.0.0
tag = False
tag_name = {new_version}
commit = True
parse =
    (?P<major>\d+)
    \.
    (?P<minor>\d+)
    \.
    (?P<patch>\d+)
    (\-(?P<pre>[a-z]+)\.(?P<prenum>\d+))?
serialize =
    {major}.{minor}.{patch}-{pre}.{prenum}
    {major}.{minor}.{patch}

[bumpversion:part:pre]
optional_value = placeholder
first_value = alpha
values =
    alpha
    beta
    rc
    placeholder

[bumpversion:part:prenum]
first_value = 1

[bumpversion:file:pyproject.toml]

当我碰到部分minor时添加预发布值

>>> bumpversion minor
Bumpversion: 0.0.0 -> 0.1.0-alpha.1

我不希望 -alpha.N、-beta.N 等标签的一部分在我处于主要版本 0 时出现(即快速开发;不会发生预发布测试我直到主要版本 1 和更高版本。

对于所有N &gt; 0,我确实想要从主要版本0 到1 或N 到N+1 的预发布部分(因为预发布测试将在这些阶段进行),只是不是为了快速发展。当我处于快速开发阶段时(尤其是因为在 1.0.0 之前我会有很多版本),我不想每次颠簸都手动输入 --new-version。

有人有解决办法吗?

【问题讨论】:

  • 你有什么不做bumpversion minor --no-tag的特殊原因吗?
  • @florisla 因为我确实想要一个标签。当我处于主要版本0(快速开发)时,我只是不希望标签的预发布部分出现。我会更新我的问题的措辞,因为我知道这会被误读。

标签: python bump2version


【解决方案1】:

作为“猴子补丁”/解决方法,我在 bumpversion.version_part 中编辑了函数 _choose_serialize_format() 来自

def _choose_serialize_format(self, version, context):

        chosen = None

        logger.debug(
            "Available serialization formats: '%s'", "', '".join(self.serialize_formats)
        )

        for serialize_format in self.serialize_formats:
            try:
                self._serialize(
                    version, serialize_format, context, raise_if_incomplete=True
                )
                chosen = serialize_format
                logger.debug("Found '%s' to be a usable serialization format", chosen)
            except IncompleteVersionRepresentationException as e:
                if not chosen:
                    chosen = serialize_format
            except MissingValueForSerializationException as e:
                logger.info(e.message)
                raise e

        if not chosen:
            raise KeyError("Did not find suitable serialization format")

        logger.debug("Selected serialization format '%s'", chosen)

        return chosen

到

def _choose_serialize_format(self, version, context):

        chosen = None

        logger.debug(
            "Available serialization formats: '%s'", "', '".join(self.serialize_formats)
        )

        if version._values["major"].value == "0":
            _serialize_formats = [
                self.serialize_formats[-1],
            ]
        else:
            _serialize_formats = self.serialize_formats

        for serialize_format in _serialize_formats:
            try:
                self._serialize(
                    version, serialize_format, context, raise_if_incomplete=True
                )
                chosen = serialize_format
                logger.debug("Found '%s' to be a usable serialization format", chosen)
            except IncompleteVersionRepresentationException as e:
                if not chosen:
                    chosen = serialize_format
            except MissingValueForSerializationException as e:
                logger.info(e.message)
                raise e

        if not chosen:
            raise KeyError("Did not find suitable serialization format")

        logger.debug("Selected serialization format '%s'", chosen)

        return chosen

添加的行是

if version._values["major"].value == "0":
    _serialize_formats = [
        self.serialize_formats[-1],
    ]
else:
    _serialize_formats = self.serialize_formats

而改变的行是

for serialize_format in self.serialize_formats:

到

for serialize_format in _serialize_formats:

【讨论】:

    猜你喜欢
    • 2018-02-21
    • 2021-07-06
    • 1970-01-01
    • 2017-11-17
    • 1970-01-01
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多