Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions commitizen/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ def read_cfg() -> BaseConfig:

_conf: Union[TomlConfig, JsonConfig, YAMLConfig]

with open(filename, "r") as f:
data: str = f.read()
with open(filename, "rb") as f:
data: bytes = f.read()

if "toml" in filename.suffix:
_conf = TomlConfig(data=data, path=filename)
Expand Down
2 changes: 1 addition & 1 deletion commitizen/config/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ def update(self, data: dict):
def add_path(self, path: Union[str, Path]):
self._path = Path(path)

def _parse_setting(self, data: str) -> dict:
def _parse_setting(self, data: Union[bytes, str]) -> dict:
raise NotImplementedError()
6 changes: 3 additions & 3 deletions commitizen/config/json_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class JsonConfig(BaseConfig):
def __init__(self, *, data: str, path: Union[Path, str]):
def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]):
super(JsonConfig, self).__init__()
self.is_empty_config = False
self._parse_setting(data)
Expand All @@ -22,15 +22,15 @@ def set_key(self, key, value):
For now only strings are supported.
We use to update the version number.
"""
with open(self.path, "r") as f:
with open(self.path, "rb") as f:
parser = json.load(f)

parser["commitizen"][key] = value
with open(self.path, "w") as f:
json.dump(parser, f)
return self

def _parse_setting(self, data: str):
def _parse_setting(self, data: Union[bytes, str]):
"""We expect to have a section in .cz.json looking like

```
Expand Down
6 changes: 3 additions & 3 deletions commitizen/config/toml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class TomlConfig(BaseConfig):
def __init__(self, *, data: str, path: Union[Path, str]):
def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]):
super(TomlConfig, self).__init__()
self.is_empty_config = False
self._parse_setting(data)
Expand All @@ -23,15 +23,15 @@ def set_key(self, key, value):
For now only strings are supported.
We use to update the version number.
"""
with open(self.path, "r") as f:
with open(self.path, "rb") as f:
parser = parse(f.read())

parser["tool"]["commitizen"][key] = value
with open(self.path, "w") as f:
f.write(parser.as_string())
return self

def _parse_setting(self, data: str):
def _parse_setting(self, data: Union[bytes, str]):
"""We expect to have a section in pyproject looking like

```
Expand Down
6 changes: 3 additions & 3 deletions commitizen/config/yaml_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class YAMLConfig(BaseConfig):
def __init__(self, *, data: str, path: Union[Path, str]):
def __init__(self, *, data: Union[bytes, str], path: Union[Path, str]):
super(YAMLConfig, self).__init__()
self.is_empty_config = False
self._parse_setting(data)
Expand All @@ -17,7 +17,7 @@ def init_empty_config_content(self):
with open(self.path, "a") as json_file:
yaml.dump({"commitizen": {}}, json_file)

def _parse_setting(self, data: str):
def _parse_setting(self, data: Union[bytes, str]):
"""We expect to have a section in cz.yaml looking like

```
Expand All @@ -37,7 +37,7 @@ def set_key(self, key, value):
For now only strings are supported.
We use to update the version number.
"""
with open(self.path, "r") as yaml_file:
with open(self.path, "rb") as yaml_file:
parser = yaml.load(yaml_file, Loader=yaml.FullLoader)

parser["commitizen"][key] = value
Expand Down