diff --git a/commitizen/config/__init__.py b/commitizen/config/__init__.py index 48a61c75fd..b0dbd7bdc4 100644 --- a/commitizen/config/__init__.py +++ b/commitizen/config/__init__.py @@ -43,11 +43,10 @@ def read_cfg() -> BaseConfig: ) raise SystemExit(NOT_A_GIT_PROJECT) - allowed_cfg_files = defaults.config_files cfg_paths = ( path / Path(filename) for path in [Path("."), git_project_root] - for filename in allowed_cfg_files + for filename in defaults.config_files ) for filename in cfg_paths: if not filename.exists(): @@ -60,11 +59,6 @@ def read_cfg() -> BaseConfig: if "toml" in filename.suffix: _conf = TomlConfig(data=data, path=filename) else: - warnings.warn( - ".cz, setup.cfg, and .cz.cfg will be deprecated " - "in next major version. \n" - 'Please use "pyproject.toml", ".cz.toml" instead' - ) _conf = IniConfig(data=data, path=filename) if _conf.is_empty_config: diff --git a/commitizen/config/ini_config.py b/commitizen/config/ini_config.py index 6ac003ad46..78274123db 100644 --- a/commitizen/config/ini_config.py +++ b/commitizen/config/ini_config.py @@ -9,16 +9,6 @@ class IniConfig(BaseConfig): def __init__(self, *, data: str, path: Union[Path, str]): - warnings.simplefilter("always", DeprecationWarning) - warnings.warn( - ( - ".cz, setup.cfg, and .cz.cfg will be deprecated " - "in next major version. \n" - 'Please use "pyproject.toml", ".cz.toml" instead' - ), - category=DeprecationWarning, - ) - super(IniConfig, self).__init__() self.is_empty_config = False self._parse_setting(data) @@ -74,3 +64,13 @@ def _parse_setting(self, data: str): self._settings.update(_data) except KeyError: self.is_empty_config = True + else: + warnings.simplefilter("always", DeprecationWarning) + warnings.warn( + ( + ".cz, setup.cfg, and .cz.cfg will be deprecated " + "in next major version. \n" + 'Please use "pyproject.toml", ".cz.toml" instead' + ), + category=DeprecationWarning, + ) diff --git a/tests/test_conf.py b/tests/test_conf.py index 277234e5e5..58580e52a6 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -142,6 +142,13 @@ def test_read_cfg_when_not_in_a_git_project(tmpdir): config.read_cfg() +class TestInilConfig: + def test_read_setup_cfg_without_commitizen_config(self, tmpdir): + path = tmpdir.mkdir("commitizen").join("setup.cfg") + ini_config = config.IniConfig(data="", path=path) + assert ini_config.is_empty_config + + class TestTomlConfig: def test_init_empty_config_content(self, tmpdir): path = tmpdir.mkdir("commitizen").join(".cz.toml")