Skip to content

Commit 3193887

Browse files
committed
refactor: make methods protected, better type
1 parent 5b3d4db commit 3193887

File tree

6 files changed

+24
-21
lines changed

6 files changed

+24
-21
lines changed

commitizen/commands/bump.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def __init__(self, config: BaseConfig, arguments: dict):
101101
)
102102
self.extras = arguments["extras"]
103103

104-
def is_initial_tag(
104+
def _is_initial_tag(
105105
self, current_tag: git.GitTag | None, is_yes: bool = False
106106
) -> bool:
107107
"""Check if reading the whole git tree up to HEAD is needed."""
@@ -118,7 +118,7 @@ def is_initial_tag(
118118
)
119119
return bool(questionary.confirm("Is this the first tag created?").ask())
120120

121-
def find_increment(self, commits: list[git.GitCommit]) -> Increment | None:
121+
def _find_increment(self, commits: list[git.GitCommit]) -> Increment | None:
122122
# Update the bump map to ensure major version doesn't increment.
123123
is_major_version_zero: bool = self.bump_settings["major_version_zero"]
124124
# self.cz.bump_map = defaults.bump_map_major_version_zero
@@ -135,7 +135,7 @@ def find_increment(self, commits: list[git.GitCommit]) -> Increment | None:
135135
)
136136
return bump.find_increment(commits, regex=bump_pattern, increments_map=bump_map)
137137

138-
def __call__(self) -> None: # noqa: C901
138+
def __call__(self) -> None:
139139
"""Steps executed to bump."""
140140
provider = get_provider(self.config)
141141

@@ -227,7 +227,7 @@ def __call__(self) -> None: # noqa: C901
227227
current_tag, "name", rules.normalize_tag(current_version)
228228
)
229229

230-
is_initial = self.is_initial_tag(current_tag, is_yes)
230+
is_initial = self._is_initial_tag(current_tag, is_yes)
231231

232232
if manual_version:
233233
try:
@@ -255,7 +255,7 @@ def __call__(self) -> None: # noqa: C901
255255
"[NO_COMMITS_FOUND]\nNo new commits found."
256256
)
257257

258-
increment = self.find_increment(commits)
258+
increment = self._find_increment(commits)
259259

260260
# It may happen that there are commits, but they are not eligible
261261
# for an increment, this generates a problem when using prerelease (#281)

commitizen/commands/changelog.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _find_incremental_rev(self, latest_version: str, tags: Iterable[GitTag]) ->
136136
raise NoRevisionError()
137137
return start_rev
138138

