Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address TODO in pyproject/tables #600

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions src/poetry/core/pyproject/tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from contextlib import suppress
from dataclasses import dataclass
from dataclasses import field
from pathlib import Path
from typing import TYPE_CHECKING

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


# TODO: Convert to dataclass once python 2.7, 3.5 is dropped
@dataclass
class BuildSystem:
def __init__(
self, build_backend: str | None = None, requires: list[str] | None = None
) -> None:
self.build_backend = (
build_backend
if build_backend is not None
else "setuptools.build_meta:__legacy__"
)
self.requires = requires if requires is not None else ["setuptools", "wheel"]
self._dependencies: list[Dependency] | None = None
build_backend: str | None = field(default=None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it is now, I think it's a step backwards compared to the old implementation. build_backend should be of type str even if None can be passed to __init__. IMO, we should find a better solution with dataclasses or keep the old implementation and just remove the TODO.

requires: list[str] = field(default_factory=list)
_dependencies: list[Dependency] | None = field(default=None, init=False)

def __post_init__(self) -> None:
self.build_backend = self.build_backend or "setuptools.build_meta:__legacy__"
self.requires = self.requires or ["setuptools", "wheel"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the old implementation self.requires should only be set to this default if it's None (not if it's an empty list). However, I assume this distinction is not necessary because each build-backend requires at least itself so there is no case where an empty list makes sense.

By the way, we should probably require setuptools >= 40.8.0. I suppose in older versions there is no "setuptools.build_meta:__legacy__", cf build


@property
def dependencies(self) -> list[Dependency]:
Expand All @@ -38,13 +36,10 @@ def dependencies(self) -> list[Dependency]:
except ValueError:
# PEP 517 requires can be path if not PEP 508
path = Path(requirement)
# compatibility Python < 3.8
# https://docs.python.org/3/library/pathlib.html#methods
with suppress(OSError):
if path.is_file():
dependency = FileDependency(name=path.name, path=path)
elif path.is_dir():
dependency = DirectoryDependency(name=path.name, path=path)
if path.is_file():
dependency = FileDependency(name=path.name, path=path)
elif path.is_dir():
dependency = DirectoryDependency(name=path.name, path=path)

if dependency is None:
# skip since we could not determine requirement
Expand Down