Skip to content

Commit

Permalink
fix: Add mutual exclusive flags for micro
Browse files Browse the repository at this point in the history
Micro and no-micro can now be used.
Micro is the default, no-micro must explicitly enabled.

Both values can be set to false, IF old behavior shall be restored
  • Loading branch information
carstencodes committed Jul 23, 2024
1 parent e3ac40d commit be6dc28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
45 changes: 32 additions & 13 deletions src/pdm_bump/actions/preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(
self,
version: "Version",
persister: "VersionPersister",
increment_micro: bool = True,
increment_micro: bool,
**kwargs,
) -> None:
super().__init__(version, persister, **kwargs)
Expand All @@ -79,13 +79,23 @@ def _update_command(cls, sub_parser: "ArgumentParser") -> None:
-------
"""
sub_parser.add_argument(
"--no-micro",
action="store_false",
grp = sub_parser.add_mutually_exclusive_group(required=False)
grp.add_argument(
"--micro",
action="store_true",
dest="increment_micro",
help="When setting pre-release, specifies "
+ "that micro version shall not "
+ "be incremented as well",
help="If set, the micro version will be incremented. This is the "
"default, if you are not incrementing a version that is a pre-"
"release yet. Cannot be mixed with --no-micro.",
)

grp.add_argument(
"--no-micro",
action="store_true",
dest="no_increment_micro",
help="If set, do not increment the micro version, even it would"
"apply as it is no pre-release version yet. Cannot be mixed "
"with --micro.",
)

VersionModifier._update_command(sub_parser)
Expand Down Expand Up @@ -183,37 +193,46 @@ class PreReleaseIncrementingVersionModifier(VersionModifier):
"Increment a pre-release part (alpha, beta, release-candidate)"
)

def __init__(
# Justification: self and kwargs should not count, both boolean
# arguments must be applied due to arg-parse implementation
def __init__( # pylint: disable=R0913
self,
version: "Version",
persister: "VersionPersister",
pre_release_part: "Optional[str]",
increment_micro: bool = True,
increment_micro: bool,
no_increment_micro: bool,
**kwargs,
) -> None:
super().__init__(version, persister, **kwargs)

do_increment_micro: bool = (
increment_micro
or not no_increment_micro
or not version.is_pre_release
)

if pre_release_part is None:
pre_release_part = (
version.preview[0]
if version.preview is not None
else AlphaIncrementingVersionModifier.name
)
increment_micro = not version.is_pre_release

self.__sub_modifier: VersionModifier
if (
pre_release_part in (AlphaIncrementingVersionModifier.name,)
or pre_release_part in AlphaIncrementingVersionModifier.aliases
):
self.__sub_modifier = AlphaIncrementingVersionModifier(
version, _DummyPersister(), increment_micro
version, _DummyPersister(), do_increment_micro
)
elif (
pre_release_part in (BetaIncrementingVersionModifier.name,)
or pre_release_part in BetaIncrementingVersionModifier.aliases
):
self.__sub_modifier = BetaIncrementingVersionModifier(
version, _DummyPersister(), increment_micro
version, _DummyPersister(), do_increment_micro
)
elif (
pre_release_part
Expand All @@ -222,7 +241,7 @@ def __init__(
in ReleaseCandidateIncrementingVersionModifier.aliases
):
self.__sub_modifier = ReleaseCandidateIncrementingVersionModifier(
version, _DummyPersister(), increment_micro
version, _DummyPersister(), do_increment_micro
)
else:
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions src/pdm_bump/actions/version_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def __select_micro_version_modifier(self):
self.__version.preview
)
modifier = PreReleaseIncrementingVersionModifier(
self.__version, self, pre_release_part, False
self.__version, self, pre_release_part, False, True
)
else:
modifier = ResetNonSemanticPartsModifier(self.__version, self)
Expand All @@ -201,7 +201,7 @@ def __select_minor_version_modifier(self):
)
pre_release_part = self.__shift_preview_part(pre_release_part)
modifier = PreReleaseIncrementingVersionModifier(
self.__version, self, pre_release_part, False
self.__version, self, pre_release_part, False, True
)
return modifier

Expand Down

0 comments on commit be6dc28

Please sign in to comment.