Skip to content

Commit a0330e7

Browse files
committed
refactor: improve readability and fix typos
1 parent a0cc490 commit a0330e7

File tree

7 files changed

+23
-30
lines changed

7 files changed

+23
-30
lines changed

commitizen/bump.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def update_version_in_files(
7676
"""
7777
# TODO: separate check step and write step
7878
updated = []
79-
for path, regex in files_and_regexs(files, current_version):
79+
for path, regex in _files_and_regexes(files, current_version):
8080
current_version_found, version_file = _bump_with_regex(
8181
path,
8282
current_version,
@@ -99,7 +99,7 @@ def update_version_in_files(
9999
return updated
100100

101101

102-
def files_and_regexs(patterns: list[str], version: str) -> list[tuple[str, str]]:
102+
def _files_and_regexes(patterns: list[str], version: str) -> list[tuple[str, str]]:
103103
"""
104104
Resolve all distinct files with their regexp from a list of glob patterns with optional regexp
105105
"""
@@ -128,13 +128,15 @@ def _bump_with_regex(
128128
pattern = re.compile(regex)
129129
with open(version_filepath, encoding=encoding) as f:
130130
for line in f:
131-
if pattern.search(line):
132-
bumped_line = line.replace(current_version, new_version)
133-
if bumped_line != line:
134-
current_version_found = True
135-
lines.append(bumped_line)
136-
else:
131+
if not pattern.search(line):
137132
lines.append(line)
133+
continue
134+
135+
bumped_line = line.replace(current_version, new_version)
136+
if bumped_line != line:
137+
current_version_found = True
138+
lines.append(bumped_line)
139+
138140
return current_version_found, "".join(lines)
139141

140142

commitizen/changelog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def process_commit_message(
190190
def order_changelog_tree(tree: Iterable, change_type_order: list[str]) -> Iterable:
191191
if len(set(change_type_order)) != len(change_type_order):
192192
raise InvalidConfigurationError(
193-
f"Change types contain duplicates types ({change_type_order})"
193+
f"Change types contain duplicated types ({change_type_order})"
194194
)
195195

196196
sorted_tree = []

commitizen/cli.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,10 @@ def main():
633633
extra_args = " ".join(unknown_args[1:])
634634
arguments["extra_cli_args"] = extra_args
635635

636-
if args.config:
637-
conf = config.read_cfg(args.config)
638-
else:
639-
conf = config.read_cfg()
640-
636+
conf = config.read_cfg(args.config)
641637
if args.name:
642638
conf.update({"name": args.name})
643-
elif not args.name and not conf.path:
639+
elif not conf.path:
644640
conf.update({"name": "cz_conventional_commits"})
645641

646642
if args.debug:

commitizen/cz/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from commitizen import git
66
from commitizen.cz import exceptions
77

8+
_RE_LOCAL_VERSION = re.compile(r"\+.+")
9+
810

911
def required_validator(answer, msg=None):
1012
if not answer:
@@ -17,16 +19,13 @@ def multiple_line_breaker(answer, sep="|"):
1719

1820

1921
def strip_local_version(version: str) -> str:
20-
return re.sub(r"\+.+", "", version)
22+
return _RE_LOCAL_VERSION.sub("", version)
2123

2224

2325
def get_backup_file_path() -> str:
2426
project_root = git.find_git_project_root()
25-
26-
if project_root is None:
27-
project = ""
28-
else:
29-
project = project_root.as_posix().replace("/", "%")
27+
project = project_root.as_posix().replace("/", "%") if project_root else ""
3028

3129
user = os.environ.get("USER", "")
30+
3231
return os.path.join(tempfile.gettempdir(), f"cz.commit%{user}%{project}.backup")

commitizen/defaults.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class Settings(TypedDict, total=False):
142142
def get_tag_regexes(
143143
version_regex: str,
144144
) -> dict[str, str]:
145-
regexs = {
145+
regexes = {
146146
"version": version_regex,
147147
"major": r"(?P<major>\d+)",
148148
"minor": r"(?P<minor>\d+)",
@@ -151,6 +151,6 @@ def get_tag_regexes(
151151
"devrelease": r"(?P<devrelease>\.dev\d+)?",
152152
}
153153
return {
154-
**{f"${k}": v for k, v in regexs.items()},
155-
**{f"${{{k}}}": v for k, v in regexs.items()},
154+
**{f"${k}": v for k, v in regexes.items()},
155+
**{f"${{{k}}}": v for k, v in regexes.items()},
156156
}

commitizen/tags.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ def include_in_changelog(self, tag: GitTag) -> bool:
174174
version = self.extract_version(tag)
175175
except InvalidVersion:
176176
return False
177-
178-
if self.merge_prereleases and version.is_prerelease:
179-
return False
180-
181-
return True
177+
return not (self.merge_prereleases and version.is_prerelease)
182178

183179
def search_version(self, text: str, last: bool = False) -> VersionTag | None:
184180
"""

tests/test_changelog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ def test_order_changelog_tree_raises():
12381238
with pytest.raises(InvalidConfigurationError) as excinfo:
12391239
changelog.order_changelog_tree(COMMITS_TREE, change_type_order)
12401240

1241-
assert "Change types contain duplicates types" in str(excinfo)
1241+
assert "Change types contain duplicated types" in str(excinfo)
12421242

12431243

12441244
def test_render_changelog(

0 commit comments

Comments
 (0)