Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3d3b90c

Browse files
bearomorphismLee-W
authored andcommitted
refactor: improve readability and fix typos
1 parent a8094ae commit 3d3b90c

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
@@ -637,14 +637,10 @@ def main():
637637
extra_args = " ".join(unknown_args[1:])
638638
arguments["extra_cli_args"] = extra_args
639639

640-
if args.config:
641-
conf = config.read_cfg(args.config)
642-
else:
643-
conf = config.read_cfg()
644-
640+
conf = config.read_cfg(args.config)
645641
if args.name:
646642
conf.update({"name": args.name})
647-
elif not args.name and not conf.path:
643+
elif not conf.path:
648644
conf.update({"name": "cz_conventional_commits"})
649645

650646
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
@@ -141,7 +141,7 @@ class Settings(TypedDict, total=False):
141141
def get_tag_regexes(
142142
version_regex: str,
143143
) -> dict[str, str]:
144-
regexs = {
144+
regexes = {
145145
"version": version_regex,
146146
"major": r"(?P<major>\d+)",
147147
"minor": r"(?P<minor>\d+)",
@@ -150,6 +150,6 @@ def get_tag_regexes(
150150
"devrelease": r"(?P<devrelease>\.dev\d+)?",
151151
}
152152
return {
153-
**{f"${k}": v for k, v in regexs.items()},
154-
**{f"${{{k}}}": v for k, v in regexs.items()},
153+
**{f"${k}": v for k, v in regexes.items()},
154+
**{f"${{{k}}}": v for k, v in regexes.items()},
155155
}

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
@@ -1236,7 +1236,7 @@ def test_order_changelog_tree_raises():
12361236
with pytest.raises(InvalidConfigurationError) as excinfo:
12371237
changelog.order_changelog_tree(COMMITS_TREE, change_type_order)
12381238

1239-
assert "Change types contain duplicates types" in str(excinfo)
1239+
assert "Change types contain duplicated types" in str(excinfo)
12401240

12411241

12421242
def test_render_changelog(

0 commit comments

Comments
 (0)