Skip to content

Commit 7d6d78e

Browse files
committed
refactor(BaseConfig): rename function
1 parent e3b4465 commit 7d6d78e

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

commitizen/config/base_config.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ def settings(self) -> Settings:
1919
def path(self) -> Path | None:
2020
return self._path
2121

22+
"""
23+
mypy does not like the following until 1.16
24+
See https://github.com/python/mypy/pull/18510
25+
TODO: update this when 1.16 is available
26+
27+
@path.setter
28+
def path(self, path: str | Path) -> None:
29+
self._path = Path(path)
30+
"""
31+
32+
def update_path(self, path: str | Path) -> None:
33+
self._path = Path(path)
34+
2235
def set_key(self, key, value):
2336
"""Set or update a key in the conf.
2437
@@ -30,8 +43,5 @@ def set_key(self, key, value):
3043
def update(self, data: Settings) -> None:
3144
self._settings.update(data)
3245

33-
def add_path(self, path: str | Path) -> None:
34-
self._path = Path(path)
35-
3646
def _parse_setting(self, data: bytes | str) -> None:
3747
raise NotImplementedError()

commitizen/config/json_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class JsonConfig(BaseConfig):
1313
def __init__(self, *, data: bytes | str, path: Path | str):
1414
super().__init__()
1515
self.is_empty_config = False
16-
self.add_path(path)
16+
self.update_path(path)
1717
self._parse_setting(data)
1818

1919
def init_empty_config_content(self):

commitizen/config/toml_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TomlConfig(BaseConfig):
1414
def __init__(self, *, data: bytes | str, path: Path | str):
1515
super().__init__()
1616
self.is_empty_config = False
17-
self.add_path(path)
17+
self.update_path(path)
1818
self._parse_setting(data)
1919

2020
def init_empty_config_content(self):

commitizen/config/yaml_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class YAMLConfig(BaseConfig):
1414
def __init__(self, *, data: bytes | str, path: Path | str):
1515
super().__init__()
1616
self.is_empty_config = False
17-
self.add_path(path)
17+
self.update_path(path)
1818
self._parse_setting(data)
1919

2020
def init_empty_config_content(self):

tests/commands/test_init_command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import os
55
import sys
6+
from pathlib import Path
67
from typing import Any
78

89
import pytest
@@ -86,7 +87,7 @@ def test_init_without_setup_pre_commit_hook(tmpdir, mocker: MockFixture, config)
8687
def test_init_when_config_already_exists(config, capsys):
8788
# Set config path
8889
path = os.sep.join(["tests", "pyproject.toml"])
89-
config.add_path(path)
90+
config.path = Path(path)
9091

9192
commands.Init(config)()
9293
captured = capsys.readouterr()

0 commit comments

Comments
 (0)