-
-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathdefaults.py
More file actions
198 lines (177 loc) · 5.44 KB
/
defaults.py
File metadata and controls
198 lines (177 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
from __future__ import annotations
import warnings
from collections import OrderedDict
from collections.abc import Iterable, MutableMapping, Sequence
from typing import TYPE_CHECKING, Any, TypedDict
if TYPE_CHECKING:
import pathlib
from commitizen.question import CzQuestion
class CzSettings(TypedDict, total=False):
bump_pattern: str
bump_map: OrderedDict[str, str]
bump_map_major_version_zero: OrderedDict[str, str]
change_type_order: list[str]
questions: Iterable[CzQuestion]
example: str | None
schema_pattern: str | None
schema: str | None
info_path: str | pathlib.Path
info: str
message_template: str
commit_parser: str | None
changelog_pattern: str | None
change_type_map: dict[str, str] | None
class Settings(TypedDict, total=False):
allow_abort: bool
allowed_prefixes: list[str]
always_signoff: bool
annotated_tag: bool
bump_message: str | None
change_type_map: dict[str, str]
changelog_file: str
changelog_format: str | None
changelog_incremental: bool
changelog_merge_prerelease: bool
changelog_start_rev: str | None
customize: CzSettings
encoding: str
extras: dict[str, Any]
gpg_sign: bool
ignored_tag_formats: Sequence[str]
legacy_tag_formats: Sequence[str]
major_version_zero: bool
message_length_limit: int
name: str
post_bump_hooks: list[str] | None
pre_bump_hooks: list[str] | None
prerelease_offset: int
retry_after_failure: bool
style: list[tuple[str, str]]
tag_format: str
template: str | None
update_changelog_on_bump: bool
use_shortcuts: bool
version_files: list[str]
version_provider: str | None
version_scheme: str | None
version_type: str | None
version: str | None
breaking_change_exclamation_in_title: bool
CONFIG_FILES: tuple[str, ...] = (
".cz.toml",
"cz.toml",
".cz.json",
"cz.json",
".cz.yaml",
"cz.yaml",
"pyproject.toml",
)
ENCODING = "utf-8"
DEFAULT_SETTINGS: Settings = {
"name": "cz_conventional_commits",
"version": None,
"version_files": [],
"version_provider": "commitizen",
"version_scheme": None,
"tag_format": "$version", # example v$version
"legacy_tag_formats": [],
"ignored_tag_formats": [],
"bump_message": None, # bumped v$current_version to $new_version
"retry_after_failure": False,
"allow_abort": False,
"allowed_prefixes": [
"Merge",
"Revert",
"Pull request",
"fixup!",
"squash!",
"amend!",
],
"changelog_file": "CHANGELOG.md",
"changelog_format": None, # default guessed from changelog_file
"changelog_incremental": False,
"changelog_start_rev": None,
"changelog_merge_prerelease": False,
"update_changelog_on_bump": False,
"use_shortcuts": False,
"major_version_zero": False,
"pre_bump_hooks": [],
"post_bump_hooks": [],
"prerelease_offset": 0,
"encoding": ENCODING,
"always_signoff": False,
"template": None, # default provided by plugin
"extras": {},
"breaking_change_exclamation_in_title": False,
"message_length_limit": 0, # 0 for no limit
}
MAJOR = "MAJOR"
MINOR = "MINOR"
PATCH = "PATCH"
CHANGELOG_FORMAT = "markdown"
BUMP_PATTERN = r"^((BREAKING[\-\ ]CHANGE|\w+)(\(.+\))?!?):"
BUMP_MAP = OrderedDict(
(
(r"^.+!$", MAJOR),
(r"^BREAKING[\-\ ]CHANGE", MAJOR),
(r"^feat", MINOR),
(r"^fix", PATCH),
(r"^refactor", PATCH),
(r"^perf", PATCH),
)
)
BUMP_MAP_MAJOR_VERSION_ZERO = OrderedDict(
(
(r"^.+!$", MINOR),
(r"^BREAKING[\-\ ]CHANGE", MINOR),
(r"^feat", MINOR),
(r"^fix", PATCH),
(r"^refactor", PATCH),
(r"^perf", PATCH),
)
)
CHANGE_TYPE_ORDER = ["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"]
BUMP_MESSAGE = "bump: version $current_version → $new_version"
def get_tag_regexes(
version_regex: str,
) -> dict[str, str]:
regexes = {
"version": version_regex,
"major": r"(?P<major>\d+)",
"minor": r"(?P<minor>\d+)",
"patch": r"(?P<patch>\d+)",
"prerelease": r"(?P<prerelease>\w+\d+)?",
"devrelease": r"(?P<devrelease>\.dev\d+)?",
}
return {
**{f"${k}": v for k, v in regexes.items()},
**{f"${{{k}}}": v for k, v in regexes.items()},
}
# Type
Questions = Iterable[MutableMapping[str, Any]] # TODO: remove this in v5
def __getattr__(name: str) -> Any:
# PEP-562: deprecate module-level variable
# {"deprecated key": (value, "new key")}
deprecated_vars = {
"bump_pattern": (BUMP_PATTERN, "BUMP_PATTERN"),
"bump_map": (BUMP_MAP, "BUMP_MAP"),
"bump_map_major_version_zero": (
BUMP_MAP_MAJOR_VERSION_ZERO,
"BUMP_MAP_MAJOR_VERSION_ZERO",
),
"bump_message": (BUMP_MESSAGE, "BUMP_MESSAGE"),
"change_type_order": (CHANGE_TYPE_ORDER, "CHANGE_TYPE_ORDER"),
"encoding": (ENCODING, "ENCODING"),
"name": (DEFAULT_SETTINGS["name"], "DEFAULT_SETTINGS['name']"),
"Questions": (Questions, "Iterable[CzQuestion]"),
}
if name in deprecated_vars:
value, replacement = deprecated_vars[name]
warnings.warn(
f"{name} is deprecated and will be removed in v5. "
f"Use {replacement} instead.",
DeprecationWarning,
stacklevel=2,
)
return value
raise AttributeError(f"{name} is not an attribute of {__name__}")