Skip to content

Commit 48ce191

Browse files
authored
refactor: new config system where each config type has its own class
* refactor(config): Make config a class and each type of config (e.g., toml, ini) a child class * Use new config structure to fix the previously fixed Issue #97 * Rename the config inside a config as settings * Use config class as argument for cz and commands instead of dict config * Remove settings from default * fix(config/ini_config): replase outdated _parse_ini_settings with _parse_settings * fix(config): fix load global_conf even if it doesn't exist * refactor(config): move default settings back to defaults * test(all): fix test break due to refactoring note that empty config file is not yet handled. should be fix in next commit * fix(config): handle empty config file * refactor(cz/customize): remove unnecessary statement "raise NotImplementedError("Not Implemented yet")" * refactor(all): replace all the _settings invoke with settings.update * refactor(config): use add_path instead of directly assigning _path
2 parents 5390bc7 + bac6b89 commit 48ce191

25 files changed

+343
-272
lines changed

commitizen/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def main():
155155
out.error("Command is required")
156156
raise SystemExit()
157157

158-
if args.name and not conf["name"]:
158+
if args.name:
159159
conf.update({"name": args.name})
160160

161161
if args.version:

commitizen/commands/bump.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import questionary
44
from packaging.version import Version
55

6-
from commitizen import bump, config, factory, git, out
6+
from commitizen import bump, factory, git, out
7+
from commitizen.config import BaseConfig
78

89
NO_COMMITS_FOUND = 3
910
NO_VERSION_SPECIFIED = 4
@@ -15,11 +16,11 @@
1516
class Bump:
1617
"""Show prompt for the user to create a guided commit."""
1718

18-
def __init__(self, config: dict, arguments: dict):
19-
self.config: dict = config
19+
def __init__(self, config: BaseConfig, arguments: dict):
20+
self.config: BaseConfig = config
2021
self.arguments: dict = arguments
2122
self.parameters: dict = {
22-
**config,
23+
**config.settings,
2324
**{
2425
key: arguments[key]
2526
for key in [
@@ -56,7 +57,7 @@ def find_increment(self, commits: list) -> Optional[str]:
5657
bump_pattern = self.cz.bump_pattern
5758
bump_map = self.cz.bump_map
5859
if not bump_map or not bump_pattern:
59-
out.error(f"'{self.config['name']}' rule does not support bump")
60+
out.error(f"'{self.config.settings['name']}' rule does not support bump")
6061
raise SystemExit(NO_PATTERN_MAP)
6162
increment = bump.find_increment(
6263
commits, regex=bump_pattern, increments_map=bump_map
@@ -74,7 +75,7 @@ def __call__(self):
7475
raise SystemExit(NO_VERSION_SPECIFIED)
7576

7677
# Initialize values from sources (conf)
77-
current_version: str = self.config["version"]
78+
current_version: str = self.config.settings["version"]
7879
tag_format: str = self.parameters["tag_format"]
7980
bump_commit_message: str = self.parameters["bump_message"]
8081
current_tag_version: str = bump.create_tag(
@@ -127,7 +128,7 @@ def __call__(self):
127128
if is_files_only:
128129
raise SystemExit()
129130

130-
config.set_key("version", new_version.public)
131+
self.config.set_key("version", new_version.public)
131132
c = git.commit(message, args="-a")
132133
if c.err:
133134
out.error('git.commit errror: "{}"'.format(c.err.strip()))

commitizen/commands/check.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33

44
from commitizen import factory, out
5+
from commitizen.config import BaseConfig
56

67

78
NO_COMMIT_MSG = 3
@@ -11,19 +12,19 @@
1112
class Check:
1213
"""Check if the current commit msg matches the commitizen format."""
1314

14-
def __init__(self, config: dict, arguments: dict, cwd=os.getcwd()):
15+
def __init__(self, config: BaseConfig, arguments: dict, cwd=os.getcwd()):
1516
"""Init method.
1617
1718
Parameters
1819
----------
19-
config : dict
20+
config : BaseConfig
2021
the config object required for the command to perform its action
2122
arguments : dict
2223
the arguments object that contains all
2324
the flags provided by the user
2425
2526
"""
26-
self.config: dict = config
27+
self.config: BaseConfig = config
2728
self.cz = factory.commiter_factory(self.config)
2829
self.arguments: dict = arguments
2930

commitizen/commands/commit.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from commitizen import factory, git, out
88
from commitizen.cz.exceptions import CzException
9+
from commitizen.config import BaseConfig
10+
911

1012
NO_ANSWERS = 5
1113
COMMIT_ERROR = 6
@@ -17,8 +19,8 @@
1719
class Commit:
1820
"""Show prompt for the user to create a guided commit."""
1921

20-
def __init__(self, config: dict, arguments: dict):
21-
self.config: dict = config
22+
def __init__(self, config: BaseConfig, arguments: dict):
23+
self.config: BaseConfig = config
2224
self.cz = factory.commiter_factory(self.config)
2325
self.arguments = arguments
2426
self.temp_file: str = os.path.join(tempfile.gettempdir(), "cz.commit.backup")

commitizen/commands/example.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from commitizen import factory, out
2+
from commitizen.config import BaseConfig
23

34

45
class Example:
56
"""Show an example so people understands the rules."""
67

7-
def __init__(self, config: dict, *args):
8-
self.config: dict = config
8+
def __init__(self, config: BaseConfig, *args):
9+
self.config: BaseConfig = config
910
self.cz = factory.commiter_factory(self.config)
1011

1112
def __call__(self):

commitizen/commands/info.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from commitizen import factory, out
2+
from commitizen.config import BaseConfig
23

34

45
class Info:
56
"""Show in depth explanation of your rules."""
67

7-
def __init__(self, config: dict, *args):
8-
self.config: dict = config
8+
def __init__(self, config: BaseConfig, *args):
9+
self.config: BaseConfig = config
910
self.cz = factory.commiter_factory(self.config)
1011

1112
def __call__(self):

commitizen/commands/list_cz.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from commitizen import out
22
from commitizen.cz import registry
3+
from commitizen.config import BaseConfig
34

45

56
class ListCz:
67
"""List currently installed rules."""
78

8-
def __init__(self, config: dict, *args):
9-
self.config: dict = config
9+
def __init__(self, config: BaseConfig, *args):
10+
self.config: BaseConfig = config
1011

1112
def __call__(self):
1213
out.write("\n".join(registry.keys()))

commitizen/commands/schema.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from commitizen import factory, out
2+
from commitizen.config import BaseConfig
23

34

45
class Schema:
56
"""Show structure of the rule."""
67

7-
def __init__(self, config: dict, *args):
8-
self.config: dict = config
8+
def __init__(self, config: BaseConfig, *args):
9+
self.config: BaseConfig = config
910
self.cz = factory.commiter_factory(self.config)
1011

1112
def __call__(self):

commitizen/commands/version.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
from commitizen import out
2+
from commitizen.config import BaseConfig
23
from commitizen.__version__ import __version__
34

45

56
class Version:
67
"""Get the version of the installed commitizen."""
78

8-
def __init__(self, config: dict, *args):
9-
self.config: dict = config
9+
def __init__(self, config: BaseConfig, *args):
10+
self.config: BaseConfig = config
1011

1112
def __call__(self):
1213
out.write(__version__)

commitizen/config.py

Lines changed: 0 additions & 162 deletions
This file was deleted.

0 commit comments

Comments
 (0)