Skip to content

Commit 1a31a42

Browse files
committed
Address TODO in pyproject/tables
1 parent 071fc66 commit 1a31a42

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

src/poetry/core/pyproject/tables.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

3-
from contextlib import suppress
3+
from dataclasses import dataclass
4+
from dataclasses import field
45
from pathlib import Path
56
from typing import TYPE_CHECKING
67

@@ -9,18 +10,15 @@
910
from poetry.core.packages.dependency import Dependency
1011

1112

12-
# TODO: Convert to dataclass once python 2.7, 3.5 is dropped
13+
@dataclass
1314
class BuildSystem:
14-
def __init__(
15-
self, build_backend: str | None = None, requires: list[str] | None = None
16-
) -> None:
17-
self.build_backend = (
18-
build_backend
19-
if build_backend is not None
20-
else "setuptools.build_meta:__legacy__"
21-
)
22-
self.requires = requires if requires is not None else ["setuptools", "wheel"]
23-
self._dependencies: list[Dependency] | None = None
15+
build_backend: str | None = field(default=None)
16+
requires: list[str] = field(default_factory=list)
17+
_dependencies: list[Dependency] | None = field(default=None, init=False)
18+
19+
def __post_init__(self) -> None:
20+
self.build_backend = self.build_backend or "setuptools.build_meta:__legacy__"
21+
self.requires = self.requires or ["setuptools", "wheel"]
2422

2523
@property
2624
def dependencies(self) -> list[Dependency]:
@@ -38,13 +36,10 @@ def dependencies(self) -> list[Dependency]:
3836
except ValueError:
3937
# PEP 517 requires can be path if not PEP 508
4038
path = Path(requirement)
41-
# compatibility Python < 3.8
42-
# https://docs.python.org/3/library/pathlib.html#methods
43-
with suppress(OSError):
44-
if path.is_file():
45-
dependency = FileDependency(name=path.name, path=path)
46-
elif path.is_dir():
47-
dependency = DirectoryDependency(name=path.name, path=path)
39+
if path.is_file():
40+
dependency = FileDependency(name=path.name, path=path)
41+
elif path.is_dir():
42+
dependency = DirectoryDependency(name=path.name, path=path)
4843

4944
if dependency is None:
5045
# skip since we could not determine requirement

0 commit comments

Comments
 (0)