Skip to content

Add Unicode Support #615

New issue

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

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

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
b5bccb3
chore(squash): merge `fix/ci` branch
adam-grant-hendry Oct 17, 2022
6bd488f
feat(unicode): add unicode support
adam-grant-hendry Oct 22, 2022
99b45aa
test(unicode): add tests
adam-grant-hendry Oct 23, 2022
231ff3e
fix(json_config.py): remove unused import
adam-grant-hendry Oct 23, 2022
2ab376f
fix(pythonpackage.yml): use `bash`
adam-grant-hendry Oct 17, 2022
5cff7c3
fix(pythonpackage.yml): undo indent reformatting
adam-grant-hendry Oct 19, 2022
8333aab
test(cli): skip argcomplete activation on Windows
adam-grant-hendry Oct 20, 2022
f1d0d5d
test(argcomplete): fix command
adam-grant-hendry Oct 20, 2022
5a0cd79
bump: version 2.35.0 → 2.36.0
github-actions[bot] Oct 28, 2022
6077e9b
feat: add major-version-zero option to support initial package develo…
jenstroeger Oct 6, 2022
06eaa15
bump: version 2.36.0 → 2.37.0
github-actions[bot] Oct 28, 2022
257b4eb
docs(README.md): update poetry dev dependency usage
Nov 16, 2022
fee433c
docs(README.md): include older version of poetry
Nov 17, 2022
6995cdf
test: fix test case changes due to tomlkit upgrade
Lee-W Nov 28, 2022
725f898
test(bump_command): replace \ as / for windows test cases
Lee-W Nov 28, 2022
fa9a6d8
docs(config.md): list settings first and add missing param
woile Nov 28, 2022
064d580
chore: add Funding
woile Nov 29, 2022
883f969
fix(changelog): allow rev range lookups without a tag format
gsalvatella Nov 27, 2022
37c088c
bump: version 2.37.0 → 2.37.1
github-actions[bot] Nov 30, 2022
e63be68
feat(unicode): add unicode support
adam-grant-hendry Oct 22, 2022
13144e3
fix(scripts): use portable shebang
adam-grant-hendry Oct 19, 2022
a49e096
fix(scripts): use cross-platform POSIX
adam-grant-hendry Oct 19, 2022
6211792
test(cli): skip argcomplete activation on Windows
adam-grant-hendry Oct 20, 2022
41188f2
feat: add major-version-zero option to support initial package develo…
jenstroeger Oct 6, 2022
bf0202d
feat(unicode): add unicode support
adam-grant-hendry Oct 22, 2022
72b8ce6
fix(pythonpackage.yml): use `bash`
adam-grant-hendry Oct 17, 2022
766372c
feat: add major-version-zero option to support initial package develo…
jenstroeger Oct 6, 2022
ef75fe5
test: fix test case changes due to tomlkit upgrade
Lee-W Nov 28, 2022
933037a
feat(unicode): add unicode support
adam-grant-hendry Oct 22, 2022
7dbb29f
feat: add major-version-zero option to support initial package develo…
jenstroeger Oct 6, 2022
ffcb355
feat(unicode): add unicode support
adam-grant-hendry Oct 22, 2022
d963804
Merge branch 'master' into feat/unicode
adam-grant-hendry Dec 3, 2022
2fd5bf5
feat(unicode): add unicode support
adam-grant-hendry Oct 22, 2022
dbc715d
feat: add major-version-zero option to support initial package develo…
jenstroeger Oct 6, 2022
242056b
feat(unicode): add unicode support
adam-grant-hendry Oct 22, 2022
c73827d
feat: add major-version-zero option to support initial package develo…
jenstroeger Oct 6, 2022
271f50b
feat: add major-version-zero option to support initial package develo…
jenstroeger Oct 6, 2022
8602fd0
feat(unicode): add unicode support
adam-grant-hendry Oct 22, 2022
ca3cef4
feat: add major-version-zero option to support initial package develo…
jenstroeger Oct 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions commitizen/bump.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions commitizen/changelog.py
Original file line number Diff line number Diff line change
@@ -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()

4 changes: 2 additions & 2 deletions commitizen/changelog_parser.py
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 2 additions & 0 deletions commitizen/commands/bump.py
Original file line number Diff line number Diff line change
@@ -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,
@@ -267,6 +268,7 @@ def __call__(self): # noqa: C901
current_version,
str(new_version),
version_files,
self.encoding,
check_consistency=self.check_consistency,
)

7 changes: 4 additions & 3 deletions commitizen/commands/changelog.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 2 additions & 1 deletion commitizen/commands/check.py
Original file line number Diff line number Diff line change
@@ -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:
5 changes: 3 additions & 2 deletions commitizen/commands/commit.py
Original file line number Diff line number Diff line change
@@ -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()
9 changes: 7 additions & 2 deletions commitizen/commands/init.py
Original file line number Diff line number Diff line change
@@ -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")
6 changes: 4 additions & 2 deletions commitizen/config/json_config.py
Original file line number Diff line number Diff line change
@@ -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

@@ -44,6 +45,7 @@ def _parse_setting(self, data: Union[bytes, str]) -> None:
```
"""
doc = json.loads(data)

try:
self.settings.update(doc["commitizen"])
except KeyError:
5 changes: 3 additions & 2 deletions commitizen/config/toml_config.py
Original file line number Diff line number Diff line change
@@ -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:
5 changes: 3 additions & 2 deletions commitizen/config/yaml_config.py
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion commitizen/cz/customize/customize.py
Original file line number Diff line number Diff line change
@@ -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:
2 changes: 1 addition & 1 deletion commitizen/cz/jira/jira.py
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions commitizen/defaults.py
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ class Settings(TypedDict, total=False):
style: Optional[List[Tuple[str, str]]]
customize: CzSettings
major_version_zero: bool
encoding: str
major_version_zero: bool


name: str = "cz_conventional_commits"
@@ -51,6 +53,7 @@ class Settings(TypedDict, total=False):
".cz.yaml",
"cz.yaml",
]
encoding: str = "utf-8"

DEFAULT_SETTINGS: Settings = {
"name": "cz_conventional_commits",
@@ -64,6 +67,9 @@ class Settings(TypedDict, total=False):
"changelog_start_rev": None,
"update_changelog_on_bump": False,
"use_shortcuts": False,
"encoding": "utf-8",
"major_version_zero": False,
"encoding": "utf-8",
"major_version_zero": False,
}

Loading