Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CLI in line with intended default for increment_micro #329

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 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(
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 "
+ "whether micro version shall "
+ "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
Loading