From d7ffd790976de4db8011d0d2e61ba0b486c098da Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sun, 1 Mar 2020 18:05:52 +0800 Subject: [PATCH 1/3] refactor(defaults): split config files into long term support and deprecated ones --- commitizen/defaults.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index a9358f2b10..0dfee12246 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -1,6 +1,8 @@ name: str = "cz_conventional_commits" # TODO: .cz, setup.cfg, .cz.cfg should be removed in 2.0 -config_files: list = ["pyproject.toml", ".cz.toml", ".cz", "setup.cfg", ".cz.cfg"] +long_term_support_config_files: list = ["pyproject.toml", ".cz.toml"] +deprcated_config_files: list = [".cz", "setup.cfg", ".cz.cfg"] +config_files: list = long_term_support_config_files + deprcated_config_files DEFAULT_SETTINGS = { "name": "cz_conventional_commits", From 9fb34761877fac2d4ec2d7120f1b97f84089f480 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sun, 1 Mar 2020 18:06:45 +0800 Subject: [PATCH 2/3] fix(commands/init): fix clean up file when initialize commitizen config #138 --- commitizen/commands/init.py | 8 ++++---- commitizen/config/toml_config.py | 4 ++-- tests/test_conf.py | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/commitizen/commands/init.py b/commitizen/commands/init.py index 6a06abb560..cd10edf7f7 100644 --- a/commitizen/commands/init.py +++ b/commitizen/commands/init.py @@ -6,7 +6,7 @@ from commitizen.cz import registry from commitizen.config import BaseConfig, TomlConfig, IniConfig from commitizen.git import get_latest_tag_name, get_tag_names -from commitizen.defaults import config_files +from commitizen.defaults import long_term_support_config_files class Init: @@ -17,7 +17,7 @@ def __init__(self, config: BaseConfig, *args): def __call__(self): values_to_add = {} - # No config file exist + # No config for commitizen exist if not self.config.path: config_path = self._ask_config_path() @@ -26,7 +26,7 @@ def __call__(self): else: self.config = IniConfig(data="", path=config_path) - self.config.init_empty_config_file() + self.config.init_empty_config_content() values_to_add["name"] = self._ask_name() tag = self._ask_tag() @@ -41,7 +41,7 @@ def __call__(self): def _ask_config_path(self) -> str: name = questionary.select( "Please choose a supported config file: (default: pyproject.tml)", - choices=config_files, + choices=long_term_support_config_files, default="pyproject.toml", style=self.cz.style, ).ask() diff --git a/commitizen/config/toml_config.py b/commitizen/config/toml_config.py index f8bbe3efa3..21ffd62e8d 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -10,8 +10,8 @@ def __init__(self, *, data: str, path: str): self._parse_setting(data) self.add_path(path) - def init_empty_config_file(self): - with open(self.path, "w") as toml_file: + def init_empty_config_content(self): + with open(self.path, "a") as toml_file: toml_file.write("[tool.commitizen]") def set_key(self, key, value): diff --git a/tests/test_conf.py b/tests/test_conf.py index c7527cef79..5320051044 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -144,10 +144,21 @@ def test_read_cfg_when_not_in_a_git_project(tmpdir): class TestTomlConfig: - def test_init_empty_config_file(self, tmpdir): + def test_init_empty_config_content(self, tmpdir): path = tmpdir.mkdir("commitizen").join(".cz.toml") toml_config = config.TomlConfig(data="", path=path) - toml_config.init_empty_config_file() + toml_config.init_empty_config_content() with open(path, "r") as toml_file: assert toml_file.read() == "[tool.commitizen]" + + def test_init_empty_config_content_with_existing_content(self, tmpdir): + existing_content = "[tool.black]\n" "line-length = 88\n" + + path = tmpdir.mkdir("commitizen").join(".cz.toml") + path.write(existing_content) + toml_config = config.TomlConfig(data="", path=path) + toml_config.init_empty_config_content() + + with open(path, "r") as toml_file: + assert toml_file.read() == existing_content + "[tool.commitizen]" From 7317194799c6b405044d3a7092392a0c35051b65 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Sun, 1 Mar 2020 18:15:31 +0800 Subject: [PATCH 3/3] ci(pyproject.toml): add configuration for coverage --- pyproject.toml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 7398fe6f9e..8f6b7c910b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,3 +73,24 @@ git-cz = "commitizen.cli:main" [build-system] requires = ["poetry>=0.12"] build-backend = "poetry.masonry.api" + +[tool.coverage] + [tool.coverage.report] + show_missing = true + exclude_lines = [ + # Have to re-enable the standard pragma + 'pragma: no cover', + + # Don't complain about missing debug-only code: + 'def __repr__', + 'if self\.debug', + + # Don't complain if tests don't hit defensive assertion code: + 'raise AssertionError', + 'raise NotImplementedError', + + # Don't complain if non-runnable code isn't run: + 'if 0:', + 'if __name__ == .__main__.:' + ] +