1
1
from __future__ import annotations
2
2
3
3
from contextlib import suppress
4
- from pathlib import Path
4
+ from typing import TYPE_CHECKING
5
5
from typing import Any
6
6
7
7
from poetry .core .pyproject .tables import BuildSystem
8
8
from poetry .core .utils ._compat import tomllib
9
9
10
10
11
+ if TYPE_CHECKING :
12
+ from pathlib import Path
13
+
14
+
11
15
class PyProjectTOML :
12
- def __init__ (self , path : str | Path ) -> None :
13
- self ._file = path if isinstance ( path , Path ) else Path ( path )
16
+ def __init__ (self , path : Path ) -> None :
17
+ self ._file = path
14
18
self ._data : dict [str , Any ] | None = None
15
19
self ._build_system : BuildSystem | None = None
16
20
17
21
@property
18
- def file (self ) -> Path :
22
+ def path (self ) -> Path :
19
23
return self ._file
20
24
21
25
@property
22
26
def data (self ) -> dict [str , Any ]:
23
27
if self ._data is None :
24
- if not self .file .exists ():
28
+ if not self .path .exists ():
25
29
self ._data = {}
26
30
else :
27
- with self .file .open ("rb" ) as f :
31
+ with self .path .open ("rb" ) as f :
28
32
self ._data = tomllib .load (f )
29
33
30
34
return self ._data
@@ -38,7 +42,7 @@ def build_system(self) -> BuildSystem:
38
42
build_backend = None
39
43
requires = None
40
44
41
- if not self .file .exists ():
45
+ if not self .path .exists ():
42
46
build_backend = "poetry.core.masonry.api"
43
47
requires = ["poetry-core" ]
44
48
@@ -68,7 +72,7 @@ def poetry_config(self) -> dict[str, Any]:
68
72
def is_poetry_project (self ) -> bool :
69
73
from poetry .core .pyproject .exceptions import PyProjectException
70
74
71
- if self .file .exists ():
75
+ if self .path .exists ():
72
76
with suppress (PyProjectException ):
73
77
_ = self .poetry_config
74
78
return True
0 commit comments