139-
def write_changelog(
139+
def _write_changelog(
140140
self, changelog_out: str, lines: list[str], changelog_meta: changelog.Metadata
141141
):
142142
with smart_open(self.file_name, "w", encoding=self.encoding) as changelog_file:
@@ -153,7 +153,7 @@ def write_changelog(
153153

154154
changelog_file.write(changelog_out)
155155

156-
def export_template(self) -> None:
156+
def _export_template(self) -> None:
157157
tpl = changelog.get_changelog_template(self.cz.template_loader, self.template)
158158
src = Path(tpl.filename) # type: ignore
159159
Path(self.export_template_to).write_text(src.read_text()) # type: ignore
@@ -173,7 +173,7 @@ def __call__(self) -> None:
173173
)
174174

175175
if self.export_template_to:
176-
return self.export_template()
176+
return self._export_template()
177177

178178
if not changelog_pattern or not commit_parser:
179179
raise NoPatternMapError(
@@ -240,4 +240,4 @@ def __call__(self) -> None:
240240
with open(self.file_name, encoding=self.encoding) as changelog_file:
241241
lines = changelog_file.readlines()
242242

243-
self.write_changelog(changelog_out, lines, changelog_meta)
243+
self._write_changelog(changelog_out, lines, changelog_meta)

commitizen/commands/commit.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, config: BaseConfig, arguments: dict):
4141
self.arguments = arguments
4242
self.temp_file: str = get_backup_file_path()
4343

44-
def read_backup_message(self) -> str | None:
44+
def _read_backup_message(self) -> str | None:
4545
# Check the commit backup file exists
4646
if not os.path.isfile(self.temp_file):
4747
return None
@@ -50,7 +50,7 @@ def read_backup_message(self) -> str | None:
5050
with open(self.temp_file, encoding=self.encoding) as f:
5151
return f.read().strip()
5252

53-
def prompt_commit_questions(self) -> str:
53+
def _prompt_commit_questions(self) -> str:
5454
# Prompt user for the commit message
5555
cz = self.cz
5656
questions = cz.questions()
@@ -96,16 +96,16 @@ def manual_edit(self, message: str) -> str:
9696

9797
def _get_message(self) -> str:
9898
if self.arguments.get("retry"):
99-
m = self.read_backup_message()
99+
m = self._read_backup_message()
100100
if m is None:
101101
raise NoCommitBackupError()
102102
return m
103103

104104
if self.config.settings.get("retry_after_failure") and not self.arguments.get(
105105
"no_retry"
106106
):
107-
return self.read_backup_message() or self.prompt_commit_questions()
108-
return self.prompt_commit_questions()
107+
return self._read_backup_message() or self._prompt_commit_questions()
108+
return self._prompt_commit_questions()
109109

110110
def __call__(self) -> None:
111111
extra_args = cast(str, self.arguments.get("extra_cli_args", ""))

commitizen/commands/init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def __init__(self, config: BaseConfig, *args):
8585
self.cz = factory.committer_factory(self.config)
8686
self.project_info = ProjectInfo()
8787

88-
def __call__(self):
88+
def __call__(self) -> None:
8989
if self.config.path:
9090
out.line(f"Config file {self.config.path} already exists")
9191
return
@@ -120,7 +120,7 @@ def __call__(self):
120120
self.config = JsonConfig(data="{}", path=config_path)
121121
elif "yaml" in config_path:
122122
self.config = YAMLConfig(data="", path=config_path)
123-
values_to_add = {}
123+
values_to_add: dict[str, Any] = {}
124124
values_to_add["name"] = cz_name
125125
values_to_add["tag_format"] = tag_format
126126
values_to_add["version_scheme"] = version_scheme

commitizen/config/base_config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,6 @@ def update(self, data: Settings) -> None:
4141

4242
def _parse_setting(self, data: bytes | str) -> None:
4343
raise NotImplementedError()
44+
45+
def init_empty_config_content(self) -> None:
46+
raise NotImplementedError()

tests/commands/test_bump_command.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,7 +1692,7 @@ def test_bump_warn_but_dont_fail_on_invalid_tags(
16921692

16931693

16941694
def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project):
1695-
"""Test the is_initial_tag method behavior."""
1695+
"""Test the _is_initial_tag method behavior."""
16961696
# Create a commit but no tags
16971697
create_file_and_commit("feat: initial commit")
16981698

@@ -1725,15 +1725,15 @@ def test_is_initial_tag(mocker: MockFixture, tmp_commitizen_project):
17251725

17261726
# Test case 1: No current tag, not yes mode
17271727
mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: True))
1728-
assert bump_cmd.is_initial_tag(None, is_yes=False) is True
1728+
assert bump_cmd._is_initial_tag(None, is_yes=False) is True
17291729

17301730
# Test case 2: No current tag, yes mode
1731-
assert bump_cmd.is_initial_tag(None, is_yes=True) is True
1731+
assert bump_cmd._is_initial_tag(None, is_yes=True) is True
17321732

17331733
# Test case 3: Has current tag
17341734
mock_tag = mocker.Mock()
1735-
assert bump_cmd.is_initial_tag(mock_tag, is_yes=False) is False
1735+
assert bump_cmd._is_initial_tag(mock_tag, is_yes=False) is False
17361736

17371737
# Test case 4: No current tag, user denies
17381738
mocker.patch("questionary.confirm", return_value=mocker.Mock(ask=lambda: False))
1739-
assert bump_cmd.is_initial_tag(None, is_yes=False) is False
1739+
assert bump_cmd._is_initial_tag(None, is_yes=False) is False

0 commit comments

Comments
 (0)