|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -import os |
4 | 3 | from typing import TYPE_CHECKING |
5 | 4 |
|
6 | 5 | from tomlkit import TOMLDocument, exceptions, parse, table |
@@ -28,25 +27,25 @@ def __init__(self, *, data: bytes | str, path: Path) -> None: |
28 | 27 |
|
29 | 28 | def init_empty_config_content(self) -> None: |
30 | 29 | config_doc = TOMLDocument() |
31 | | - if os.path.isfile(self.path): |
32 | | - with open(self.path, "rb") as input_toml_file: |
| 30 | + if self.path.is_file(): |
| 31 | + with self.path.open("rb") as input_toml_file: |
33 | 32 | config_doc = parse(input_toml_file.read()) |
34 | 33 |
|
35 | 34 | if config_doc.get("tool") is None: |
36 | 35 | config_doc["tool"] = table() |
37 | 36 | config_doc["tool"]["commitizen"] = table() # type: ignore[index] |
38 | 37 |
|
39 | | - with open(self.path, "wb") as output_toml_file: |
| 38 | + with self.path.open("wb") as output_toml_file: |
40 | 39 | output_toml_file.write( |
41 | 40 | config_doc.as_string().encode(self._settings["encoding"]) |
42 | 41 | ) |
43 | 42 |
|
44 | 43 | def set_key(self, key: str, value: object) -> Self: |
45 | | - with open(self.path, "rb") as f: |
| 44 | + with self.path.open("rb") as f: |
46 | 45 | config_doc = parse(f.read()) |
47 | 46 |
|
48 | 47 | config_doc["tool"]["commitizen"][key] = value # type: ignore[index] |
49 | | - with open(self.path, "wb") as f: |
| 48 | + with self.path.open("wb") as f: |
50 | 49 | f.write(config_doc.as_string().encode(self._settings["encoding"])) |
51 | 50 |
|
52 | 51 | return self |
|
0 commit comments