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

fix(config): display ini config deprecation warning only when commitizen config is inside #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Lee-W merged 2 commits into master from fix-ini-warning
Apr 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions commitizen/config/__init__.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions commitizen/config/ini_config.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
)
7 changes: 7 additions & 0 deletions tests/test_conf.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

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