Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 865a22e

Browse filesBrowse files
committed
refactor: improve readability and fix typos
1 parent 2cb2daf commit 865a22e
Copy full SHA for 865a22e

File tree

7 files changed

+27
-34
lines changed
Filter options

7 files changed

+27
-34
lines changed

‎commitizen/bump.py

Copy file name to clipboardExpand all lines: commitizen/bump.py
+15-11Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,20 @@ def find_increment(
3030
increment: str | None = None
3131

3232
for commit in commits:
33-
for message in commit.message.split("\n"):
34-
result = select_pattern.search(message)
35-
36-
if result:
33+
for message in filter(
34+
None, map(select_pattern.search, commit.message.split("\n"))
35+
):
36+
if result := select_pattern.search(message):
3737
found_keyword = result.group(1)
38-
new_increment = None
39-
for match_pattern in increments_map.keys():
40-
if re.match(match_pattern, found_keyword):
41-
new_increment = increments_map[match_pattern]
42-
break
38+
39+
new_increment = next(
40+
(
41+
increment_type
42+
for match_pattern, increment_type in increments_map.items()
43+
if re.match(match_pattern, found_keyword)
44+
),
45+
None,
46+
)
4347

4448
if new_increment is None:
4549
logger.debug(
@@ -76,7 +80,7 @@ def update_version_in_files(
7680
"""
7781
# TODO: separate check step and write step
7882
updated = []
79-
for path, regex in files_and_regexs(files, current_version):
83+
for path, regex in _files_and_regexes(files, current_version):
8084
current_version_found, version_file = _bump_with_regex(
8185
path,
8286
current_version,
@@ -99,7 +103,7 @@ def update_version_in_files(
99103
return updated
100104

101105

102-
def files_and_regexs(patterns: list[str], version: str) -> list[tuple[str, str]]:
106+
def _files_and_regexes(patterns: list[str], version: str) -> list[tuple[str, str]]:
103107
"""
104108
Resolve all distinct files with their regexp from a list of glob patterns with optional regexp
105109
"""

‎commitizen/changelog.py

Copy file name to clipboardExpand all lines: commitizen/changelog.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: commitizen/cli.py
+2-6Lines 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 or None)
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

Copy file name to clipboardExpand all lines: commitizen/cz/utils.py
+4-7Lines changed: 4 additions & 7 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,11 @@ 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("/", "%")
30-
27+
project = "" if project_root is None else project_root.as_posix().replace("/", "%")
3128
user = os.environ.get("USER", "")
3229
return os.path.join(tempfile.gettempdir(), f"cz.commit%{user}%{project}.backup")

‎commitizen/defaults.py

Copy file name to clipboardExpand all lines: commitizen/defaults.py
+3-3Lines 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

Copy file name to clipboardExpand all lines: commitizen/tags.py
+1-5Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,7 @@ def include_in_changelog(self, tag: GitTag) -> bool:
172172
version = self.extract_version(tag)
173173
except InvalidVersion:
174174
return False
175-
176-
if self.merge_prereleases and version.is_prerelease:
177-
return False
178-
179-
return True
175+
return not (self.merge_prereleases and version.is_prerelease)
180176

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

‎tests/test_changelog.py

Copy file name to clipboardExpand all lines: tests/test_changelog.py
+1-1Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.