-
-
Notifications
You must be signed in to change notification settings - Fork 334
Expand file tree
/
Copy pathfactory.py
More file actions
26 lines (19 loc) · 839 Bytes
/
factory.py
File metadata and controls
26 lines (19 loc) · 839 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
from __future__ import annotations
from typing import TYPE_CHECKING
from commitizen.config.json_config import JsonConfig
from commitizen.config.toml_config import TomlConfig
from commitizen.config.yaml_config import YAMLConfig
if TYPE_CHECKING:
from pathlib import Path
from commitizen.config.base_config import BaseConfig
def create_config(*, data: bytes | str | None = None, path: Path) -> BaseConfig:
if "toml" in path.suffix:
return TomlConfig(data=data or "", path=path)
if "json" in path.suffix:
return JsonConfig(data=data or "{}", path=path)
if "yaml" in path.suffix:
return YAMLConfig(data=data or "", path=path)
# Should be unreachable. See the constant CONFIG_FILES.
raise ValueError(
f"Unsupported config file: {path.name} due to unknown file extension"
)