Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f662983

Browse files
authored
Merge pull request #160 from commitizen-tools/fix-ini-warning
fix(config): display ini config deprecation warning only when commitizen config is inside
2 parents 400b35b + c1d780c commit f662983

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

‎commitizen/config/__init__.py‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ def read_cfg() -> BaseConfig:
4343
)
4444
raise SystemExit(NOT_A_GIT_PROJECT)
4545

46-
allowed_cfg_files = defaults.config_files
4746
cfg_paths = (
4847
path / Path(filename)
4948
for path in [Path("."), git_project_root]
50-
for filename in allowed_cfg_files
49+
for filename in defaults.config_files
5150
)
5251
for filename in cfg_paths:
5352
if not filename.exists():
@@ -60,11 +59,6 @@ def read_cfg() -> BaseConfig:
6059
if "toml" in filename.suffix:
6160
_conf = TomlConfig(data=data, path=filename)
6261
else:
63-
warnings.warn(
64-
".cz, setup.cfg, and .cz.cfg will be deprecated "
65-
"in next major version. \n"
66-
'Please use "pyproject.toml", ".cz.toml" instead'
67-
)
6862
_conf = IniConfig(data=data, path=filename)
6963

7064
if _conf.is_empty_config:

‎commitizen/config/ini_config.py‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99

1010
class IniConfig(BaseConfig):
1111
def __init__(self, *, data: str, path: Union[Path, str]):
12-
warnings.simplefilter("always", DeprecationWarning)
13-
warnings.warn(
14-
(
15-
".cz, setup.cfg, and .cz.cfg will be deprecated "
16-
"in next major version. \n"
17-
'Please use "pyproject.toml", ".cz.toml" instead'
18-
),
19-
category=DeprecationWarning,
20-
)
21-
2212
super(IniConfig, self).__init__()
2313
self.is_empty_config = False
2414
self._parse_setting(data)
@@ -74,3 +64,13 @@ def _parse_setting(self, data: str):
7464
self._settings.update(_data)
7565
except KeyError:
7666
self.is_empty_config = True
67+
else:
68+
warnings.simplefilter("always", DeprecationWarning)
69+
warnings.warn(
70+
(
71+
".cz, setup.cfg, and .cz.cfg will be deprecated "
72+
"in next major version. \n"
73+
'Please use "pyproject.toml", ".cz.toml" instead'
74+
),
75+
category=DeprecationWarning,
76+
)

‎tests/test_conf.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ def test_read_cfg_when_not_in_a_git_project(tmpdir):
142142
config.read_cfg()
143143

144144

145+
class TestInilConfig:
146+
def test_read_setup_cfg_without_commitizen_config(self, tmpdir):
147+
path = tmpdir.mkdir("commitizen").join("setup.cfg")
148+
ini_config = config.IniConfig(data="", path=path)
149+
assert ini_config.is_empty_config
150+
151+
145152
class TestTomlConfig:
146153
def test_init_empty_config_content(self, tmpdir):
147154
path = tmpdir.mkdir("commitizen").join(".cz.toml")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /