|
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 |
@@ -33,25 +32,25 @@ def contains_commitizen_section(self) -> bool: |
33 | 32 |
|
34 | 33 | def init_empty_config_content(self) -> None: |
35 | 34 | config_doc = TOMLDocument() |
36 | | - if os.path.isfile(self.path): |
37 | | - with open(self.path, "rb") as input_toml_file: |
| 35 | + if self.path.is_file(): |
| 36 | + with self.path.open("rb") as input_toml_file: |
38 | 37 | config_doc = parse(input_toml_file.read()) |
39 | 38 |
|
40 | 39 | if config_doc.get("tool") is None: |
41 | 40 | config_doc["tool"] = table() |
42 | 41 | config_doc["tool"]["commitizen"] = table() # type: ignore[index] |
43 | 42 |
|
44 | | - with open(self.path, "wb") as output_toml_file: |
| 43 | + with self.path.open("wb") as output_toml_file: |
45 | 44 | output_toml_file.write( |
46 | 45 | config_doc.as_string().encode(self._settings["encoding"]) |
47 | 46 | ) |
48 | 47 |
|
49 | 48 | def set_key(self, key: str, value: object) -> Self: |
50 | | - with open(self.path, "rb") as f: |
| 49 | + with self.path.open("rb") as f: |
51 | 50 | config_doc = parse(f.read()) |
52 | 51 |
|
53 | 52 | config_doc["tool"]["commitizen"][key] = value # type: ignore[index] |
54 | | - with open(self.path, "wb") as f: |
| 53 | + with self.path.open("wb") as f: |
55 | 54 | f.write(config_doc.as_string().encode(self._settings["encoding"])) |
56 | 55 |
|
57 | 56 | return self |
|
0 commit comments