Skip to content

Commit 9c8e840

Browse files
committed
fix(defaults): add non-capitalized default constants back and deprecated warning
Closes #1446
1 parent a8094ae commit 9c8e840

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

commitizen/defaults.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import pathlib
4+
import warnings
45
from collections import OrderedDict
56
from collections.abc import Iterable, MutableMapping, Sequence
67
from typing import Any, TypedDict
@@ -153,3 +154,29 @@ def get_tag_regexes(
153154
**{f"${k}": v for k, v in regexs.items()},
154155
**{f"${{{k}}}": v for k, v in regexs.items()},
155156
}
157+
158+
159+
def __getattr__(name: str) -> Any:
160+
"""Deprecated variable access"""
161+
deprecated_vars = {
162+
"bump_pattern": (BUMP_PATTERN, "BUMP_PATTERN"),
163+
"bump_map": (BUMP_MAP, "BUMP_MAP"),
164+
"bump_map_major_version_zero": (
165+
BUMP_MAP_MAJOR_VERSION_ZERO,
166+
"BUMP_MAP_MAJOR_VERSION_ZERO",
167+
),
168+
"bump_message": (BUMP_MESSAGE, "BUMP_MESSAGE"),
169+
"change_type_order": (CHANGE_TYPE_ORDER, "CHANGE_TYPE_ORDER"),
170+
"encoding": (ENCODING, "ENCODING"),
171+
"name": (DEFAULT_SETTINGS["name"], "DEFAULT_SETTINGS['name']"),
172+
}
173+
if name in deprecated_vars:
174+
value, replacement = deprecated_vars[name]
175+
warnings.warn(
176+
f"{name} is deprecated and will be removed in a future version. "
177+
f"Use {replacement} instead.",
178+
DeprecationWarning,
179+
stacklevel=2,
180+
)
181+
return value
182+
raise AttributeError(f"{name} is not an attribute of {__name__}")

tests/test_defaults.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import pytest
2+
3+
from commitizen import defaults
4+
5+
6+
def test_getattr_deprecated_vars():
7+
# Test each deprecated variable
8+
with pytest.warns(DeprecationWarning) as record:
9+
assert defaults.bump_pattern == defaults.BUMP_PATTERN
10+
assert defaults.bump_map == defaults.BUMP_MAP
11+
assert (
12+
defaults.bump_map_major_version_zero == defaults.BUMP_MAP_MAJOR_VERSION_ZERO
13+
)
14+
assert defaults.bump_message == defaults.BUMP_MESSAGE
15+
assert defaults.change_type_order == defaults.CHANGE_TYPE_ORDER
16+
assert defaults.encoding == defaults.ENCODING
17+
assert defaults.name == defaults.DEFAULT_SETTINGS["name"]
18+
19+
# Verify warning messages
20+
assert len(record) == 7
21+
for warning in record:
22+
assert "is deprecated and will be removed in a future version" in str(
23+
warning.message
24+
)
25+
26+
27+
def test_getattr_non_existent():
28+
# Test non-existent attribute
29+
with pytest.raises(AttributeError) as exc_info:
30+
_ = defaults.non_existent_attribute
31+
assert "is not an attribute of" in str(exc_info.value)

0 commit comments

Comments
 (0)