File tree 7 files changed +23
-14
lines changed 7 files changed +23
-14
lines changed Original file line number Diff line number Diff line change 5
5
from collections import OrderedDict
6
6
from string import Template
7
7
8
- from commitizen .defaults import bump_message
8
+ from commitizen .defaults import bump_message , encoding
9
9
from commitizen .exceptions import CurrentVersionNotFoundError
10
10
from commitizen .git import GitCommit , smart_open
11
11
from commitizen .version_schemes import DEFAULT_SCHEME , Version , VersionScheme
@@ -48,9 +48,9 @@ def update_version_in_files(
48
48
current_version : str ,
49
49
new_version : str ,
50
50
files : list [str ],
51
- encoding : str ,
52
51
* ,
53
52
check_consistency = False ,
53
+ encoding : str = encoding ,
54
54
) -> None :
55
55
"""Change old version to the new one in every file given.
56
56
@@ -71,7 +71,7 @@ def update_version_in_files(
71
71
current_version ,
72
72
new_version ,
73
73
regex ,
74
- encoding ,
74
+ encoding = encoding ,
75
75
)
76
76
77
77
if check_consistency and not current_version_found :
@@ -91,7 +91,7 @@ def _bump_with_regex(
91
91
current_version : str ,
92
92
new_version : str ,
93
93
regex : str ,
94
- encoding : str ,
94
+ encoding : str = encoding ,
95
95
) -> tuple [bool , str ]:
96
96
current_version_found = False
97
97
lines = []
Original file line number Diff line number Diff line change 36
36
37
37
from commitizen import out
38
38
from commitizen .bump import normalize_tag
39
+ from commitizen .defaults import encoding
39
40
from commitizen .exceptions import InvalidConfigurationError , NoCommitsFoundError
40
41
from commitizen .git import GitCommit , GitTag
41
42
from commitizen .version_schemes import (
@@ -214,7 +215,7 @@ def parse_title_type_of_line(value: str) -> str | None:
214
215
215
216
216
217
def get_metadata (
217
- filepath : str , scheme : VersionScheme = Pep440 , encoding : str = "utf-8"
218
+ filepath : str , scheme : VersionScheme = Pep440 , encoding : str = encoding
218
219
) -> dict :
219
220
unreleased_start : int | None = None
220
221
unreleased_end : int | None = None
Original file line number Diff line number Diff line change 13
13
from collections import defaultdict
14
14
from typing import Generator , Iterable
15
15
16
+ from commitizen .defaults import encoding
17
+
16
18
MD_VERSION_RE = r"^##\s(?P<version>[a-zA-Z0-9.+]+)\s?\(?(?P<date>[0-9-]+)?\)?"
17
19
MD_CHANGE_TYPE_RE = r"^###\s(?P<change_type>[a-zA-Z0-9.+\s]+)"
18
20
MD_MESSAGE_RE = (
36
38
]
37
39
38
40
39
- def find_version_blocks (filepath : str , encoding : str ) -> Generator :
41
+ def find_version_blocks (filepath : str , encoding : str = encoding ) -> Generator :
40
42
"""Find version block (version block: contains all the information about a version.)
41
43
42
44
E.g:
Original file line number Diff line number Diff line change 1
1
from __future__ import annotations
2
2
3
3
import os
4
- from logging import getLogger
5
4
import warnings
5
+ from logging import getLogger
6
6
7
7
import questionary
8
8
23
23
NoVersionSpecifiedError ,
24
24
)
25
25
from commitizen .providers import get_provider
26
- from commitizen .version_schemes import get_version_scheme , InvalidVersion
26
+ from commitizen .version_schemes import InvalidVersion , get_version_scheme
27
27
28
28
logger = getLogger ("commitizen" )
29
29
@@ -298,8 +298,8 @@ def __call__(self): # noqa: C901
298
298
str (current_version ),
299
299
str (new_version ),
300
300
version_files ,
301
- self .encoding ,
302
301
check_consistency = self .check_consistency ,
302
+ encoding = self .encoding ,
303
303
)
304
304
305
305
provider .set_version (str (new_version ))
Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ def __call__(self):
145
145
changelog_meta = changelog .get_metadata (
146
146
self .file_name ,
147
147
self .scheme ,
148
- self .encoding ,
148
+ encoding = self .encoding ,
149
149
)
150
150
latest_version = changelog_meta .get ("latest_version" )
151
151
if latest_version :
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ def __call__(self):
83
83
out .info (f"\n { m } \n " )
84
84
85
85
if write_message_to_file :
86
- with smart_open (write_message_to_file , "w" ) as file :
86
+ with smart_open (write_message_to_file , "w" , encoding = self . encoding ) as file :
87
87
file .write (m )
88
88
89
89
if dry_run :
Original file line number Diff line number Diff line change @@ -47,7 +47,9 @@ def existing_changelog_file(tmpdir):
47
47
48
48
49
49
def test_read_changelog_blocks (existing_changelog_file ):
50
- blocks = changelog_parser .find_version_blocks (existing_changelog_file , "utf-8" )
50
+ blocks = changelog_parser .find_version_blocks (
51
+ existing_changelog_file , encoding = "utf-8"
52
+ )
51
53
blocks = list (blocks )
52
54
amount_of_blocks = len (blocks )
53
55
assert amount_of_blocks == 2
@@ -127,7 +129,9 @@ def test_transform_change_type_fail():
127
129
128
130
129
131
def test_generate_block_tree (existing_changelog_file ):
130
- blocks = changelog_parser .find_version_blocks (existing_changelog_file , "utf-8" )
132
+ blocks = changelog_parser .find_version_blocks (
133
+ existing_changelog_file , encoding = "utf-8"
134
+ )
131
135
block = next (blocks )
132
136
tree = changelog_parser .generate_block_tree (block )
133
137
assert tree == {
@@ -157,7 +161,9 @@ def test_generate_block_tree(existing_changelog_file):
157
161
158
162
159
163
def test_generate_full_tree (existing_changelog_file ):
160
- blocks = changelog_parser .find_version_blocks (existing_changelog_file , "utf-8" )
164
+ blocks = changelog_parser .find_version_blocks (
165
+ existing_changelog_file , encoding = "utf-8"
166
+ )
161
167
tree = list (changelog_parser .generate_full_tree (blocks ))
162
168
163
169
assert tree == [
You can’t perform that action at this time.
0 commit comments