From b5bccb369469452609926909f9892529bfc93504 Mon Sep 17 00:00:00 2001 From: "Hendry, Adam" Date: Mon, 17 Oct 2022 08:29:19 -0700 Subject: [PATCH 01/38] chore(squash): merge `fix/ci` branch This commit can be removed once `fix/ci` is merged into `master`. --- .github/workflows/pythonpackage.yml | 1 + commitizen/bump.py | 5 ++++- commitizen/commands/bump.py | 9 ++++++++- commitizen/commands/check.py | 2 +- scripts/format | 6 ++---- scripts/test | 11 +++++------ tests/commands/test_bump_command.py | 9 ++++++--- tests/commands/test_init_command.py | 2 +- tests/conftest.py | 5 +++-- tests/test_bump_create_commit_message.py | 11 +++++++++-- tests/test_bump_update_version_in_files.py | 6 +++--- tests/test_cli.py | 5 +++++ tests/test_git.py | 5 ++++- 13 files changed, 52 insertions(+), 25 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index 90ccbaaa30..d377023813 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -27,6 +27,7 @@ jobs: git config --global user.email "action@github.com" git config --global user.name "GitHub Action" ./scripts/test + shell: bash - name: Upload coverage to Codecov if: runner.os == 'Linux' uses: codecov/codecov-action@v1.0.3 diff --git a/commitizen/bump.py b/commitizen/bump.py index f571e6a04b..7b621a6e1c 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -1,3 +1,4 @@ +import os import re from collections import OrderedDict from itertools import zip_longest @@ -155,7 +156,9 @@ def update_version_in_files( """ # TODO: separate check step and write step for location in files: - filepath, _, regex = location.partition(":") + drive, tail = os.path.splitdrive(location) + path, _, regex = tail.partition(":") + filepath = drive + path if not regex: regex = _version_to_regex(current_version) diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index bc43032036..06dc908dcc 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -1,3 +1,4 @@ +import os from logging import getLogger from typing import List, Optional @@ -230,9 +231,15 @@ def __call__(self): # noqa: C901 }, ) changelog_cmd() + file_names = [] + for file_name in version_files: + drive, tail = os.path.splitdrive(file_name) + path, _, regex = tail.partition(":") + path = drive + path if path != "" else drive + regex + file_names.append(path) git_add_changelog_and_version_files_command = ( f"git add {changelog_cmd.file_name} " - f"{' '.join(file_name.partition(':')[0] for file_name in version_files)}" + f"{' '.join(name for name in file_names)}" ) c = cmd.run(git_add_changelog_and_version_files_command) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index 58f6814ba3..2ce8ed4d64 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -40,7 +40,7 @@ def _valid_command_argument(self): arg is not None for arg in (self.commit_msg_file, self.commit_msg, self.rev_range) ) - if num_exclusive_args_provided == 0 and not os.isatty(0): + if num_exclusive_args_provided == 0 and not sys.stdin.isatty(): self.commit_msg: Optional[str] = sys.stdin.read() elif num_exclusive_args_provided != 1: raise InvalidCommandArgumentError( diff --git a/scripts/format b/scripts/format index 47b2b90f44..9d300e964b 100755 --- a/scripts/format +++ b/scripts/format @@ -1,9 +1,7 @@ -#!/bin/sh -e +#!/usr/bin/env sh +set -e export PREFIX="poetry run python -m " -if [ -d 'venv' ] ; then - export PREFIX="venv/bin/" -fi set -x diff --git a/scripts/test b/scripts/test index 11131cd209..ea5a318988 100755 --- a/scripts/test +++ b/scripts/test @@ -1,14 +1,13 @@ -#!/bin/sh -e +#!/usr/bin/env sh +set -e -export PREFIX="poetry run python -m " -if [ -d 'venv' ] ; then - export PREFIX="venv/bin/" -fi +export PREFIX='poetry run python -m ' +export REGEX='^(?![.]|venv).*' ${PREFIX}pytest -n 3 --cov-report term-missing --cov-report=xml:coverage.xml --cov=commitizen tests/ ${PREFIX}black commitizen tests --check ${PREFIX}isort --check-only commitizen tests ${PREFIX}flake8 commitizen/ tests/ ${PREFIX}mypy commitizen/ tests/ -${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 +${PREFIX}pydocstyle --convention=google --add-ignore=D1,D415 --match-dir='"${REGEX}"' ${PREFIX}commitizen check --rev-range origin/master.. diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 7374e5aa52..81b4f9d1b4 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -302,9 +302,10 @@ def test_bump_when_version_inconsistent_in_version_files( tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("100.999.10000") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_version_file_string = str(tmp_version_file).replace("\\", "/") tmp_commitizen_cfg_file.write( f"{tmp_commitizen_cfg_file.read()}\n" - f'version_files = ["{str(tmp_version_file)}"]' + f'version_files = ["{tmp_version_file_string}"]' ) create_file_and_commit("feat: new file") @@ -323,9 +324,10 @@ def test_bump_files_only(mocker, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("0.1.0") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_version_file_string = str(tmp_version_file).replace("\\", "/") tmp_commitizen_cfg_file.write( f"{tmp_commitizen_cfg_file.read()}\n" - f'version_files = ["{str(tmp_version_file)}"]' + f'version_files = ["{tmp_version_file_string}"]' ) create_file_and_commit("feat: new user interface") @@ -355,10 +357,11 @@ def test_bump_local_version(mocker, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("4.5.1+0.1.0") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_version_file_string = str(tmp_version_file).replace("\\", "/") tmp_commitizen_cfg_file.write( f"[tool.commitizen]\n" 'version="4.5.1+0.1.0"\n' - f'version_files = ["{str(tmp_version_file)}"]' + f'version_files = ["{tmp_version_file_string}"]' ) create_file_and_commit("feat: new user interface") diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 131aaaad44..6fa8d5008a 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -65,7 +65,7 @@ def test_init_without_setup_pre_commit_hook(tmpdir, mocker, config): def test_init_when_config_already_exists(config, capsys): # Set config path - path = "tests/pyproject.toml" + path = os.sep.join(["tests", "pyproject.toml"]) config.add_path(path) commands.Init(config)() diff --git a/tests/conftest.py b/tests/conftest.py index 64a5652f1a..bb18531699 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -28,7 +28,7 @@ def tmp_commitizen_project(tmp_git_project): def _get_gpg_keyid(signer_mail): _new_key = cmd.run(f"gpg --list-secret-keys {signer_mail}") _m = re.search( - rf"[a-zA-Z0-9 \[\]-_]*{os.linesep}[ ]*([0-9A-Za-z]*){os.linesep}[{os.linesep}a-zA-Z0-9 \[\]-_<>@]*", + r"[a-zA-Z0-9 \[\]-_]*\n[ ]*([0-9A-Za-z]*)\n[\na-zA-Z0-9 \[\]-_<>@]*", _new_key.out, ) return _m.group(1) if _m else None @@ -42,7 +42,8 @@ def tmp_commitizen_project_with_gpg(tmp_commitizen_project): # create a temporary GPGHOME to store a temporary keyring. # Home path must be less than 104 characters gpg_home = tempfile.TemporaryDirectory(suffix="_cz") - os.environ["GNUPGHOME"] = gpg_home.name # tempdir = temp keyring + if os.name != "nt": + os.environ["GNUPGHOME"] = gpg_home.name # tempdir = temp keyring # create a key (a keyring will be generated within GPUPGHOME) c = cmd.run( diff --git a/tests/test_bump_create_commit_message.py b/tests/test_bump_create_commit_message.py index ee1f1f768c..b4bcf9631a 100644 --- a/tests/test_bump_create_commit_message.py +++ b/tests/test_bump_create_commit_message.py @@ -1,3 +1,4 @@ +import os import sys from pathlib import Path from textwrap import dedent @@ -55,7 +56,10 @@ def test_bump_pre_commit_changelog(tmp_commitizen_project, mocker, freezer, retr """ ) cmd.run("git add -A") - cmd.run("git commit -m 'fix: _test'") + if os.name == "nt": + cmd.run('git commit -m "fix: _test"') + else: + cmd.run("git commit -m 'fix: _test'") cmd.run("pre-commit install") cli.main() # Pre-commit fixed last line adding extra indent and "\" char @@ -93,7 +97,10 @@ def test_bump_pre_commit_changelog_fails_always( """ ) cmd.run("git add -A") - cmd.run("git commit -m 'feat: forbid changelogs'") + if os.name == "nt": + cmd.run('git commit -m "feat: forbid changelogs"') + else: + cmd.run("git commit -m 'feat: forbid changelogs'") cmd.run("pre-commit install") with pytest.raises(exceptions.BumpCommitFailedError): cli.main() diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 3113638003..0c37bf538c 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -15,9 +15,9 @@ def _copy_sample_file_to_tmpdir( tmpdir: LocalPath, source_filename: str, dest_filename: str ) -> str: - tmp_file = tmpdir.join(dest_filename) - copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", str(tmp_file)) - return str(tmp_file) + tmp_file = str(tmpdir.join(dest_filename)).replace("\\", "/") + copyfile(f"{TESTING_FILE_PREFIX}/{source_filename}", tmp_file) + return tmp_file @pytest.fixture(scope="function") diff --git a/tests/test_cli.py b/tests/test_cli.py index 383d7a18cf..68a9c04a23 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1,3 +1,4 @@ +import os import subprocess import sys @@ -84,6 +85,10 @@ def test_commitizen_debug_excepthook(capsys): assert "NotAGitProjectError" in str(excinfo.traceback[0]) +@pytest.mark.skipif( + os.name == "nt", + reason="`argcomplete` does not support Git Bash on Windows.", +) def test_argcomplete_activation(): """ This function is testing the one-time activation of argcomplete for diff --git a/tests/test_git.py b/tests/test_git.py index ca51c8f2cd..cc1f4cf3c9 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -206,7 +206,10 @@ def test_is_staging_clean_when_updating_file(tmp_commitizen_project): cmd.run("touch test_file") cmd.run("git add test_file") - cmd.run("git commit -m 'add test_file'") + if os.name == "nt": + cmd.run('git commit -m "add test_file"') + else: + cmd.run("git commit -m 'add test_file'") cmd.run("echo 'test' > test_file") assert git.is_staging_clean() is True From 6bd488ff38b28e4b6bf03861caa2762456814ff4 Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 15:46:58 -0700 Subject: [PATCH 02/38] feat(unicode): add unicode support This will allow commiting, e.g., emoji's and parsing commit messages for unicode characters when creating change logs. --- commitizen/bump.py | 23 +++++-- commitizen/changelog.py | 4 +- commitizen/changelog_parser.py | 4 +- commitizen/commands/bump.py | 2 + commitizen/commands/changelog.py | 7 +- commitizen/commands/check.py | 3 +- commitizen/commands/commit.py | 5 +- commitizen/commands/init.py | 9 ++- commitizen/config/json_config.py | 5 +- commitizen/config/toml_config.py | 5 +- commitizen/config/yaml_config.py | 5 +- .../conventional_commits.py | 2 +- commitizen/cz/customize/customize.py | 2 +- commitizen/cz/jira/jira.py | 2 +- commitizen/defaults.py | 3 + tests/commands/test_bump_command.py | 26 +++---- tests/commands/test_changelog_command.py | 68 +++++++++---------- tests/commands/test_init_command.py | 26 ++++--- tests/test_bump_update_version_in_files.py | 28 ++++---- ...t_multiple_versions_to_bump_with_eol_.toml | 27 ++++++++ ...ultiple_versions_to_bump_without_eol_.toml | 27 ++++++++ tests/test_changelog.py | 2 +- tests/test_changelog_meta.py | 16 ++--- tests/test_changelog_parser.py | 10 +-- tests/test_conf.py | 10 +-- 25 files changed, 208 insertions(+), 113 deletions(-) create mode 100644 tests/test_bump_update_version_in_files/test_multiple_versions_to_bump_with_eol_.toml create mode 100644 tests/test_bump_update_version_in_files/test_multiple_versions_to_bump_without_eol_.toml diff --git a/commitizen/bump.py b/commitizen/bump.py index 7b621a6e1c..d6a1684ea5 100644 --- a/commitizen/bump.py +++ b/commitizen/bump.py @@ -146,7 +146,12 @@ def generate_version( def update_version_in_files( - current_version: str, new_version: str, files: List[str], *, check_consistency=False + current_version: str, + new_version: str, + files: List[str], + encoding: str, + *, + check_consistency=False, ) -> None: """Change old version to the new one in every file given. @@ -163,7 +168,11 @@ def update_version_in_files( regex = _version_to_regex(current_version) current_version_found, version_file = _bump_with_regex( - filepath, current_version, new_version, regex + filepath, + current_version, + new_version, + regex, + encoding, ) if check_consistency and not current_version_found: @@ -174,17 +183,21 @@ def update_version_in_files( ) # Write the file out again - with smart_open(filepath, "w") as file: + with smart_open(filepath, "w", encoding=encoding) as file: file.write(version_file) def _bump_with_regex( - version_filepath: str, current_version: str, new_version: str, regex: str + version_filepath: str, + current_version: str, + new_version: str, + regex: str, + encoding: str, ) -> Tuple[bool, str]: current_version_found = False lines = [] pattern = re.compile(regex) - with open(version_filepath, "r") as f: + with open(version_filepath, "r", encoding=encoding) as f: for line in f: if pattern.search(line): bumped_line = line.replace(current_version, new_version) diff --git a/commitizen/changelog.py b/commitizen/changelog.py index ead80ab775..63d19d8baa 100644 --- a/commitizen/changelog.py +++ b/commitizen/changelog.py @@ -164,7 +164,7 @@ def parse_title_type_of_line(value: str) -> Optional[str]: return m.groupdict().get("title") -def get_metadata(filepath: str) -> Dict: +def get_metadata(filepath: str, encoding: str) -> Dict: unreleased_start: Optional[int] = None unreleased_end: Optional[int] = None unreleased_title: Optional[str] = None @@ -178,7 +178,7 @@ def get_metadata(filepath: str) -> Dict: "latest_version_position": None, } - with open(filepath, "r") as changelog_file: + with open(filepath, "r", encoding=encoding) as changelog_file: for index, line in enumerate(changelog_file): line = line.strip().lower() diff --git a/commitizen/changelog_parser.py b/commitizen/changelog_parser.py index e53c52893a..f3a33798c9 100644 --- a/commitizen/changelog_parser.py +++ b/commitizen/changelog_parser.py @@ -34,7 +34,7 @@ ] -def find_version_blocks(filepath: str) -> Generator: +def find_version_blocks(filepath: str, encoding: str) -> Generator: """Find version block (version block: contains all the information about a version.) E.g: @@ -51,7 +51,7 @@ def find_version_blocks(filepath: str) -> Generator: ``` """ - with open(filepath, "r") as f: + with open(filepath, "r", encoding=encoding) as f: block: list = [] for line in f: line = line.strip("\n") diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 06dc908dcc..6e146b22ea 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -33,6 +33,7 @@ def __init__(self, config: BaseConfig, arguments: dict): raise NotAGitProjectError() self.config: BaseConfig = config + self.encoding = config.settings["encoding"] self.arguments: dict = arguments self.bump_settings: dict = { **config.settings, @@ -251,6 +252,7 @@ def __call__(self): # noqa: C901 current_version, str(new_version), version_files, + self.encoding, check_consistency=self.check_consistency, ) diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index 854060a867..ff735f6ad6 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -24,6 +24,7 @@ def __init__(self, config: BaseConfig, args): raise NotAGitProjectError() self.config: BaseConfig = config + self.encoding = self.config.settings["encoding"] self.cz = factory.commiter_factory(self.config) self.start_rev = args.get("start_rev") or self.config.settings.get( @@ -87,7 +88,7 @@ def write_changelog( ) changelog_hook: Optional[Callable] = self.cz.changelog_hook - with smart_open(self.file_name, "w") as changelog_file: + with smart_open(self.file_name, "w", encoding=self.encoding) as changelog_file: partial_changelog: Optional[str] = None if self.incremental: new_lines = changelog.incremental_build( @@ -129,7 +130,7 @@ def __call__(self): end_rev = "" if self.incremental: - changelog_meta = changelog.get_metadata(self.file_name) + changelog_meta = changelog.get_metadata(self.file_name, self.encoding) latest_version = changelog_meta.get("latest_version") if latest_version: latest_tag_version: str = bump.normalize_tag( @@ -170,7 +171,7 @@ def __call__(self): lines = [] if self.incremental and os.path.isfile(self.file_name): - with open(self.file_name, "r") as changelog_file: + with open(self.file_name, "r", encoding=self.encoding) as changelog_file: lines = changelog_file.readlines() self.write_changelog(changelog_out, lines, changelog_meta) diff --git a/commitizen/commands/check.py b/commitizen/commands/check.py index 2ce8ed4d64..9c2f23cc94 100644 --- a/commitizen/commands/check.py +++ b/commitizen/commands/check.py @@ -33,6 +33,7 @@ def __init__(self, config: BaseConfig, arguments: Dict[str, str], cwd=os.getcwd( self._valid_command_argument() self.config: BaseConfig = config + self.encoding = config.settings["encoding"] self.cz = factory.commiter_factory(self.config) def _valid_command_argument(self): @@ -86,7 +87,7 @@ def _get_commits(self): # Get commit message from file (--commit-msg-file) if self.commit_msg_file is not None: # Enter this branch if commit_msg_file is "". - with open(self.commit_msg_file, "r", encoding="utf-8") as commit_file: + with open(self.commit_msg_file, "r", encoding=self.encoding) as commit_file: msg = commit_file.read() # Get commit message from command line (--message) elif self.commit_msg is not None: diff --git a/commitizen/commands/commit.py b/commitizen/commands/commit.py index 13e61abe6d..b3479379a9 100644 --- a/commitizen/commands/commit.py +++ b/commitizen/commands/commit.py @@ -27,6 +27,7 @@ def __init__(self, config: BaseConfig, arguments: dict): raise NotAGitProjectError() self.config: BaseConfig = config + self.encoding = config.settings["encoding"] self.cz = factory.commiter_factory(self.config) self.arguments = arguments self.temp_file: str = os.path.join( @@ -40,7 +41,7 @@ def read_backup_message(self) -> str: raise NoCommitBackupError() # Read commit message from backup - with open(self.temp_file, "r") as f: + with open(self.temp_file, "r", encoding=self.encoding) as f: return f.read().strip() def prompt_commit_questions(self) -> str: @@ -90,7 +91,7 @@ def __call__(self): out.error(c.err) # Create commit backup - with smart_open(self.temp_file, "w") as f: + with smart_open(self.temp_file, "w", encoding=self.encoding) as f: f.write(m) raise CommitError() diff --git a/commitizen/commands/init.py b/commitizen/commands/init.py index 3b10a58230..c85f519567 100644 --- a/commitizen/commands/init.py +++ b/commitizen/commands/init.py @@ -16,6 +16,7 @@ class Init: def __init__(self, config: BaseConfig, *args): self.config: BaseConfig = config + self.encoding = config.settings["encoding"] self.cz = factory.commiter_factory(self.config) def __call__(self): @@ -122,7 +123,9 @@ def _install_pre_commit_hook(self): # .pre-commit-config does not exist config_data["repos"] = [cz_hook_config] else: - with open(pre_commit_config_filename) as config_file: + with open( + pre_commit_config_filename, encoding=self.encoding + ) as config_file: yaml_data = yaml.safe_load(config_file) if yaml_data: config_data = yaml_data @@ -138,7 +141,9 @@ def _install_pre_commit_hook(self): # .pre-commit-config exists but there's no "repos" key config_data["repos"] = [cz_hook_config] - with smart_open(pre_commit_config_filename, "w") as config_file: + with smart_open( + pre_commit_config_filename, "w", encoding=self.encoding + ) as config_file: yaml.safe_dump(config_data, stream=config_file) c = cmd.run("pre-commit install --hook-type commit-msg") diff --git a/commitizen/config/json_config.py b/commitizen/config/json_config.py index 34a81a9ef7..afc59b2149 100644 --- a/commitizen/config/json_config.py +++ b/commitizen/config/json_config.py @@ -10,12 +10,13 @@ class JsonConfig(BaseConfig): def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]): super(JsonConfig, self).__init__() + self.encoding = self.settings["encoding"] self.is_empty_config = False self._parse_setting(data) self.add_path(path) def init_empty_config_content(self): - with smart_open(self.path, "a") as json_file: + with smart_open(self.path, "a", encoding=self.encoding) as json_file: json.dump({"commitizen": {}}, json_file) def set_key(self, key, value): @@ -28,7 +29,7 @@ def set_key(self, key, value): parser = json.load(f) parser["commitizen"][key] = value - with smart_open(self.path, "w") as f: + with smart_open(self.path, "w", encoding=self.encoding) as f: json.dump(parser, f, indent=2) return self diff --git a/commitizen/config/toml_config.py b/commitizen/config/toml_config.py index 0d09c90796..29b4572e0d 100644 --- a/commitizen/config/toml_config.py +++ b/commitizen/config/toml_config.py @@ -10,6 +10,7 @@ class TomlConfig(BaseConfig): def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]): super(TomlConfig, self).__init__() + self.encoding = self.settings["encoding"] self.is_empty_config = False self._parse_setting(data) self.add_path(path) @@ -25,7 +26,7 @@ def init_empty_config_content(self): if parser.get("tool") is None: parser["tool"] = table() parser["tool"]["commitizen"] = table() - output_toml_file.write(parser.as_string().encode("utf-8")) + output_toml_file.write(parser.as_string().encode(self.encoding)) def set_key(self, key, value): """Set or update a key in the conf. @@ -38,7 +39,7 @@ def set_key(self, key, value): parser["tool"]["commitizen"][key] = value with open(self.path, "wb") as f: - f.write(parser.as_string().encode("utf-8")) + f.write(parser.as_string().encode(self.encoding)) return self def _parse_setting(self, data: Union[bytes, str]) -> None: diff --git a/commitizen/config/yaml_config.py b/commitizen/config/yaml_config.py index 503b32ce06..405b94637b 100644 --- a/commitizen/config/yaml_config.py +++ b/commitizen/config/yaml_config.py @@ -11,12 +11,13 @@ class YAMLConfig(BaseConfig): def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]): super(YAMLConfig, self).__init__() + self.encoding = self.settings["encoding"] self.is_empty_config = False self._parse_setting(data) self.add_path(path) def init_empty_config_content(self): - with smart_open(self.path, "a") as json_file: + with smart_open(self.path, "a", encoding=self.encoding) as json_file: yaml.dump({"commitizen": {}}, json_file) def _parse_setting(self, data: Union[bytes, str]) -> None: @@ -43,7 +44,7 @@ def set_key(self, key, value): parser = yaml.load(yaml_file, Loader=yaml.FullLoader) parser["commitizen"][key] = value - with smart_open(self.path, "w") as yaml_file: + with smart_open(self.path, "w", encoding=self.encoding) as yaml_file: yaml.dump(parser, yaml_file) return self diff --git a/commitizen/cz/conventional_commits/conventional_commits.py b/commitizen/cz/conventional_commits/conventional_commits.py index 7989a17122..a5caf31e4a 100644 --- a/commitizen/cz/conventional_commits/conventional_commits.py +++ b/commitizen/cz/conventional_commits/conventional_commits.py @@ -202,7 +202,7 @@ def schema_pattern(self) -> str: def info(self) -> str: dir_path = os.path.dirname(os.path.realpath(__file__)) filepath = os.path.join(dir_path, "conventional_commits_info.txt") - with open(filepath, "r") as f: + with open(filepath, "r", encoding=self.config.settings["encoding"]) as f: content = f.read() return content diff --git a/commitizen/cz/customize/customize.py b/commitizen/cz/customize/customize.py index 994c21c714..e0fb86dd8a 100644 --- a/commitizen/cz/customize/customize.py +++ b/commitizen/cz/customize/customize.py @@ -73,7 +73,7 @@ def info(self) -> Optional[str]: info_path = self.custom_settings.get("info_path") info = self.custom_settings.get("info") if info_path: - with open(info_path, "r") as f: + with open(info_path, "r", encoding=self.config.settings["encoding"]) as f: content = f.read() return content elif info: diff --git a/commitizen/cz/jira/jira.py b/commitizen/cz/jira/jira.py index bd3cd3c7ee..cc33cd791a 100644 --- a/commitizen/cz/jira/jira.py +++ b/commitizen/cz/jira/jira.py @@ -76,6 +76,6 @@ def schema_pattern(self) -> str: def info(self) -> str: dir_path = os.path.dirname(os.path.realpath(__file__)) filepath = os.path.join(dir_path, "jira_info.txt") - with open(filepath, "r") as f: + with open(filepath, "r", encoding=self.config.settings["encoding"]) as f: content = f.read() return content diff --git a/commitizen/defaults.py b/commitizen/defaults.py index f6b6dee1c3..120ff66e2d 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -39,6 +39,7 @@ class Settings(TypedDict, total=False): use_shortcuts: bool style: Optional[List[Tuple[str, str]]] customize: CzSettings + encoding: str name: str = "cz_conventional_commits" @@ -50,6 +51,7 @@ class Settings(TypedDict, total=False): ".cz.yaml", "cz.yaml", ] +encoding: str = "utf-8" DEFAULT_SETTINGS: Settings = { "name": "cz_conventional_commits", @@ -63,6 +65,7 @@ class Settings(TypedDict, total=False): "changelog_start_rev": None, "update_changelog_on_bump": False, "use_shortcuts": False, + "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 81b4f9d1b4..f83c344eff 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -197,7 +197,7 @@ def test_bump_command_prelease(mocker): def test_bump_on_git_with_hooks_no_verify_disabled(mocker): """Bump commit without --no-verify""" cmd.run("mkdir .git/hooks") - with open(".git/hooks/pre-commit", "w") as f: + with open(".git/hooks/pre-commit", "w", encoding="utf-8") as f: f.write("#!/usr/bin/env bash\n" 'echo "0.1.0"') cmd.run("chmod +x .git/hooks/pre-commit") @@ -216,7 +216,7 @@ def test_bump_on_git_with_hooks_no_verify_disabled(mocker): @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_tag_exists_raises_exception(mocker): cmd.run("mkdir .git/hooks") - with open(".git/hooks/post-commit", "w") as f: + with open(".git/hooks/post-commit", "w", encoding="utf-8") as f: f.write("#!/usr/bin/env bash\n" "exit 9") cmd.run("chmod +x .git/hooks/post-commit") @@ -235,7 +235,7 @@ def test_bump_tag_exists_raises_exception(mocker): @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_on_git_with_hooks_no_verify_enabled(mocker): cmd.run("mkdir .git/hooks") - with open(".git/hooks/pre-commit", "w") as f: + with open(".git/hooks/pre-commit", "w", encoding="utf-8") as f: f.write("#!/usr/bin/env bash\n" 'echo "0.1.0"') cmd.run("chmod +x .git/hooks/pre-commit") @@ -346,10 +346,10 @@ def test_bump_files_only(mocker, tmp_commitizen_project): tag_exists = git.tag_exist("0.3.0") assert tag_exists is False - with open(tmp_version_file, "r") as f: + with open(tmp_version_file, "r", encoding="utf-8") as f: assert "0.3.0" in f.read() - with open(tmp_commitizen_cfg_file, "r") as f: + with open(tmp_commitizen_cfg_file, "r", encoding="utf-8") as f: assert "0.3.0" in f.read() @@ -371,7 +371,7 @@ def test_bump_local_version(mocker, tmp_commitizen_project): tag_exists = git.tag_exist("4.5.1+0.2.0") assert tag_exists is True - with open(tmp_version_file, "r") as f: + with open(tmp_version_file, "r", encoding="utf-8") as f: assert "4.5.1+0.2.0" in f.read() @@ -450,7 +450,7 @@ def test_bump_with_changelog_arg(mocker, changelog_path): tag_exists = git.tag_exist("0.2.0") assert tag_exists is True - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() assert out.startswith("#") assert "0.2.0" in out @@ -459,7 +459,7 @@ def test_bump_with_changelog_arg(mocker, changelog_path): @pytest.mark.usefixtures("tmp_commitizen_project") def test_bump_with_changelog_config(mocker, changelog_path, config_path): create_file_and_commit("feat(user): new file") - with open(config_path, "a") as fp: + with open(config_path, "a", encoding="utf-8") as fp: fp.write("update_changelog_on_bump = true\n") testargs = ["cz", "bump", "--yes"] @@ -468,7 +468,7 @@ def test_bump_with_changelog_config(mocker, changelog_path, config_path): tag_exists = git.tag_exist("0.2.0") assert tag_exists is True - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() assert out.startswith("#") assert "0.2.0" in out @@ -512,7 +512,7 @@ def test_bump_with_changelog_to_stdout_arg(mocker, capsys, changelog_path): tag_exists = git.tag_exist("0.2.0") assert tag_exists is True - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() assert out.startswith("#") assert "0.2.0" in out @@ -604,11 +604,13 @@ def test_bump_changelog_command_commits_untracked_changelog_and_version_files( """ with tmp_commitizen_project.join("pyproject.toml").open( - mode="a" + mode="a", encoding="utf-8" ) as commitizen_config: commitizen_config.write(f"version_files = [\n" f"'{version_regex}'\n]") - with tmp_commitizen_project.join(version_filepath).open(mode="a+") as version_file: + with tmp_commitizen_project.join(version_filepath).open( + mode="a+", encoding="utf-8" + ) as version_file: version_file.write(version_file_content) create_file_and_commit("fix: some test commit") diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index dc932bd405..e6188de69c 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -62,7 +62,7 @@ def test_changelog_from_start(mocker, capsys, changelog_path, file_regression): mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -91,7 +91,7 @@ def test_changelog_replacing_unreleased_using_incremental( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read().replace( datetime.strftime(datetime.now(), "%Y-%m-%d"), "2022-08-14" ) @@ -116,7 +116,7 @@ def test_changelog_is_persisted_using_incremental( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "a") as f: + with open(changelog_path, "a", encoding="utf-8") as f: f.write("\nnote: this should be persisted using increment\n") create_file_and_commit("fix: mama gotta work") @@ -128,7 +128,7 @@ def test_changelog_is_persisted_using_incremental( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read().replace( datetime.strftime(datetime.now(), "%Y-%m-%d"), "2022-08-14" ) @@ -140,7 +140,7 @@ def test_changelog_is_persisted_using_incremental( def test_changelog_incremental_angular_sample( mocker, capsys, changelog_path, file_regression ): - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write( "# [10.0.0-rc.3](https://github.com/angular/angular/compare/10.0.0-rc.2...10.0.0-rc.3) (2020-04-22)\n" "\n" @@ -162,7 +162,7 @@ def test_changelog_incremental_angular_sample( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -197,7 +197,7 @@ def test_changelog_incremental_angular_sample( def test_changelog_incremental_keep_a_changelog_sample( mocker, capsys, changelog_path, file_regression ): - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write(KEEP_A_CHANGELOG) create_file_and_commit("irrelevant commit") git.tag("1.0.0") @@ -213,7 +213,7 @@ def test_changelog_incremental_keep_a_changelog_sample( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -292,7 +292,7 @@ def test_changelog_multiple_incremental_do_not_add_new_lines( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -303,7 +303,7 @@ def test_changelog_incremental_newline_separates_new_content_from_old( mocker, changelog_path ): """Test for https://github.com/commitizen-tools/commitizen/issues/509""" - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write("Pre-existing content that should be kept\n") create_file_and_commit("feat: add more cat videos") @@ -313,7 +313,7 @@ def test_changelog_incremental_newline_separates_new_content_from_old( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() assert ( @@ -436,9 +436,9 @@ def test_changelog_config_flag_increment( mocker, changelog_path, config_path, file_regression ): - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write("changelog_incremental = true\n") - with open(changelog_path, "a") as f: + with open(changelog_path, "a", encoding="utf-8") as f: f.write("\nnote: this should be persisted using increment\n") create_file_and_commit("feat: add new output") @@ -447,7 +447,7 @@ def test_changelog_config_flag_increment( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() assert "this should be persisted using increment" in out @@ -469,7 +469,7 @@ def test_changelog_config_start_rev_option( create_file_and_commit("feat: after 0.2.0") create_file_and_commit("feat: after 0.2") - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('changelog_start_rev = "0.2.0"\n') testargs = ["cz", "changelog", "--dry-run"] @@ -486,7 +486,7 @@ def test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag( mocker, capsys, changelog_path, file_regression ): """Fix #378""" - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write(KEEP_A_CHANGELOG) create_file_and_commit("irrelevant commit") git.tag("1.0.0", annotated=True) @@ -502,7 +502,7 @@ def test_changelog_incremental_keep_a_changelog_sample_with_annotated_tag( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -515,7 +515,7 @@ def test_changelog_incremental_with_release_candidate_version( mocker, changelog_path, file_regression, test_input ): """Fix #357""" - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write(KEEP_A_CHANGELOG) create_file_and_commit("irrelevant commit") git.tag("1.0.0", annotated=True) @@ -536,7 +536,7 @@ def test_changelog_incremental_with_release_candidate_version( mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -545,7 +545,7 @@ def test_changelog_incremental_with_release_candidate_version( @pytest.mark.usefixtures("tmp_commitizen_project") def test_changelog_with_filename_as_empty_string(mocker, changelog_path, config_path): - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write("changelog_file = true\n") create_file_and_commit("feat: add new output") @@ -563,7 +563,7 @@ def test_changelog_from_rev_first_version_from_arg( ): mocker.patch("commitizen.git.GitTag.date", "2022-02-13") - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') # create commit and tag @@ -584,7 +584,7 @@ def test_changelog_from_rev_first_version_from_arg( testargs = ["cz", "changelog", "0.2.0"] mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -597,7 +597,7 @@ def test_changelog_from_rev_latest_version_from_arg( ): mocker.patch("commitizen.git.GitTag.date", "2022-02-13") - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') # create commit and tag @@ -632,7 +632,7 @@ def test_changelog_from_rev_single_version_not_found( mocker, config_path, changelog_path ): """Provides an invalid revision ID to changelog command""" - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') # create commit and tag @@ -663,7 +663,7 @@ def test_changelog_from_rev_single_version_not_found( @pytest.mark.freeze_time("2022-02-13") def test_changelog_from_rev_range_version_not_found(mocker, config_path): """Provides an invalid end revision ID to changelog command""" - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') # create commit and tag @@ -694,7 +694,7 @@ def test_changelog_from_rev_version_range_including_first_tag( ): mocker.patch("commitizen.git.GitTag.date", "2022-02-13") - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') # create commit and tag @@ -713,7 +713,7 @@ def test_changelog_from_rev_version_range_including_first_tag( testargs = ["cz", "changelog", "0.2.0..0.3.0"] mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -726,7 +726,7 @@ def test_changelog_from_rev_version_range_from_arg( ): mocker.patch("commitizen.git.GitTag.date", "2022-02-13") - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') # create commit and tag @@ -753,7 +753,7 @@ def test_changelog_from_rev_version_range_from_arg( testargs = ["cz", "changelog", "0.3.0..0.4.0"] mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -766,7 +766,7 @@ def test_changelog_from_rev_version_with_big_range_from_arg( ): mocker.patch("commitizen.git.GitTag.date", "2022-02-13") - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') # create commit and tag @@ -813,7 +813,7 @@ def test_changelog_from_rev_version_with_big_range_from_arg( testargs = ["cz", "changelog", "0.3.0..0.5.0"] mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") @@ -826,7 +826,7 @@ def test_changelog_from_rev_latest_version_dry_run( ): mocker.patch("commitizen.git.GitTag.date", "2022-02-13") - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') # create commit and tag @@ -880,7 +880,7 @@ def test_changelog_with_customized_change_type_order( ): mocker.patch("commitizen.git.GitTag.date", "2022-02-13") - with open(config_path, "a") as f: + with open(config_path, "a", encoding="utf-8") as f: f.write('tag_format = "$version"\n') f.write( 'change_type_order = ["BREAKING CHANGE", "Perf", "Fix", "Feat", "Refactor"]\n' @@ -912,7 +912,7 @@ def test_changelog_with_customized_change_type_order( testargs = ["cz", "changelog", "0.3.0..0.4.0"] mocker.patch.object(sys, "argv", testargs) cli.main() - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: out = f.read() file_regression.check(out, extension=".md") diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 6fa8d5008a..22c027bdf9 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -56,7 +56,7 @@ def test_init_without_setup_pre_commit_hook(tmpdir, mocker, config): with tmpdir.as_cwd(): commands.Init(config)() - with open("pyproject.toml", "r") as toml_file: + with open("pyproject.toml", "r", encoding="utf-8") as toml_file: config_data = toml_file.read() assert config_data == expected_config @@ -113,7 +113,7 @@ def test_no_existing_pre_commit_conifg(_, default_choice, tmpdir, config): with tmpdir.as_cwd(): commands.Init(config)() - with open(default_choice, "r") as file: + with open(default_choice, "r", encoding="utf-8") as file: if "json" in default_choice: assert json.load(file) == EXPECTED_DICT_CONFIG elif "yaml" in default_choice: @@ -124,7 +124,9 @@ def test_no_existing_pre_commit_conifg(_, default_choice, tmpdir, config): config_data = file.read() assert config_data == expected_config - with open(pre_commit_config_filename, "r") as pre_commit_file: + with open( + pre_commit_config_filename, "r", encoding="utf-8" + ) as pre_commit_file: pre_commit_config_data = yaml.safe_load(pre_commit_file.read()) assert pre_commit_config_data == {"repos": [cz_hook_config]} @@ -135,7 +137,7 @@ def test_empty_pre_commit_config(_, default_choice, tmpdir, config): commands.Init(config)() - with open(default_choice, "r") as file: + with open(default_choice, "r", encoding="utf-8") as file: if "json" in default_choice: assert json.load(file) == EXPECTED_DICT_CONFIG elif "yaml" in default_choice: @@ -146,7 +148,9 @@ def test_empty_pre_commit_config(_, default_choice, tmpdir, config): config_data = file.read() assert config_data == expected_config - with open(pre_commit_config_filename, "r") as pre_commit_file: + with open( + pre_commit_config_filename, "r", encoding="utf-8" + ) as pre_commit_file: pre_commit_config_data = yaml.safe_load(pre_commit_file.read()) assert pre_commit_config_data == {"repos": [cz_hook_config]} @@ -163,7 +167,7 @@ def test_pre_commit_config_without_cz_hook(_, default_choice, tmpdir, config): commands.Init(config)() - with open(default_choice, "r") as file: + with open(default_choice, "r", encoding="utf-8") as file: if "json" in default_choice: assert json.load(file) == EXPECTED_DICT_CONFIG elif "yaml" in default_choice: @@ -174,7 +178,9 @@ def test_pre_commit_config_without_cz_hook(_, default_choice, tmpdir, config): config_data = file.read() assert config_data == expected_config - with open(pre_commit_config_filename, "r") as pre_commit_file: + with open( + pre_commit_config_filename, "r", encoding="utf-8" + ) as pre_commit_file: pre_commit_config_data = yaml.safe_load(pre_commit_file.read()) assert pre_commit_config_data == { "repos": [existing_hook_config, cz_hook_config] @@ -187,7 +193,7 @@ def test_cz_hook_exists_in_pre_commit_config(_, default_choice, tmpdir, config): commands.Init(config)() - with open(default_choice, "r") as file: + with open(default_choice, "r", encoding="utf-8") as file: if "json" in default_choice: assert json.load(file) == EXPECTED_DICT_CONFIG elif "yaml" in default_choice: @@ -198,7 +204,9 @@ def test_cz_hook_exists_in_pre_commit_config(_, default_choice, tmpdir, config): config_data = file.read() assert config_data == expected_config - with open(pre_commit_config_filename, "r") as pre_commit_file: + with open( + pre_commit_config_filename, "r", encoding="utf-8" + ) as pre_commit_file: pre_commit_config_data = yaml.safe_load(pre_commit_file.read()) # check that config is not duplicated diff --git a/tests/test_bump_update_version_in_files.py b/tests/test_bump_update_version_in_files.py index 0c37bf538c..c15425e459 100644 --- a/tests/test_bump_update_version_in_files.py +++ b/tests/test_bump_update_version_in_files.py @@ -102,11 +102,11 @@ def version_files( def test_update_version_in_files(version_files, file_regression): old_version = "1.2.3" new_version = "2.0.0" - bump.update_version_in_files(old_version, new_version, version_files) + bump.update_version_in_files(old_version, new_version, version_files, "utf-8") file_contents = "" for filepath in version_files: - with open(filepath, "r") as f: + with open(filepath, "r", encoding="utf-8") as f: file_contents += f.read() file_regression.check(file_contents, extension=".txt") @@ -117,8 +117,8 @@ def test_partial_update_of_file(version_repeated_file, file_regression): regex = "version" location = f"{version_repeated_file}:{regex}" - bump.update_version_in_files(old_version, new_version, [location]) - with open(version_repeated_file, "r") as f: + bump.update_version_in_files(old_version, new_version, [location], "utf-8") + with open(version_repeated_file, "r", encoding="utf-8") as f: file_regression.check(f.read(), extension=".json") @@ -127,7 +127,7 @@ def test_random_location(random_location_version_file, file_regression): new_version = "2.0.0" location = f"{random_location_version_file}:version.+Commitizen" - bump.update_version_in_files(old_version, new_version, [location]) + bump.update_version_in_files(old_version, new_version, [location], "utf-8") with open(random_location_version_file, "r") as f: file_regression.check(f.read(), extension=".lock") @@ -139,8 +139,8 @@ def test_duplicates_are_change_with_no_regex( new_version = "2.0.0" location = f"{random_location_version_file}:version" - bump.update_version_in_files(old_version, new_version, [location]) - with open(random_location_version_file, "r") as f: + bump.update_version_in_files(old_version, new_version, [location], "utf-8") + with open(random_location_version_file, "r", encoding="utf-8") as f: file_regression.check(f.read(), extension=".lock") @@ -151,7 +151,7 @@ def test_version_bump_increase_string_length( new_version = "1.2.10" location = f"{multiple_versions_increase_string}:version" - bump.update_version_in_files(old_version, new_version, [location]) + bump.update_version_in_files(old_version, new_version, [location], "utf-8") with open(multiple_versions_increase_string, "r") as f: file_regression.check(f.read(), extension=".txt") @@ -163,8 +163,8 @@ def test_version_bump_reduce_string_length( new_version = "2.0.0" location = f"{multiple_versions_reduce_string}:version" - bump.update_version_in_files(old_version, new_version, [location]) - with open(multiple_versions_reduce_string, "r") as f: + bump.update_version_in_files(old_version, new_version, [location], "utf-8") + with open(multiple_versions_reduce_string, "r", encoding="utf-8") as f: file_regression.check(f.read(), extension=".txt") @@ -180,7 +180,7 @@ def test_file_version_inconsistent_error( new_version = "2.0.0" with pytest.raises(CurrentVersionNotFoundError) as excinfo: bump.update_version_in_files( - old_version, new_version, version_files, check_consistency=True + old_version, new_version, version_files, "utf-8", check_consistency=True ) expected_msg = ( @@ -191,13 +191,13 @@ def test_file_version_inconsistent_error( assert expected_msg in str(excinfo.value) -def test_multiplt_versions_to_bump( +def test_multiple_versions_to_bump( multiple_versions_to_update_poetry_lock, file_regression ): old_version = "1.2.9" new_version = "1.2.10" location = f"{multiple_versions_to_update_poetry_lock}:version" - bump.update_version_in_files(old_version, new_version, [location]) - with open(multiple_versions_to_update_poetry_lock, "r") as f: + bump.update_version_in_files(old_version, new_version, [location], "utf-8") + with open(multiple_versions_to_update_poetry_lock, "r", encoding="utf-8") as f: file_regression.check(f.read(), extension=".toml") diff --git a/tests/test_bump_update_version_in_files/test_multiple_versions_to_bump_with_eol_.toml b/tests/test_bump_update_version_in_files/test_multiple_versions_to_bump_with_eol_.toml new file mode 100644 index 0000000000..f279eb4d61 --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_multiple_versions_to_bump_with_eol_.toml @@ -0,0 +1,27 @@ +[[package]] +name = "to-update-1" +version = "1.2.10" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "to-update-2" +version = "1.2.10" diff --git a/tests/test_bump_update_version_in_files/test_multiple_versions_to_bump_without_eol_.toml b/tests/test_bump_update_version_in_files/test_multiple_versions_to_bump_without_eol_.toml new file mode 100644 index 0000000000..47092b958b --- /dev/null +++ b/tests/test_bump_update_version_in_files/test_multiple_versions_to_bump_without_eol_.toml @@ -0,0 +1,27 @@ +[[package]] +name = "to-update-1" +version = "1.2.10" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "not-to-update" +version = "1.3.3" + +[[package]] +name = "to-update-2" +version = "1.2.10" \ No newline at end of file diff --git a/tests/test_changelog.py b/tests/test_changelog.py index e68a3abdcf..9d7efcc659 100644 --- a/tests/test_changelog.py +++ b/tests/test_changelog.py @@ -496,7 +496,7 @@ def tags() -> list: @pytest.fixture def changelog_content() -> str: changelog_path = "tests/CHANGELOG_FOR_TEST.md" - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: return f.read() diff --git a/tests/test_changelog_meta.py b/tests/test_changelog_meta.py index 505daefb83..0f06ab58c9 100644 --- a/tests/test_changelog_meta.py +++ b/tests/test_changelog_meta.py @@ -44,7 +44,7 @@ def changelog_a_file(): changelog_path = "tests/CHANGELOG.md" - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write(CHANGELOG_A) yield changelog_path @@ -56,7 +56,7 @@ def changelog_a_file(): def changelog_b_file(): changelog_path = "tests/CHANGELOG.md" - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write(CHANGELOG_B) yield changelog_path @@ -68,7 +68,7 @@ def changelog_b_file(): def changelog_c_file(): changelog_path = "tests/CHANGELOG.md" - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write(CHANGELOG_C) yield changelog_path @@ -80,7 +80,7 @@ def changelog_c_file(): def changelog_d_file(): changelog_path = "tests/CHANGELOG.md" - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write(CHANGELOG_D) yield changelog_path @@ -126,7 +126,7 @@ def test_parse_title_type_of_line(line_from_changelog, output_title): def test_get_metadata_from_a(changelog_a_file): - meta = changelog.get_metadata(changelog_a_file) + meta = changelog.get_metadata(changelog_a_file, "utf-8") assert meta == { "latest_version": "1.0.0", "latest_version_position": 10, @@ -136,7 +136,7 @@ def test_get_metadata_from_a(changelog_a_file): def test_get_metadata_from_b(changelog_b_file): - meta = changelog.get_metadata(changelog_b_file) + meta = changelog.get_metadata(changelog_b_file, "utf-8") assert meta == { "latest_version": "1.2.0", "latest_version_position": 3, @@ -146,7 +146,7 @@ def test_get_metadata_from_b(changelog_b_file): def test_get_metadata_from_c(changelog_c_file): - meta = changelog.get_metadata(changelog_c_file) + meta = changelog.get_metadata(changelog_c_file, "utf-8") assert meta == { "latest_version": "1.0.0", "latest_version_position": 3, @@ -156,7 +156,7 @@ def test_get_metadata_from_c(changelog_c_file): def test_get_metadata_from_d(changelog_d_file): - meta = changelog.get_metadata(changelog_d_file) + meta = changelog.get_metadata(changelog_d_file, "utf-8") assert meta == { "latest_version": None, "latest_version_position": None, diff --git a/tests/test_changelog_parser.py b/tests/test_changelog_parser.py index 540f62fd19..75f6788a8d 100644 --- a/tests/test_changelog_parser.py +++ b/tests/test_changelog_parser.py @@ -28,7 +28,7 @@ @pytest.fixture def changelog_content() -> str: changelog_path = "tests/CHANGELOG_FOR_TEST.md" - with open(changelog_path, "r") as f: + with open(changelog_path, "r", encoding="utf-8") as f: return f.read() @@ -38,7 +38,7 @@ def existing_changelog_file(tmpdir): changelog_path = os.path.join(os.getcwd(), "CHANGELOG.md") # changelog_path = "tests/CHANGELOG.md" - with open(changelog_path, "w") as f: + with open(changelog_path, "w", encoding="utf-8") as f: f.write(CHANGELOG_TEMPLATE) yield changelog_path @@ -47,7 +47,7 @@ def existing_changelog_file(tmpdir): def test_read_changelog_blocks(existing_changelog_file): - blocks = changelog_parser.find_version_blocks(existing_changelog_file) + blocks = changelog_parser.find_version_blocks(existing_changelog_file, "utf-8") blocks = list(blocks) amount_of_blocks = len(blocks) assert amount_of_blocks == 2 @@ -127,7 +127,7 @@ def test_transform_change_type_fail(): def test_generate_block_tree(existing_changelog_file): - blocks = changelog_parser.find_version_blocks(existing_changelog_file) + blocks = changelog_parser.find_version_blocks(existing_changelog_file, "utf-8") block = next(blocks) tree = changelog_parser.generate_block_tree(block) assert tree == { @@ -157,7 +157,7 @@ def test_generate_block_tree(existing_changelog_file): def test_generate_full_tree(existing_changelog_file): - blocks = changelog_parser.find_version_blocks(existing_changelog_file) + blocks = changelog_parser.find_version_blocks(existing_changelog_file, "utf-8") tree = list(changelog_parser.generate_full_tree(blocks)) assert tree == [ diff --git a/tests/test_conf.py b/tests/test_conf.py index f051a1f56f..340491a62d 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -48,6 +48,7 @@ "changelog_start_rev": None, "update_changelog_on_bump": False, "use_shortcuts": False, + "encoding": "utf-8", } _new_settings = { @@ -63,6 +64,7 @@ "changelog_start_rev": None, "update_changelog_on_bump": False, "use_shortcuts": False, + "encoding": "utf-8", } _read_settings = { @@ -78,7 +80,7 @@ def config_files_manager(request, tmpdir): with tmpdir.as_cwd(): filename = request.param - with open(filename, "w") as f: + with open(filename, "w", encoding="utf-8") as f: if "toml" in filename: f.write(PYPROJECT) elif "json" in filename: @@ -135,7 +137,7 @@ def test_init_empty_config_content(self, tmpdir): toml_config = config.TomlConfig(data="", path=path) toml_config.init_empty_config_content() - with open(path, "r") as toml_file: + with open(path, "r", encoding="utf-8") as toml_file: assert toml_file.read() == "[tool]\n[tool.commitizen]\n" def test_init_empty_config_content_with_existing_content(self, tmpdir): @@ -146,7 +148,7 @@ def test_init_empty_config_content_with_existing_content(self, tmpdir): toml_config = config.TomlConfig(data="", path=path) toml_config.init_empty_config_content() - with open(path, "r") as toml_file: + with open(path, "r", encoding="utf-8") as toml_file: assert toml_file.read() == existing_content + "\n[tool.commitizen]\n" @@ -156,5 +158,5 @@ def test_init_empty_config_content(self, tmpdir): json_config = config.JsonConfig(data="{}", path=path) json_config.init_empty_config_content() - with open(path, "r") as json_file: + with open(path, "r", encoding="utf-8") as json_file: assert json.load(json_file) == {"commitizen": {}} From 99b45aabe91131106905cc9add7b3f9ddf1347ac Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 19:06:34 -0700 Subject: [PATCH 03/38] test(unicode): add tests --- commitizen/config/json_config.py | 2 + tests/test_cz_customize.py | 245 +++++++++++++++++++++++++++++-- 2 files changed, 234 insertions(+), 13 deletions(-) diff --git a/commitizen/config/json_config.py b/commitizen/config/json_config.py index afc59b2149..5a6e86b4a1 100644 --- a/commitizen/config/json_config.py +++ b/commitizen/config/json_config.py @@ -1,4 +1,5 @@ import json +import sys from pathlib import Path from typing import Union @@ -45,6 +46,7 @@ def _parse_setting(self, data: Union[bytes, str]) -> None: ``` """ doc = json.loads(data) + try: self.settings.update(doc["commitizen"]) except KeyError: diff --git a/tests/test_cz_customize.py b/tests/test_cz_customize.py index 84e463cf96..154d15d40d 100644 --- a/tests/test_cz_customize.py +++ b/tests/test_cz_customize.py @@ -7,7 +7,7 @@ TOML_STR = r""" [tool.commitizen.customize] message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}" - example = "feature: this feature enable customize through config file" + example = "feature: this feature enables customization through a config file" schema = ": " schema_pattern = "(feature|bug fix):(\\s.*)" commit_parser = "^(?Pfeature|bug fix):\\s(?P.*)?" @@ -50,7 +50,7 @@ ], "customize": { "message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}", - "example": "feature: this feature enable customize through config file", + "example": "feature: this feature enables customization through a config file", "schema": ": ", "schema_pattern": "(feature|bug fix):(\\s.*)", "bump_pattern": "^(break|new|fix|hotfix)", @@ -106,7 +106,7 @@ - pyproject.toml customize: message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}" - example: 'feature: this feature enable customize through config file' + example: 'feature: this feature enables customization through a config file' schema: ": " schema_pattern: "(feature|bug fix):(\\s.*)" bump_pattern: "^(break|new|fix|hotfix)" @@ -134,11 +134,110 @@ message: Do you want to add body message in commit? """ +TOML_WITH_UNICODE = r""" + [tool.commitizen] + name = "cz_customize" + version = "1.0.0" + version_files = [ + "commitizen/__version__.py", + "pyproject.toml:version" + ] + + [tool.commitizen.customize] + message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}" + example = "✨ feature: this feature enables customization through a config file" + schema = ": " + schema_pattern = "(✨ feature|🐛 bug fix):(\\s.*)" + commit_parser = "^(?P✨ feature|🐛 bug fix):\\s(?P.*)?" + changelog_pattern = "^(✨ feature|🐛 bug fix)?(!)?" + change_type_map = {"✨ feature" = "Feat", "🐛 bug fix" = "Fix"} + + bump_pattern = "^(✨ feat|🐛 bug fix)" + bump_map = {"break" = "MAJOR", "✨ feat" = "MINOR", "🐛 bug fix" = "MINOR"} + change_type_order = ["perf", "BREAKING CHANGE", "feat", "fix", "refactor"] + info = "This is a customized cz with emojis 🎉!" + + [[tool.commitizen.customize.questions]] + type = "list" + name = "change_type" + choices = [ + {value = "✨ feature", name = "✨ feature: A new feature."}, + {value = "🐛 bug fix", name = "🐛 bug fix: A bug fix."} + ] + message = "Select the type of change you are committing" + + [[tool.commitizen.customize.questions]] + type = "input" + name = "message" + message = "Body." + + [[tool.commitizen.customize.questions]] + type = "confirm" + name = "show_message" + message = "Do you want to add body message in commit?" +""" + +JSON_WITH_UNICODE = r""" + { + "commitizen": { + "name": "cz_customize", + "version": "1.0.0", + "version_files": [ + "commitizen/__version__.py", + "pyproject.toml:version" + ], + "customize": { + "message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}", + "example": "✨ feature: this feature enables customization through a config file", + "schema": ": ", + "schema_pattern": "(✨ feature|🐛 bug fix):(\\s.*)", + "bump_pattern": "^(✨ feat|🐛 bug fix)", + "bump_map": { + "break": "MAJOR", + "✨ feat": "MINOR", + "🐛 bug fix": "MINOR" + }, + "commit_parser": "^(?P✨ feature|🐛 bug fix):\\s(?P.*)?", + "changelog_pattern": "^(✨ feature|🐛 bug fix)?(!)?", + "change_type_map": {"✨ feature": "Feat", "🐛 bug fix": "Fix"}, + "change_type_order": ["perf", "BREAKING CHANGE", "feat", "fix", "refactor"], + "info": "This is a customized cz with emojis 🎉!", + "questions": [ + { + "type": "list", + "name": "change_type", + "choices": [ + { + "value": "✨ feature", + "name": "✨ feature: A new feature." + }, + { + "value": "🐛 bug fix", + "name": "🐛 bug fix: A bug fix." + } + ], + "message": "Select the type of change you are committing" + }, + { + "type": "input", + "name": "message", + "message": "Body." + }, + { + "type": "confirm", + "name": "show_message", + "message": "Do you want to add body message in commit?" + } + ] + } + } + } +""" TOML_STR_INFO_PATH = """ [tool.commitizen.customize] message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}" - example = "feature: this feature enable customize through config file" + example = "feature: this feature enables customization through a config file" schema = ": " bump_pattern = "^(break|new|fix|hotfix)" bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"} @@ -150,7 +249,7 @@ "commitizen": { "customize": { "message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}", - "example": "feature: this feature enable customize through config file", + "example": "feature: this feature enables customization through a config file", "schema": ": ", "bump_pattern": "^(break|new|fix|hotfix)", "bump_map": { @@ -169,7 +268,7 @@ commitizen: customize: message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}" - example: 'feature: this feature enable customize through config file' + example: 'feature: this feature enables customization through a config file' schema: ": " bump_pattern: "^(break|new|fix|hotfix)" bump_map: @@ -183,7 +282,7 @@ TOML_STR_WITHOUT_INFO = """ [tool.commitizen.customize] message_template = "{{change_type}}:{% if show_message %} {{message}}{% endif %}" - example = "feature: this feature enable customize through config file" + example = "feature: this feature enables customization through a config file" schema = ": " bump_pattern = "^(break|new|fix|hotfix)" bump_map = {"break" = "MAJOR", "new" = "MINOR", "fix" = "PATCH", "hotfix" = "PATCH"} @@ -194,7 +293,7 @@ "commitizen": { "customize": { "message_template": "{{change_type}}:{% if show_message %} {{message}}{% endif %}", - "example": "feature: this feature enable customize through config file", + "example": "feature: this feature enables customization through a config file", "schema": ": ", "bump_pattern": "^(break|new|fix|hotfix)", "bump_map": { @@ -212,7 +311,7 @@ commitizen: customize: message_template: "{{change_type}}:{% if show_message %} {{message}}{% endif %}" - example: 'feature: this feature enable customize through config file' + example: 'feature: this feature enables customization through a config file' schema: ": " bump_pattern: "^(break|new|fix|hotfix)" bump_map: @@ -260,6 +359,16 @@ def config_without_info(request): return request.param +@pytest.fixture( + params=[ + TomlConfig(data=TOML_WITH_UNICODE, path="not_exist.toml"), + JsonConfig(data=JSON_WITH_UNICODE, path="not_exist.json"), + ] +) +def config_with_unicode(request): + return request.param + + def test_initialize_cz_customize_failed(): with pytest.raises(MissingCzCustomizeConfigError) as excinfo: config = BaseConfig() @@ -273,6 +382,11 @@ def test_bump_pattern(config): assert cz.bump_pattern == "^(break|new|fix|hotfix)" +def test_bump_pattern_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert cz.bump_pattern == "^(✨ feat|🐛 bug fix)" + + def test_bump_map(config): cz = CustomizeCommitsCz(config) assert cz.bump_map == { @@ -283,6 +397,15 @@ def test_bump_map(config): } +def test_bump_map_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert cz.bump_map == { + "break": "MAJOR", + "✨ feat": "MINOR", + "🐛 bug fix": "MINOR", + } + + def test_change_type_order(config): cz = CustomizeCommitsCz(config) assert cz.change_type_order == [ @@ -294,6 +417,17 @@ def test_change_type_order(config): ] +def test_change_type_order_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert cz.change_type_order == [ + "perf", + "BREAKING CHANGE", + "feat", + "fix", + "refactor", + ] + + def test_questions(config): cz = CustomizeCommitsCz(config) questions = cz.questions() @@ -317,29 +451,87 @@ def test_questions(config): assert list(questions) == expected_questions +def test_questions_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + questions = cz.questions() + expected_questions = [ + { + "type": "list", + "name": "change_type", + "choices": [ + {"value": "✨ feature", "name": "✨ feature: A new feature."}, + {"value": "🐛 bug fix", "name": "🐛 bug fix: A bug fix."}, + ], + "message": "Select the type of change you are committing", + }, + {"type": "input", "name": "message", "message": "Body."}, + { + "type": "confirm", + "name": "show_message", + "message": "Do you want to add body message in commit?", + }, + ] + assert list(questions) == expected_questions + + def test_answer(config): cz = CustomizeCommitsCz(config) answers = { "change_type": "feature", - "message": "this feature enaable customize through config file", + "message": "this feature enables customization through a config file", "show_message": True, } message = cz.message(answers) - assert message == "feature: this feature enaable customize through config file" + assert ( + message == "feature: this feature enables customization through a config file" + ) cz = CustomizeCommitsCz(config) answers = { "change_type": "feature", - "message": "this feature enaable customize through config file", + "message": "this feature enables customization through a config file", "show_message": False, } message = cz.message(answers) assert message == "feature:" +def test_answer_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + answers = { + "change_type": "✨ feature", + "message": "this feature enables customization through a config file", + "show_message": True, + } + message = cz.message(answers) + assert ( + message == "✨ feature: this feature enables customization through a config file" + ) + + cz = CustomizeCommitsCz(config_with_unicode) + answers = { + "change_type": "✨ feature", + "message": "this feature enables customization through a config file", + "show_message": False, + } + message = cz.message(answers) + assert message == "✨ feature:" + + def test_example(config): cz = CustomizeCommitsCz(config) - assert "feature: this feature enable customize through config file" in cz.example() + assert ( + "feature: this feature enables customization through a config file" + in cz.example() + ) + + +def test_example_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert ( + "✨ feature: this feature enables customization through a config file" + in cz.example() + ) def test_schema(config): @@ -352,11 +544,21 @@ def test_schema_pattern(config): assert r"(feature|bug fix):(\s.*)" in cz.schema_pattern() +def test_schema_pattern_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert r"(✨ feature|🐛 bug fix):(\s.*)" in cz.schema_pattern() + + def test_info(config): cz = CustomizeCommitsCz(config) assert "This is a customized cz." in cz.info() +def test_info_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert "This is a customized cz with emojis 🎉!" in cz.info() + + def test_info_with_info_path(tmpdir, config_info): with tmpdir.as_cwd(): tmpfile = tmpdir.join("info.txt") @@ -376,11 +578,28 @@ def test_commit_parser(config): assert cz.commit_parser == "^(?Pfeature|bug fix):\\s(?P.*)?" +def test_commit_parser_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert ( + cz.commit_parser == "^(?P✨ feature|🐛 bug fix):\\s(?P.*)?" + ) + + def test_changelog_pattern(config): cz = CustomizeCommitsCz(config) assert cz.changelog_pattern == "^(feature|bug fix)?(!)?" +def test_changelog_pattern_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert cz.changelog_pattern == "^(✨ feature|🐛 bug fix)?(!)?" + + def test_change_type_map(config): cz = CustomizeCommitsCz(config) assert cz.change_type_map == {"feature": "Feat", "bug fix": "Fix"} + + +def test_change_type_map_unicode(config_with_unicode): + cz = CustomizeCommitsCz(config_with_unicode) + assert cz.change_type_map == {"✨ feature": "Feat", "🐛 bug fix": "Fix"} From 231ff3ecc0430562874d780d026fe8b4dd3de612 Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sun, 23 Oct 2022 10:56:54 -0700 Subject: [PATCH 04/38] fix(json_config.py): remove unused import --- commitizen/config/json_config.py | 1 - 1 file changed, 1 deletion(-) diff --git a/commitizen/config/json_config.py b/commitizen/config/json_config.py index 5a6e86b4a1..0a8327b6d2 100644 --- a/commitizen/config/json_config.py +++ b/commitizen/config/json_config.py @@ -1,5 +1,4 @@ import json -import sys from pathlib import Path from typing import Union From 2ab376f6566623387716fd3d64af8768e819baab Mon Sep 17 00:00:00 2001 From: "Hendry, Adam" Date: Mon, 17 Oct 2022 08:29:19 -0700 Subject: [PATCH 05/38] fix(pythonpackage.yml): use `bash` Specify `shell` as `bash` in `Run tests and linters` step. Fixes: Issue #604 --- .github/workflows/pythonpackage.yml | 52 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index d377023813..aa87888b16 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -10,29 +10,29 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install -U pip poetry - poetry --version - poetry install - - name: Run tests and linters - run: | - git config --global user.email "action@github.com" - git config --global user.name "GitHub Action" - ./scripts/test - shell: bash - - name: Upload coverage to Codecov - if: runner.os == 'Linux' - uses: codecov/codecov-action@v1.0.3 - with: - token: ${{secrets.CODECOV_TOKEN}} - file: ./coverage.xml - flags: unittests - name: codecov-umbrella + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install -U pip poetry + poetry --version + poetry install + - name: Run tests and linters + run: | + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + ./scripts/test + shell: bash + - name: Upload coverage to Codecov + if: runner.os == 'Linux' + uses: codecov/codecov-action@v1.0.3 + with: + token: ${{secrets.CODECOV_TOKEN}} + file: ./coverage.xml + flags: unittests + name: codecov-umbrella From 5cff7c3f4dc68f8c00dbc6c200aed35ea52614f3 Mon Sep 17 00:00:00 2001 From: "Hendry, Adam" Date: Wed, 19 Oct 2022 11:44:44 -0700 Subject: [PATCH 06/38] fix(pythonpackage.yml): undo indent reformatting --- .github/workflows/pythonpackage.yml | 52 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index aa87888b16..d377023813 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -10,29 +10,29 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install -U pip poetry - poetry --version - poetry install - - name: Run tests and linters - run: | - git config --global user.email "action@github.com" - git config --global user.name "GitHub Action" - ./scripts/test - shell: bash - - name: Upload coverage to Codecov - if: runner.os == 'Linux' - uses: codecov/codecov-action@v1.0.3 - with: - token: ${{secrets.CODECOV_TOKEN}} - file: ./coverage.xml - flags: unittests - name: codecov-umbrella + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install -U pip poetry + poetry --version + poetry install + - name: Run tests and linters + run: | + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + ./scripts/test + shell: bash + - name: Upload coverage to Codecov + if: runner.os == 'Linux' + uses: codecov/codecov-action@v1.0.3 + with: + token: ${{secrets.CODECOV_TOKEN}} + file: ./coverage.xml + flags: unittests + name: codecov-umbrella From 8333aab6b15aa4bc26bb2763934c06e6bd74508d Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Wed, 19 Oct 2022 19:36:13 -0700 Subject: [PATCH 07/38] test(cli): skip argcomplete activation on Windows `argcomplete` does not support Git Bash on Windows out of the box. For details, see https://kislyuk.github.io/argcomplete/#git-bash-support. --- tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 68a9c04a23..54a2dcd775 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -97,7 +97,7 @@ def test_argcomplete_activation(): Equivalent to run: $ eval "$(register-python-argcomplete pytest)" """ - output = subprocess.run(["register-python-argcomplete", "cz"]) + output = subprocess.run(["py", "-m", "register-python-argcomplete", "cz"]) assert output.returncode == 0 From f1d0d5df4ee263f5365ac472864ddd01d1043318 Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Thu, 20 Oct 2022 12:18:24 -0700 Subject: [PATCH 08/38] test(argcomplete): fix command `py -m` was added to command in `test_argcomplete_activation` during experimentation and was forgotten to be removed. --- tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 54a2dcd775..68a9c04a23 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -97,7 +97,7 @@ def test_argcomplete_activation(): Equivalent to run: $ eval "$(register-python-argcomplete pytest)" """ - output = subprocess.run(["py", "-m", "register-python-argcomplete", "cz"]) + output = subprocess.run(["register-python-argcomplete", "cz"]) assert output.returncode == 0 From 5a0cd791fc284b1aa2cbc3ca5ee2a616b934220f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 28 Oct 2022 03:35:49 +0000 Subject: [PATCH 09/38] =?UTF-8?q?bump:=20version=202.35.0=20=E2=86=92=202.?= =?UTF-8?q?36.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 18 ++++++++++++++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 443ea360c1..bafa7aa7fc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: no-commit-to-branch - repo: https://github.com/commitizen-tools/commitizen - rev: v2.35.0 # automatically updated by Commitizen + rev: v2.36.0 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index e9910e9f70..8cdfbb28de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,22 @@ +## v2.36.0 (2022-10-28) + +### Feat + +- **scripts**: remove `venv/bin/` +- **scripts**: add error message to `test` + +### Fix + +- **scripts/test**: MinGW64 workaround +- **scripts/test**: use double-quotes +- **scripts**: pydocstyle and cz +- **bump.py**: use `sys.stdin.isatty()` +- **scripts**: use cross-platform POSIX +- **scripts**: use portable shebang +- **pythonpackage.yml**: undo indent reformatting +- **pythonpackage.yml**: use `bash` + ## v2.35.0 (2022-09-23) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 59485c2bc3..07d3c71f32 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.35.0" +__version__ = "2.36.0" diff --git a/pyproject.toml b/pyproject.toml index e539fd60ff..bc02a2244f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.35.0" +version = "2.36.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -30,7 +30,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.35.0" +version = "2.36.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 6077e9bc467e602335dd1f172d7c80e784490e9d Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 6 Oct 2022 14:20:36 +1000 Subject: [PATCH 10/38] feat: add major-version-zero option to support initial package development --- commitizen/cli.py | 6 +++ commitizen/commands/bump.py | 18 +++++++- commitizen/defaults.py | 12 +++++ docs/bump.md | 33 ++++++++++++- tests/commands/test_bump_command.py | 72 ++++++++++++++++++++++++++++- tests/test_conf.py | 2 + tests/utils.py | 6 +++ 7 files changed, 145 insertions(+), 4 deletions(-) diff --git a/commitizen/cli.py b/commitizen/cli.py index 2064ef3bf1..bbad4e8b61 100644 --- a/commitizen/cli.py +++ b/commitizen/cli.py @@ -183,6 +183,12 @@ "default": False, "help": "retry commit if it fails the 1st time", }, + { + "name": ["--major-version-zero"], + "action": "store_true", + "default": None, + "help": "keep major version at zero, even for breaking changes", + }, { "name": "manual_version", "type": str, diff --git a/commitizen/commands/bump.py b/commitizen/commands/bump.py index 6e146b22ea..088a14ea25 100644 --- a/commitizen/commands/bump.py +++ b/commitizen/commands/bump.py @@ -5,7 +5,7 @@ import questionary from packaging.version import InvalidVersion, Version -from commitizen import bump, cmd, factory, git, out +from commitizen import bump, cmd, defaults, factory, git, out from commitizen.commands.changelog import Changelog from commitizen.config import BaseConfig from commitizen.exceptions import ( @@ -46,6 +46,7 @@ def __init__(self, config: BaseConfig, arguments: dict): "bump_message", "gpg_sign", "annotated_tag", + "major_version_zero", ] if arguments[key] is not None }, @@ -102,6 +103,7 @@ def __call__(self): # noqa: C901 tag_format: str = self.bump_settings["tag_format"] bump_commit_message: str = self.bump_settings["bump_message"] version_files: List[str] = self.bump_settings["version_files"] + major_version_zero: bool = self.bump_settings["major_version_zero"] dry_run: bool = self.arguments["dry_run"] is_yes: bool = self.arguments["yes"] @@ -127,6 +129,20 @@ def __call__(self): # noqa: C901 "--local-version cannot be combined with MANUAL_VERSION" ) + if major_version_zero: + raise NotAllowed( + "--major-version-zero cannot be combined with MANUAL_VERSION" + ) + + if major_version_zero: + if not current_version.startswith("0."): + raise NotAllowed( + f"--major-version-zero is meaningless for current version {current_version}" + ) + + # Update the bump map to ensure major version doesn't increment. + self.cz.bump_map = defaults.bump_map_major_version_zero + current_tag_version: str = bump.normalize_tag( current_version, tag_format=tag_format ) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 120ff66e2d..0dc3ffcfd3 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -40,6 +40,7 @@ class Settings(TypedDict, total=False): style: Optional[List[Tuple[str, str]]] customize: CzSettings encoding: str + major_version_zero: bool name: str = "cz_conventional_commits" @@ -66,6 +67,7 @@ class Settings(TypedDict, total=False): "update_changelog_on_bump": False, "use_shortcuts": False, "encoding": "utf-8", + "major_version_zero": False, } MAJOR = "MAJOR" @@ -83,6 +85,16 @@ class Settings(TypedDict, total=False): (r"^perf", PATCH), ) ) +bump_map_major_version_zero = OrderedDict( + ( + (r"^.+!$", MINOR), + (r"^BREAKING[\-\ ]CHANGE", MINOR), + (r"^feat", MINOR), + (r"^fix", PATCH), + (r"^refactor", PATCH), + (r"^perf", PATCH), + ) +) change_type_order = ["BREAKING CHANGE", "Feat", "Fix", "Refactor", "Perf"] bump_message = "bump: version $current_version → $new_version" diff --git a/docs/bump.md b/docs/bump.md index bf6f00d8e8..e94b96cb63 100644 --- a/docs/bump.md +++ b/docs/bump.md @@ -59,7 +59,8 @@ usage: cz bump [-h] [--dry-run] [--files-only] [--local-version] [--changelog] [--bump-message BUMP_MESSAGE] [--prerelease {alpha,beta,rc}] [--devrelease DEVRELEASE] [--increment {MAJOR,MINOR,PATCH}] [--check-consistency] [--annotated-tag] [--gpg-sign] - [--changelog-to-stdout] [--retry] [MANUAL_VERSION] + [--changelog-to-stdout] [--retry] [--major-version-zero] + [MANUAL_VERSION] positional arguments: MANUAL_VERSION bump to the given version (e.g: 1.5.3) @@ -93,6 +94,7 @@ options: --changelog-to-stdout Output changelog to the stdout --retry retry commit if it fails the 1st time + --major-version-zero keep major version at zero, even for breaking changes ``` ### `--files-only` @@ -199,6 +201,18 @@ It will retry the commit if it fails the 1st time. Useful to combine with code formatters, like [Prettier](https://prettier.io/). +### `--major-version-zero` + +A project in its initial development should have a major version zero, and even breaking changes +should not bump that major version from zero. This command ensures that behavior. + +If `--major-version-zero` is used for projects that have a version number greater than zero it fails. +If used together with a manual version the command also fails. + +We recommend setting `major_version_zero = true` in your configuration file while a project +is in its initial development. Remove that configuration using a breaking-change commit to bump +your project’s major version to `v1.0.0` once your project has reached maturity. + ## Avoid raising errors Some situations from commitizen rise an exit code different than 0. @@ -369,6 +383,8 @@ When set to `true` commitizen will create annotated tags. ```toml [tool.commitizen] +annotated_tag = true +``` --- @@ -379,7 +395,20 @@ When set to `true` commitizen will create gpg signed tags. ```toml [tool.commitizen] gpg_sign = true -annotated_tag = true +``` + +--- + +### `major_version_zero` + +When set to `true` commitizen will keep the major version at zero. +Useful during the initial development stage of your project. + +Defaults to: `false` + +```toml +[tool.commitizen] +major_version_zero = true ``` ## Custom bump diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index f83c344eff..4290a55f3c 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -22,7 +22,7 @@ NotAllowed, NoVersionSpecifiedError, ) -from tests.utils import create_file_and_commit +from tests.utils import create_file_and_commit, create_tag @pytest.mark.parametrize( @@ -151,6 +151,31 @@ def test_bump_major_increment(commit_msg, mocker): assert tag_exists is True +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.parametrize( + "commit_msg", + ( + "feat: new user interface\n\nBREAKING CHANGE: age is no longer supported", + "feat!: new user interface\n\nBREAKING CHANGE: age is no longer supported", + "feat!: new user interface", + "feat(user): new user interface\n\nBREAKING CHANGE: age is no longer supported", + "feat(user)!: new user interface\n\nBREAKING CHANGE: age is no longer supported", + "feat(user)!: new user interface", + "BREAKING CHANGE: age is no longer supported", + "BREAKING-CHANGE: age is no longer supported", + ), +) +def test_bump_major_increment_major_version_zero(commit_msg, mocker): + create_file_and_commit(commit_msg) + + testargs = ["cz", "bump", "--yes", "--major-version-zero"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + tag_exists = git.tag_exist("0.2.0") + assert tag_exists is True + + @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.parametrize( "commit_msg,increment,expected_tag", @@ -320,6 +345,34 @@ def test_bump_when_version_inconsistent_in_version_files( assert partial_expected_error_message in str(excinfo.value) +def test_bump_major_version_zero_when_major_is_not_zero(mocker, tmp_commitizen_project): + tmp_version_file = tmp_commitizen_project.join("__version__.py") + tmp_version_file.write("1.0.0") + tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") + tmp_commitizen_cfg_file.write( + f"[tool.commitizen]\n" + 'version="1.0.0"\n' + f'version_files = ["{str(tmp_version_file)}"]' + ) + tmp_changelog_file = tmp_commitizen_project.join("CHANGELOG.md") + tmp_changelog_file.write("## v1.0.0") + + create_file_and_commit("feat(user): new file") + create_tag("v1.0.0") + create_file_and_commit("feat(user)!: new file") + + testargs = ["cz", "bump", "--yes", "--major-version-zero"] + mocker.patch.object(sys, "argv", testargs) + + with pytest.raises(NotAllowed) as excinfo: + cli.main() + + expected_error_message = ( + "--major-version-zero is meaningless for current version 1.0.0" + ) + assert expected_error_message in str(excinfo.value) + + def test_bump_files_only(mocker, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("0.1.0") @@ -685,3 +738,20 @@ def test_bump_manual_version(mocker, manual_version): cli.main() tag_exists = git.tag_exist(manual_version) assert tag_exists is True + + +@pytest.mark.usefixtures("tmp_commitizen_project") +def test_bump_manual_version_disallows_major_version_zero(mocker): + create_file_and_commit("feat: new file") + + manual_version = "0.2.0" + testargs = ["cz", "bump", "--yes", "--major-version-zero", manual_version] + mocker.patch.object(sys, "argv", testargs) + + with pytest.raises(NotAllowed) as excinfo: + cli.main() + + expected_error_message = ( + "--major-version-zero cannot be combined with MANUAL_VERSION" + ) + assert expected_error_message in str(excinfo.value) diff --git a/tests/test_conf.py b/tests/test_conf.py index 340491a62d..79eaf5d00a 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -49,6 +49,7 @@ "update_changelog_on_bump": False, "use_shortcuts": False, "encoding": "utf-8", + "major_version_zero": False, } _new_settings = { @@ -65,6 +66,7 @@ "update_changelog_on_bump": False, "use_shortcuts": False, "encoding": "utf-8", + "major_version_zero": False, } _read_settings = { diff --git a/tests/utils.py b/tests/utils.py index 462efca511..5dcf6722e9 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -26,6 +26,12 @@ def create_file_and_commit(message: str, filename: Optional[str] = None): raise exceptions.CommitError(c.err) +def create_tag(tag: str): + c = git.tag(tag) + if c.return_code != 0: + raise exceptions.CommitError(c.err) + + def wait_for_tag(): """Wait for tag. From 06eaa152607bd2ca9ab6230e764ab23a3ecfa743 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 28 Oct 2022 09:09:03 +0000 Subject: [PATCH 11/38] =?UTF-8?q?bump:=20version=202.36.0=20=E2=86=92=202.?= =?UTF-8?q?37.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bafa7aa7fc..c584dba255 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: no-commit-to-branch - repo: https://github.com/commitizen-tools/commitizen - rev: v2.36.0 # automatically updated by Commitizen + rev: v2.37.0 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cdfbb28de..a8b46e2e2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.37.0 (2022-10-28) + +### Feat + +- add major-version-zero option to support initial package development + ## v2.36.0 (2022-10-28) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 07d3c71f32..09f14b57bb 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.36.0" +__version__ = "2.37.0" diff --git a/pyproject.toml b/pyproject.toml index bc02a2244f..03fae47472 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.36.0" +version = "2.37.0" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -30,7 +30,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.36.0" +version = "2.37.0" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From 257b4eb52ec5e2493bf4bcde09e7341c34f05d86 Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanovski Date: Wed, 16 Nov 2022 14:23:33 +0100 Subject: [PATCH 12/38] docs(README.md): update poetry dev dependency usage Since Poetry 1.2.0 dependency groups are introduced, and `--dev` becomes deprecated, and instead `--with dev` has to be provided. --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index b1c40b17f1..bf0a1c1c19 100644 --- a/docs/README.md +++ b/docs/README.md @@ -59,7 +59,7 @@ pip install -U commitizen ``` ```bash -poetry add commitizen --dev +poetry add commitizen --group dev ``` ### macOS From fee433cb8649e0b5596df52eb49fd99d4d09f15e Mon Sep 17 00:00:00 2001 From: Aleksandar Ivanovski Date: Thu, 17 Nov 2022 09:14:47 +0100 Subject: [PATCH 13/38] docs(README.md): include older version of poetry --- docs/README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/README.md b/docs/README.md index bf0a1c1c19..417f537852 100644 --- a/docs/README.md +++ b/docs/README.md @@ -58,10 +58,18 @@ You can add it to your local project using one of these: pip install -U commitizen ``` +for Poetry >= 1.2.0: + ```bash poetry add commitizen --group dev ``` +for Poetry < 1.2.0: + +```bash +poetry add commitizen --dev +``` + ### macOS On macOS, it can also be installed via [homebrew](https://formulae.brew.sh/formula/commitizen): From 6995cdfb863b2fbd378d1d1c1e866a706c3c13db Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Mon, 28 Nov 2022 23:01:20 +0800 Subject: [PATCH 14/38] test: fix test case changes due to tomlkit upgrade --- tests/commands/test_init_command.py | 1 - tests/test_conf.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/commands/test_init_command.py b/tests/commands/test_init_command.py index 22c027bdf9..d25f063e68 100644 --- a/tests/commands/test_init_command.py +++ b/tests/commands/test_init_command.py @@ -25,7 +25,6 @@ def ask(self): } expected_config = ( - "[tool]\n" "[tool.commitizen]\n" 'name = "cz_conventional_commits"\n' 'version = "0.0.1"\n' diff --git a/tests/test_conf.py b/tests/test_conf.py index 79eaf5d00a..c8ff648b71 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -139,8 +139,8 @@ def test_init_empty_config_content(self, tmpdir): toml_config = config.TomlConfig(data="", path=path) toml_config.init_empty_config_content() - with open(path, "r", encoding="utf-8") as toml_file: - assert toml_file.read() == "[tool]\n[tool.commitizen]\n" + with open(path, "r") as toml_file: + assert toml_file.read() == "[tool.commitizen]\n" def test_init_empty_config_content_with_existing_content(self, tmpdir): existing_content = "[tool.black]\n" "line-length = 88\n" From 725f898987a28ffcd73b7f4837115ab8f3d82b00 Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Tue, 29 Nov 2022 00:51:30 +0800 Subject: [PATCH 15/38] test(bump_command): replace \ as / for windows test cases --- tests/commands/test_bump_command.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/commands/test_bump_command.py b/tests/commands/test_bump_command.py index 4290a55f3c..7888d503d0 100644 --- a/tests/commands/test_bump_command.py +++ b/tests/commands/test_bump_command.py @@ -348,11 +348,12 @@ def test_bump_when_version_inconsistent_in_version_files( def test_bump_major_version_zero_when_major_is_not_zero(mocker, tmp_commitizen_project): tmp_version_file = tmp_commitizen_project.join("__version__.py") tmp_version_file.write("1.0.0") + tmp_version_file_string = str(tmp_version_file).replace("\\", "/") tmp_commitizen_cfg_file = tmp_commitizen_project.join("pyproject.toml") tmp_commitizen_cfg_file.write( f"[tool.commitizen]\n" 'version="1.0.0"\n' - f'version_files = ["{str(tmp_version_file)}"]' + f'version_files = ["{str(tmp_version_file_string)}"]' ) tmp_changelog_file = tmp_commitizen_project.join("CHANGELOG.md") tmp_changelog_file.write("## v1.0.0") From fa9a6d8732094dfc61e7ea7d50aa2304b580a42e Mon Sep 17 00:00:00 2001 From: Santiago Fraire Date: Mon, 28 Nov 2022 11:36:40 +0100 Subject: [PATCH 16/38] docs(config.md): list settings first and add missing param --- docs/config.md | 166 ++++++++++++++++++++----------------------------- 1 file changed, 69 insertions(+), 97 deletions(-) diff --git a/docs/config.md b/docs/config.md index 6ac36914b0..c6ee969be5 100644 --- a/docs/config.md +++ b/docs/config.md @@ -1,8 +1,33 @@ # Configuration +## Settings + +| Variable | Type | Default | Description | +| -------------------------- | ------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use | +| `version` | `str` | `None` | Current version. Example: "0.1.2" | +| `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] | +| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] | +| `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` | +| `gpg_sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. | +| `annotated_tag` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] | +| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] | +| `allow_abort` | `bool` | `false` | Disallow empty commit messages, useful in ci. [See more][allow_abort] | +| `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog | +| `changelog_incremental` | `bool` | `false` | Update changelog with the missing versions. This is good if you don't want to replace previous versions in the file. Note: when doing `cz bump --changelog` this is automatically set to `true` | +| `changelog_start_rev` | `str` | `None` | Start from a given git rev to generate the changelog | +| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)][additional-features] | +| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more][customization] | +| `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more][shortcuts] | +| `major_version_zero` | `bool` | `false` | When true, breaking changes on a `0.x` will remain as a `0.x` version. On `false`, a breaking change will bump a `0.x` version to `1.0`. [major-version-zero] | + ## pyproject.toml or .cz.toml -Add an entry to `pyproject.toml` or `.cz.toml`. Recommended for **python** projects. +Default and recommended configuration format for a project. +For a **python** project, we recommend adding an entry to your `pyproject.toml`. +You can also create a `.cz.toml` file at the root of your project folder. + +Example configuration: ```toml [tool.commitizen] @@ -26,123 +51,70 @@ style = [ ] ``` -`.cz.toml` is recommended for **other languages** projects (js, go, etc). - ## .cz.json or cz.json -JSON might be a more common configuration format for non-python projects, so Commitizen supports JSON config files, now. +Commitizen has support for JSON configuration. Recommended for `NodeJS` projects. ```json { - "commitizen": { - "name": "cz_conventional_commits", - "version": "0.1.0", - "version_files": [ - "src/__version__.py", - "pyproject.toml:version" - ], - "style": [ - [ - "qmark", - "fg:#ff9d00 bold" - ], - [ - "question", - "bold" - ], - [ - "answer", - "fg:#ff9d00 bold" - ], - [ - "pointer", - "fg:#ff9d00 bold" - ], - [ - "highlighted", - "fg:#ff9d00 bold" - ], - [ - "selected", - "fg:#cc5454" - ], - [ - "separator", - "fg:#cc5454" - ], - [ - "instruction", - "" - ], - [ - "text", - "" - ], - [ - "disabled", - "fg:#858585 italic" - ] - ] - } + "commitizen": { + "name": "cz_conventional_commits", + "version": "0.1.0", + "version_files": ["src/__version__.py", "pyproject.toml:version"], + "style": [ + ["qmark", "fg:#ff9d00 bold"], + ["question", "bold"], + ["answer", "fg:#ff9d00 bold"], + ["pointer", "fg:#ff9d00 bold"], + ["highlighted", "fg:#ff9d00 bold"], + ["selected", "fg:#cc5454"], + ["separator", "fg:#cc5454"], + ["instruction", ""], + ["text", ""], + ["disabled", "fg:#858585 italic"] + ] + } } ``` ## .cz.yaml or cz.yaml -YAML is another format for **non-python** projects as well, supported by Commitizen: + +YAML configuration is supported by Commitizen. Recommended for `Go`, `ansible`, or even `helm` charts projects. ```yaml commitizen: name: cz_conventional_commits version: 0.1.0 version_files: - - src/__version__.py - - pyproject.toml:version + - src/__version__.py + - pyproject.toml:version style: - - - qmark - - fg:#ff9d00 bold - - - question - - bold - - - answer - - fg:#ff9d00 bold - - - pointer - - fg:#ff9d00 bold - - - highlighted - - fg:#ff9d00 bold - - - selected - - fg:#cc5454 - - - separator - - fg:#cc5454 - - - instruction - - '' - - - text - - '' - - - disabled - - fg:#858585 italic + - - qmark + - fg:#ff9d00 bold + - - question + - bold + - - answer + - fg:#ff9d00 bold + - - pointer + - fg:#ff9d00 bold + - - highlighted + - fg:#ff9d00 bold + - - selected + - fg:#cc5454 + - - separator + - fg:#cc5454 + - - instruction + - "" + - - text + - "" + - - disabled + - fg:#858585 italic ``` -## Settings - -| Variable | Type | Default | Description | -|----------------------------| ------ | --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `name` | `str` | `"cz_conventional_commits"` | Name of the committing rules to use | -| `version` | `str` | `None` | Current version. Example: "0.1.2" | -| `version_files` | `list` | `[ ]` | Files were the version will be updated. A pattern to match a line, can also be specified, separated by `:` [See more][version_files] | -| `tag_format` | `str` | `None` | Format for the git tag, useful for old projects, that use a convention like `"v1.2.1"`. [See more][tag_format] | -| `update_changelog_on_bump` | `bool` | `false` | Create changelog when running `cz bump` | -| `gpg_sign` | `bool` | `false` | Use gpg signed tags instead of lightweight tags. | -| `annotated_tag` | `bool` | `false` | Use annotated tags instead of lightweight tags. [See difference][annotated-tags-vs-lightweight] | -| `bump_message` | `str` | `None` | Create custom commit message, useful to skip ci. [See more][bump_message] | -| `allow_abort` | `bool` | `false` | Disallow empty commit messages, useful in ci. [See more][allow_abort] | -| `changelog_file` | `str` | `CHANGELOG.md` | filename of exported changelog | -| `changelog_incremental` | `bool` | `false` | Update changelog with the missing versions. This is good if you don't want to replace previous versions in the file. Note: when doing `cz bump --changelog` this is automatically set to `true` | -| `changelog_start_rev` | `str` | `None` | Start from a given git rev to generate the changelog | -| `style` | `list` | see above | Style for the prompts (It will merge this value with default style.) [See More (Styling your prompts with your favorite colors)][additional-features] | -| `customize` | `dict` | `None` | **This is only supported when config through `toml`.** Custom rules for committing and bumping. [See more][customization] | -| `use_shortcuts` | `bool` | `false` | If enabled, commitizen will show keyboard shortcuts when selecting from a list. Define a `key` for each of your choices to set the key. [See more][shortcuts] | - [version_files]: bump.md#version_files [tag_format]: bump.md#tag_format [bump_message]: bump.md#bump_message +[major-version-zero]: bump.md#-major-version-zero [allow_abort]: check.md#allow-abort [additional-features]: https://github.com/tmbo/questionary#additional-features [customization]: customization.md From 064d5803674e2606893634e32381a18538c8135b Mon Sep 17 00:00:00 2001 From: Santiago Fraire Willemoes Date: Tue, 29 Nov 2022 07:34:11 +0100 Subject: [PATCH 17/38] chore: add Funding --- .github/FUNDING.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000000..4a1d4af2d2 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +open_collective: commitizen-tools From 883f969b73a71162963eab658817d8df19e627a2 Mon Sep 17 00:00:00 2001 From: Gerard Salvatella Date: Sun, 27 Nov 2022 13:07:08 +0100 Subject: [PATCH 18/38] fix(changelog): allow rev range lookups without a tag format The current default setting for `tag_format` is `None`. This is not a problem for the `bump` command, since the `normalize_tag` function defaults to `$version` when no `tag_format` is passed. However it is a problem for the `changelog` command, which seems to explicitly demand a `tag_format` in order to run a rev-range lookup. This creates issues like https://github.com/commitizen-tools/commitizen/issues/622. Either a sane default needs to be set for `tag_format` or the restriction in `changelog` has to be uplifted. In this commit the latter has been chosen. A test is also implemented to check that `changelog` will always compute a rev range with the default tag format. Fixes https://github.com/commitizen-tools/commitizen/issues/622 --- commitizen/commands/changelog.py | 2 +- tests/commands/test_changelog_command.py | 31 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/commitizen/commands/changelog.py b/commitizen/commands/changelog.py index ff735f6ad6..d95aa2d7bf 100644 --- a/commitizen/commands/changelog.py +++ b/commitizen/commands/changelog.py @@ -138,7 +138,7 @@ def __call__(self): ) start_rev = self._find_incremental_rev(latest_tag_version, tags) - if self.rev_range and self.tag_format: + if self.rev_range: start_rev, end_rev = changelog.get_oldest_and_newest_rev( tags, version=self.rev_range, diff --git a/tests/commands/test_changelog_command.py b/tests/commands/test_changelog_command.py index e6188de69c..006997b160 100644 --- a/tests/commands/test_changelog_command.py +++ b/tests/commands/test_changelog_command.py @@ -659,6 +659,37 @@ def test_changelog_from_rev_single_version_not_found( assert "Could not find a valid revision" in str(excinfo) +@pytest.mark.usefixtures("tmp_commitizen_project") +@pytest.mark.freeze_time("2022-02-13") +def test_changelog_from_rev_range_default_tag_format( + mocker, config_path, changelog_path +): + """Checks that rev_range is calculated with the default (None) tag format""" + # create commit and tag + create_file_and_commit("feat: new file") + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + wait_for_tag() + + create_file_and_commit("feat: after 0.2.0") + create_file_and_commit("feat: another feature") + + testargs = ["cz", "bump", "--yes"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + wait_for_tag() + + testargs = ["cz", "changelog", "0.3.0"] + mocker.patch.object(sys, "argv", testargs) + cli.main() + + with open(changelog_path, "r") as f: + out = f.read() + + assert "new file" not in out + + @pytest.mark.usefixtures("tmp_commitizen_project") @pytest.mark.freeze_time("2022-02-13") def test_changelog_from_rev_range_version_not_found(mocker, config_path): From 37c088cfb97c37d11172e245404e8f07a4216117 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 30 Nov 2022 08:14:57 +0000 Subject: [PATCH 19/38] =?UTF-8?q?bump:=20version=202.37.0=20=E2=86=92=202.?= =?UTF-8?q?37.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- CHANGELOG.md | 6 ++++++ commitizen/__version__.py | 2 +- pyproject.toml | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c584dba255..4d098b2b3d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: no-commit-to-branch - repo: https://github.com/commitizen-tools/commitizen - rev: v2.37.0 # automatically updated by Commitizen + rev: v2.37.1 # automatically updated by Commitizen hooks: - id: commitizen - id: commitizen-branch diff --git a/CHANGELOG.md b/CHANGELOG.md index a8b46e2e2a..340109aa8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +## v2.37.1 (2022-11-30) + +### Fix + +- **changelog**: allow rev range lookups without a tag format + ## v2.37.0 (2022-10-28) ### Feat diff --git a/commitizen/__version__.py b/commitizen/__version__.py index 09f14b57bb..3d156ee7ac 100644 --- a/commitizen/__version__.py +++ b/commitizen/__version__.py @@ -1 +1 @@ -__version__ = "2.37.0" +__version__ = "2.37.1" diff --git a/pyproject.toml b/pyproject.toml index 03fae47472..80cf47d246 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.commitizen] -version = "2.37.0" +version = "2.37.1" tag_format = "v$version" version_files = [ "pyproject.toml:version", @@ -30,7 +30,7 @@ exclude = ''' [tool.poetry] name = "commitizen" -version = "2.37.0" +version = "2.37.1" description = "Python commitizen client tool" authors = ["Santiago Fraire "] license = "MIT" From e63be683b1a7196fba745f85cf46e5b85ead3e4b Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 15:46:58 -0700 Subject: [PATCH 20/38] feat(unicode): add unicode support This will allow commiting, e.g., emoji's and parsing commit messages for unicode characters when creating change logs. --- commitizen/defaults.py | 2 ++ tests/test_conf.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 0dc3ffcfd3..79bb36eb67 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -41,6 +41,7 @@ class Settings(TypedDict, total=False): customize: CzSettings encoding: str major_version_zero: bool + encoding: str name: str = "cz_conventional_commits" @@ -68,6 +69,7 @@ class Settings(TypedDict, total=False): "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index c8ff648b71..2ad05208ec 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -50,6 +50,7 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _new_settings = { @@ -67,6 +68,7 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _read_settings = { From 13144e30d9787fe89efb5acf400685a3f50ada60 Mon Sep 17 00:00:00 2001 From: "Hendry, Adam" Date: Wed, 19 Oct 2022 12:20:33 -0700 Subject: [PATCH 21/38] fix(scripts): use portable shebang Switch `#!/bin/sh` to `#!/usr/bin/env sh` so scripts work on Windows as well as Linux and MacOS. --- scripts/format | 3 +-- scripts/test | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/format b/scripts/format index 9d300e964b..b71a6d96d9 100755 --- a/scripts/format +++ b/scripts/format @@ -1,5 +1,4 @@ -#!/usr/bin/env sh -set -e +#!/usr/bin/env sh -e export PREFIX="poetry run python -m " diff --git a/scripts/test b/scripts/test index ea5a318988..3504ccc8df 100755 --- a/scripts/test +++ b/scripts/test @@ -1,5 +1,4 @@ -#!/usr/bin/env sh -set -e +#!/usr/bin/env sh -e export PREFIX='poetry run python -m ' export REGEX='^(?![.]|venv).*' From a49e0961fd96b8789fd38b4759f1bbdb96d0ff29 Mon Sep 17 00:00:00 2001 From: "Hendry, Adam" Date: Wed, 19 Oct 2022 12:48:50 -0700 Subject: [PATCH 22/38] fix(scripts): use cross-platform POSIX - Change shebang from `#!/bin/sh` to `#!/usr/bin/env sh` - Set `$PREFIX` depending on OS --- scripts/format | 3 ++- scripts/test | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/format b/scripts/format index b71a6d96d9..9d300e964b 100755 --- a/scripts/format +++ b/scripts/format @@ -1,4 +1,5 @@ -#!/usr/bin/env sh -e +#!/usr/bin/env sh +set -e export PREFIX="poetry run python -m " diff --git a/scripts/test b/scripts/test index 3504ccc8df..ea5a318988 100755 --- a/scripts/test +++ b/scripts/test @@ -1,4 +1,5 @@ -#!/usr/bin/env sh -e +#!/usr/bin/env sh +set -e export PREFIX='poetry run python -m ' export REGEX='^(?![.]|venv).*' From 621179202c83014252122e904f5be7a4c72116bd Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Wed, 19 Oct 2022 19:36:13 -0700 Subject: [PATCH 23/38] test(cli): skip argcomplete activation on Windows `argcomplete` does not support Git Bash on Windows out of the box. For details, see https://kislyuk.github.io/argcomplete/#git-bash-support. --- tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 68a9c04a23..54a2dcd775 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -97,7 +97,7 @@ def test_argcomplete_activation(): Equivalent to run: $ eval "$(register-python-argcomplete pytest)" """ - output = subprocess.run(["register-python-argcomplete", "cz"]) + output = subprocess.run(["py", "-m", "register-python-argcomplete", "cz"]) assert output.returncode == 0 From 41188f293fc767f45731b67219c04236728b98d6 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 6 Oct 2022 14:20:36 +1000 Subject: [PATCH 24/38] feat: add major-version-zero option to support initial package development --- commitizen/defaults.py | 2 ++ tests/test_conf.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 79bb36eb67..88cd08b8eb 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -42,6 +42,7 @@ class Settings(TypedDict, total=False): encoding: str major_version_zero: bool encoding: str + major_version_zero: bool name: str = "cz_conventional_commits" @@ -70,6 +71,7 @@ class Settings(TypedDict, total=False): "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index 2ad05208ec..c5487fe5f7 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -51,6 +51,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _new_settings = { @@ -69,6 +70,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _read_settings = { From bf0202dd62310f3896181473fdab827c396dac20 Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 15:46:58 -0700 Subject: [PATCH 25/38] feat(unicode): add unicode support This will allow commiting, e.g., emoji's and parsing commit messages for unicode characters when creating change logs. --- commitizen/defaults.py | 2 ++ tests/test_conf.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 88cd08b8eb..fd02405f58 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -43,6 +43,7 @@ class Settings(TypedDict, total=False): major_version_zero: bool encoding: str major_version_zero: bool + encoding: str name: str = "cz_conventional_commits" @@ -72,6 +73,7 @@ class Settings(TypedDict, total=False): "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index c5487fe5f7..7c1bbab05f 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -52,6 +52,7 @@ "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _new_settings = { @@ -71,6 +72,7 @@ "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _read_settings = { @@ -143,8 +145,8 @@ def test_init_empty_config_content(self, tmpdir): toml_config = config.TomlConfig(data="", path=path) toml_config.init_empty_config_content() - with open(path, "r") as toml_file: - assert toml_file.read() == "[tool.commitizen]\n" + with open(path, "r", encoding="utf-8") as toml_file: + assert toml_file.read() == "[tool]\n[tool.commitizen]\n" def test_init_empty_config_content_with_existing_content(self, tmpdir): existing_content = "[tool.black]\n" "line-length = 88\n" From 72b8ce61901d021406de636eddd4e8a2bb3d821d Mon Sep 17 00:00:00 2001 From: "Hendry, Adam" Date: Mon, 17 Oct 2022 08:29:19 -0700 Subject: [PATCH 26/38] fix(pythonpackage.yml): use `bash` Specify `shell` as `bash` in `Run tests and linters` step. Fixes: Issue #604 --- .github/workflows/pythonpackage.yml | 52 ++++++++++++++--------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/.github/workflows/pythonpackage.yml b/.github/workflows/pythonpackage.yml index d377023813..aa87888b16 100644 --- a/.github/workflows/pythonpackage.yml +++ b/.github/workflows/pythonpackage.yml @@ -10,29 +10,29 @@ jobs: platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install -U pip poetry - poetry --version - poetry install - - name: Run tests and linters - run: | - git config --global user.email "action@github.com" - git config --global user.name "GitHub Action" - ./scripts/test - shell: bash - - name: Upload coverage to Codecov - if: runner.os == 'Linux' - uses: codecov/codecov-action@v1.0.3 - with: - token: ${{secrets.CODECOV_TOKEN}} - file: ./coverage.xml - flags: unittests - name: codecov-umbrella + - uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install -U pip poetry + poetry --version + poetry install + - name: Run tests and linters + run: | + git config --global user.email "action@github.com" + git config --global user.name "GitHub Action" + ./scripts/test + shell: bash + - name: Upload coverage to Codecov + if: runner.os == 'Linux' + uses: codecov/codecov-action@v1.0.3 + with: + token: ${{secrets.CODECOV_TOKEN}} + file: ./coverage.xml + flags: unittests + name: codecov-umbrella From 766372c9598601ab54579da142353a61289f4c28 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 6 Oct 2022 14:20:36 +1000 Subject: [PATCH 27/38] feat: add major-version-zero option to support initial package development --- commitizen/defaults.py | 6 ------ tests/test_conf.py | 6 ------ 2 files changed, 12 deletions(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index fd02405f58..0dc3ffcfd3 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -41,9 +41,6 @@ class Settings(TypedDict, total=False): customize: CzSettings encoding: str major_version_zero: bool - encoding: str - major_version_zero: bool - encoding: str name: str = "cz_conventional_commits" @@ -71,9 +68,6 @@ class Settings(TypedDict, total=False): "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, - "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index 7c1bbab05f..79eaf5d00a 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -50,9 +50,6 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, - "encoding": "utf-8", } _new_settings = { @@ -70,9 +67,6 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, - "encoding": "utf-8", } _read_settings = { From ef75fe59bb8f05e79f64c049134abd4d3fe0011b Mon Sep 17 00:00:00 2001 From: Wei Lee Date: Mon, 28 Nov 2022 23:01:20 +0800 Subject: [PATCH 28/38] test: fix test case changes due to tomlkit upgrade --- tests/test_conf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_conf.py b/tests/test_conf.py index 79eaf5d00a..c8ff648b71 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -139,8 +139,8 @@ def test_init_empty_config_content(self, tmpdir): toml_config = config.TomlConfig(data="", path=path) toml_config.init_empty_config_content() - with open(path, "r", encoding="utf-8") as toml_file: - assert toml_file.read() == "[tool]\n[tool.commitizen]\n" + with open(path, "r") as toml_file: + assert toml_file.read() == "[tool.commitizen]\n" def test_init_empty_config_content_with_existing_content(self, tmpdir): existing_content = "[tool.black]\n" "line-length = 88\n" From 933037a1b31b8e9b95500047c180742c9f13b8c1 Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 15:46:58 -0700 Subject: [PATCH 29/38] feat(unicode): add unicode support This will allow commiting, e.g., emoji's and parsing commit messages for unicode characters when creating change logs. --- commitizen/defaults.py | 2 ++ tests/test_conf.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 0dc3ffcfd3..79bb36eb67 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -41,6 +41,7 @@ class Settings(TypedDict, total=False): customize: CzSettings encoding: str major_version_zero: bool + encoding: str name: str = "cz_conventional_commits" @@ -68,6 +69,7 @@ class Settings(TypedDict, total=False): "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index c8ff648b71..2ad05208ec 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -50,6 +50,7 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _new_settings = { @@ -67,6 +68,7 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _read_settings = { From 7dbb29f6f81527b1c7928f2ce85deeff67c3af7c Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 6 Oct 2022 14:20:36 +1000 Subject: [PATCH 30/38] feat: add major-version-zero option to support initial package development --- commitizen/defaults.py | 2 ++ tests/test_conf.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 79bb36eb67..88cd08b8eb 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -42,6 +42,7 @@ class Settings(TypedDict, total=False): encoding: str major_version_zero: bool encoding: str + major_version_zero: bool name: str = "cz_conventional_commits" @@ -70,6 +71,7 @@ class Settings(TypedDict, total=False): "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index 2ad05208ec..c5487fe5f7 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -51,6 +51,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _new_settings = { @@ -69,6 +70,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _read_settings = { From ffcb355af22f651614efa2210f2f1d19a973c9a0 Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 15:46:58 -0700 Subject: [PATCH 31/38] feat(unicode): add unicode support This will allow commiting, e.g., emoji's and parsing commit messages for unicode characters when creating change logs. --- commitizen/defaults.py | 2 ++ tests/test_conf.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 88cd08b8eb..fd02405f58 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -43,6 +43,7 @@ class Settings(TypedDict, total=False): major_version_zero: bool encoding: str major_version_zero: bool + encoding: str name: str = "cz_conventional_commits" @@ -72,6 +73,7 @@ class Settings(TypedDict, total=False): "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index c5487fe5f7..ead47b0600 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -52,6 +52,7 @@ "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _new_settings = { @@ -71,6 +72,7 @@ "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _read_settings = { From 2fd5bf53a36a1a5805b58d9cbc5652bd614ce1ed Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 15:46:58 -0700 Subject: [PATCH 32/38] feat(unicode): add unicode support This will allow commiting, e.g., emoji's and parsing commit messages for unicode characters when creating change logs. --- commitizen/defaults.py | 1 + tests/test_conf.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 1239673427..859a2eff68 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -68,6 +68,7 @@ class Settings(TypedDict, total=False): "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index c8ff648b71..2ad05208ec 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -50,6 +50,7 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _new_settings = { @@ -67,6 +68,7 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _read_settings = { From dbc715d75450dd2e606e3250c4eb9d9f50aaac00 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 6 Oct 2022 14:20:36 +1000 Subject: [PATCH 33/38] feat: add major-version-zero option to support initial package development --- commitizen/defaults.py | 1 + tests/test_conf.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 859a2eff68..efa97e2e8a 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -69,6 +69,7 @@ class Settings(TypedDict, total=False): "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index 2ad05208ec..c5487fe5f7 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -51,6 +51,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _new_settings = { @@ -69,6 +70,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _read_settings = { From 242056bb245fe23512e0678051c0c9769f24eab2 Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 15:46:58 -0700 Subject: [PATCH 34/38] feat(unicode): add unicode support This will allow commiting, e.g., emoji's and parsing commit messages for unicode characters when creating change logs. --- commitizen/defaults.py | 1 + tests/test_conf.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index efa97e2e8a..0de8303ddc 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -70,6 +70,7 @@ class Settings(TypedDict, total=False): "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index c5487fe5f7..ead47b0600 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -52,6 +52,7 @@ "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _new_settings = { @@ -71,6 +72,7 @@ "major_version_zero": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _read_settings = { From c73827d5ee36bd6cccce63a4112bb97260ae527f Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 6 Oct 2022 14:20:36 +1000 Subject: [PATCH 35/38] feat: add major-version-zero option to support initial package development --- commitizen/defaults.py | 2 ++ tests/test_conf.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 0de8303ddc..3e364bddff 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -41,6 +41,7 @@ class Settings(TypedDict, total=False): customize: CzSettings major_version_zero: bool encoding: str + major_version_zero: bool name: str = "cz_conventional_commits" @@ -71,6 +72,7 @@ class Settings(TypedDict, total=False): "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index ead47b0600..32ef495edf 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -53,6 +53,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _new_settings = { @@ -73,6 +74,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _read_settings = { From 271f50be77d97386bf7036ebb870b05c3998ba79 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 6 Oct 2022 14:20:36 +1000 Subject: [PATCH 36/38] feat: add major-version-zero option to support initial package development --- commitizen/defaults.py | 7 +++---- tests/test_conf.py | 8 -------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 3e364bddff..18870d879f 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -40,8 +40,11 @@ class Settings(TypedDict, total=False): style: Optional[List[Tuple[str, str]]] customize: CzSettings major_version_zero: bool +<<<<<<< HEAD encoding: str major_version_zero: bool +======= +>>>>>>> 366081c (feat: add major-version-zero option to support initial package development) name: str = "cz_conventional_commits" @@ -69,10 +72,6 @@ class Settings(TypedDict, total=False): "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index 32ef495edf..c8ff648b71 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -50,10 +50,6 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, } _new_settings = { @@ -71,10 +67,6 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, - "encoding": "utf-8", - "major_version_zero": False, } _read_settings = { From 8602fd036b5bb02aff0b1465fce4a7854841d7df Mon Sep 17 00:00:00 2001 From: Adam Hendry Date: Sat, 22 Oct 2022 15:46:58 -0700 Subject: [PATCH 37/38] feat(unicode): add unicode support This will allow commiting, e.g., emoji's and parsing commit messages for unicode characters when creating change logs. --- commitizen/defaults.py | 5 +---- tests/test_conf.py | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 18870d879f..859a2eff68 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -40,11 +40,7 @@ class Settings(TypedDict, total=False): style: Optional[List[Tuple[str, str]]] customize: CzSettings major_version_zero: bool -<<<<<<< HEAD encoding: str - major_version_zero: bool -======= ->>>>>>> 366081c (feat: add major-version-zero option to support initial package development) name: str = "cz_conventional_commits" @@ -72,6 +68,7 @@ class Settings(TypedDict, total=False): "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index c8ff648b71..2ad05208ec 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -50,6 +50,7 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _new_settings = { @@ -67,6 +68,7 @@ "use_shortcuts": False, "encoding": "utf-8", "major_version_zero": False, + "encoding": "utf-8", } _read_settings = { From ca3cef4ec3cb87969c6b7c4f575fc6f54a49c322 Mon Sep 17 00:00:00 2001 From: Jens Troeger Date: Thu, 6 Oct 2022 14:20:36 +1000 Subject: [PATCH 38/38] feat: add major-version-zero option to support initial package development --- commitizen/defaults.py | 2 ++ tests/test_conf.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/commitizen/defaults.py b/commitizen/defaults.py index 859a2eff68..be11146e98 100644 --- a/commitizen/defaults.py +++ b/commitizen/defaults.py @@ -41,6 +41,7 @@ class Settings(TypedDict, total=False): customize: CzSettings major_version_zero: bool encoding: str + major_version_zero: bool name: str = "cz_conventional_commits" @@ -69,6 +70,7 @@ class Settings(TypedDict, total=False): "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } MAJOR = "MAJOR" diff --git a/tests/test_conf.py b/tests/test_conf.py index 2ad05208ec..c5487fe5f7 100644 --- a/tests/test_conf.py +++ b/tests/test_conf.py @@ -51,6 +51,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _new_settings = { @@ -69,6 +70,7 @@ "encoding": "utf-8", "major_version_zero": False, "encoding": "utf-8", + "major_version_zero": False, } _read_settings = {