-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
314 feat(config): add support for the new class YAMLConfig at the root of the confi internal package 314 test(test_config): add test support for the class YAMLConfig 314 fix(YAMLConfig): add a TypeError exception to handle in _parse_settings method feat(init): add support for yaml config file at init 314 test(tests): add test functions to test YAMLConfig class at init and customization 314 docs(docs): add instructions on how to define yaml config files 314
- Loading branch information
1 parent
57fe0ea
commit c09f377
Showing
9 changed files
with
224 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from pathlib import Path | ||
from typing import Union | ||
|
||
import yaml | ||
|
||
from .base_config import BaseConfig | ||
|
||
|
||
class YAMLConfig(BaseConfig): | ||
def __init__(self, *, data: str, path: Union[Path, str]): | ||
super(YAMLConfig, self).__init__() | ||
self.is_empty_config = False | ||
self._parse_setting(data) | ||
self.add_path(path) | ||
|
||
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): | ||
"""We expect to have a section in cz.yaml looking like | ||
``` | ||
commitizen: | ||
name: cz_conventional_commits | ||
``` | ||
""" | ||
doc = yaml.safe_load(data) | ||
try: | ||
self.settings.update(doc["commitizen"]) | ||
except (KeyError, TypeError): | ||
self.is_empty_config = True | ||
|
||
def set_key(self, key, value): | ||
"""Set or update a key in the conf. | ||
For now only strings are supported. | ||
We use to update the version number. | ||
""" | ||
with open(self.path, "r") as yaml_file: | ||
parser = yaml.load(yaml_file) | ||
|
||
parser["commitizen"][key] = value | ||
with open(self.path, "w") as yaml_file: | ||
yaml.dump(parser, yaml_file) | ||
|
||
return self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.