5
5
from difflib import SequenceMatcher
6
6
from operator import itemgetter
7
7
from pathlib import Path
8
- from typing import Callable , cast
9
8
10
9
from commitizen import changelog , defaults , factory , git , out
11
10
from commitizen .changelog_formats import get_changelog_format
@@ -32,9 +31,10 @@ def __init__(self, config: BaseConfig, args):
32
31
if not git .is_git_project ():
33
32
raise NotAGitProjectError ()
34
33
35
- self .config : BaseConfig = config
36
- changelog_file_name = args .get ("file_name" ) or cast (
37
- str , self .config .settings .get ("changelog_file" )
34
+ self .config = config
35
+
36
+ changelog_file_name = args .get ("file_name" ) or self .config .settings .get (
37
+ "changelog_file"
38
38
)
39
39
if not isinstance (changelog_file_name , str ):
40
40
raise NotAllowed (
@@ -114,28 +114,28 @@ def _find_incremental_rev(self, latest_version: str, tags: list[GitTag]) -> str:
114
114
on our experience.
115
115
"""
116
116
SIMILARITY_THRESHOLD = 0.89
117
- tag_ratio = map (
118
- lambda tag : (
119
- SequenceMatcher (
120
- None , latest_version , strip_local_version (tag .name )
121
- ).ratio (),
122
- tag ,
123
- ),
124
- tags ,
125
- )
126
117
try :
127
- score , tag = max (tag_ratio , key = itemgetter (0 ))
118
+ score , tag = max (
119
+ (
120
+ (
121
+ SequenceMatcher (
122
+ None , latest_version , strip_local_version (tag .name )
123
+ ).ratio (),
124
+ tag ,
125
+ )
126
+ for tag in tags
127
+ ),
128
+ key = itemgetter (0 ),
129
+ )
128
130
except ValueError :
129
131
raise NoRevisionError ()
130
132
if score < SIMILARITY_THRESHOLD :
131
133
raise NoRevisionError ()
132
- start_rev = tag .name
133
- return start_rev
134
+ return tag .name
134
135
135
136
def write_changelog (
136
137
self , changelog_out : str , lines : list [str ], changelog_meta : changelog .Metadata
137
138
):
138
- changelog_hook : Callable | None = self .cz .changelog_hook
139
139
with smart_open (self .file_name , "w" , encoding = self .encoding ) as changelog_file :
140
140
partial_changelog : str | None = None
141
141
if self .incremental :
@@ -145,8 +145,8 @@ def write_changelog(
145
145
changelog_out = "" .join (new_lines )
146
146
partial_changelog = changelog_out
147
147
148
- if changelog_hook :
149
- changelog_out = changelog_hook (changelog_out , partial_changelog )
148
+ if self . cz . changelog_hook :
149
+ changelog_out = self . cz . changelog_hook (changelog_out , partial_changelog )
150
150
151
151
changelog_file .write (changelog_out )
152
152
@@ -221,14 +221,12 @@ def __call__(self):
221
221
extras .update (self .extras )
222
222
changelog_out = changelog .render_changelog (
223
223
tree , loader = self .cz .template_loader , template = self .template , ** extras
224
- )
225
- changelog_out = changelog_out .lstrip ("\n " )
224
+ ).lstrip ("\n " )
226
225
227
226
# Dry_run is executed here to avoid checking and reading the files
228
227
if self .dry_run :
229
- changelog_hook : Callable | None = self .cz .changelog_hook
230
- if changelog_hook :
231
- changelog_out = changelog_hook (changelog_out , "" )
228
+ if self .cz .changelog_hook :
229
+ changelog_out = self .cz .changelog_hook (changelog_out , "" )
232
230
out .write (changelog_out )
233
231
raise DryRunExit ()
234
232
0 commit comments