Skip to content

Commit

Permalink
PyProjectTOML.file -> PyProjectTOML.path
Browse files Browse the repository at this point in the history
  • Loading branch information
dimbleby authored and radoering committed Apr 3, 2023
1 parent 3469365 commit 4d22b85
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/poetry/core/poetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def pyproject(self) -> PyProjectTOML:

@property
def pyproject_path(self) -> Path:
return self._pyproject.file
return self._pyproject.path

@property
def package(self) -> ProjectPackage:
Expand Down
20 changes: 12 additions & 8 deletions src/poetry/core/pyproject/toml.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
from __future__ import annotations

from contextlib import suppress
from pathlib import Path
from typing import TYPE_CHECKING
from typing import Any

from poetry.core.pyproject.tables import BuildSystem
from poetry.core.utils._compat import tomllib


if TYPE_CHECKING:
from pathlib import Path


class PyProjectTOML:
def __init__(self, path: str | Path) -> None:
self._file = path if isinstance(path, Path) else Path(path)
def __init__(self, path: Path) -> None:
self._file = path
self._data: dict[str, Any] | None = None
self._build_system: BuildSystem | None = None

@property
def file(self) -> Path:
def path(self) -> Path:
return self._file

@property
def data(self) -> dict[str, Any]:
if self._data is None:
if not self.file.exists():
if not self.path.exists():
self._data = {}
else:
with self.file.open("rb") as f:
with self.path.open("rb") as f:
self._data = tomllib.load(f)

return self._data
Expand All @@ -38,7 +42,7 @@ def build_system(self) -> BuildSystem:
build_backend = None
requires = None

if not self.file.exists():
if not self.path.exists():
build_backend = "poetry.core.masonry.api"
requires = ["poetry-core"]

Expand Down Expand Up @@ -68,7 +72,7 @@ def poetry_config(self) -> dict[str, Any]:
def is_poetry_project(self) -> bool:
from poetry.core.pyproject.exceptions import PyProjectException

if self.file.exists():
if self.path.exists():
with suppress(PyProjectException):
_ = self.poetry_config
return True
Expand Down

0 comments on commit 4d22b85

Please sign in to comment.