Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ Wheel
~~~~~
.. autoclass:: WheelResult

Frontend arguments
~~~~~~~~~~~~~~~~~~
.. autoclass:: FrontendArgs

Built metadata
~~~~~~~~~~~~~~
.. autoclass:: BuiltMetadata

Fresh subprocess frontend
-------------------------
.. autoclass:: SubprocessFrontend
1 change: 1 addition & 0 deletions docs/changelog.d/+restore-tuple-contract.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Restore plain tuple results and public annotations for frontend creation and built metadata.
4 changes: 0 additions & 4 deletions src/pyproject_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

from ._frontend import (
BackendFailed,
BuiltMetadata,
CmdStatus,
EditableResult,
Frontend,
FrontendArgs,
MetadataForBuildEditableResult,
MetadataForBuildWheelResult,
OptionalHooks,
Expand All @@ -24,11 +22,9 @@

__all__ = [
"BackendFailed",
"BuiltMetadata",
"CmdStatus",
"EditableResult",
"Frontend",
"FrontendArgs",
"MetadataForBuildEditableResult",
"MetadataForBuildWheelResult",
"OptionalHooks",
Expand Down
60 changes: 18 additions & 42 deletions src/pyproject_api/_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,40 +180,6 @@ class EditableResult(NamedTuple):
err: str


class FrontendArgs(NamedTuple):
"""
Arguments that create a frontend for a python project folder, to unpack into the frontend's constructor.

:param root: the project root folder
:param backend_paths: paths to provision as available to import from for the build backend
:param backend_module: the module where the backend lives
:param backend_obj: the backend object key, when the ``build-backend`` names one
:param requires: build requirements for the backend
:param reuse_backend: a flag indicating if the communication channel should be kept alive between messages
"""

root: Path
backend_paths: tuple[Path, ...]
backend_module: str
backend_obj: str | None
requires: tuple[Requirement, ...]
reuse_backend: bool


class BuiltMetadata(NamedTuple):
"""
Metadata generated by extracting the ``.dist-info`` directory of a wheel a build produced.

:param metadata: path to the extracted ``.dist-info`` directory
:param out: backend standard output while building the wheel
:param err: backend standard error while building the wheel
"""

metadata: Path
out: str
err: str


class BackendFailed(RuntimeError): # ruff:ignore[error-suffix-on-exception-name] # public exception name, kept for users
"""
An error of the build backend.
Expand All @@ -236,7 +202,13 @@ def __init__(self, result: dict[str, Any], out: str, err: str) -> None:
#: the string representation of the exception thrown
self.exc_msg: str = result.get("exc_msg", "missing Exception message")

def __reduce__(self) -> tuple[type[BackendFailed], tuple[dict[str, JsonValue], str, str], dict[str, JsonValue]]:
def __reduce__(
self,
) -> tuple[
type[BackendFailed],
tuple[dict[str, Any], str, str], # simplint: ignore[imprecise-annotation] # public pickle type
dict[str, Any], # simplint: ignore[imprecise-annotation] # public pickle type
]:
result: dict[str, JsonValue] = {"code": self.code, "exc_type": self.exc_type, "exc_msg": self.exc_msg}
return self.__class__, (result, self.out, self.err), self.__dict__

Expand Down Expand Up @@ -307,7 +279,7 @@ def backend_args(self) -> list[str]:
def create_args_from_folder(
cls,
folder: Path,
) -> FrontendArgs:
) -> tuple[Path, tuple[Path, ...], str, str | None, tuple[Requirement, ...], bool]:
"""
Frontend creation arguments from a python project folder (should have a ``pyproject.toml`` file per PEP-518).

Expand Down Expand Up @@ -352,7 +324,14 @@ def create_args_from_folder(
paths = build_backend.split(":")
backend_module: str = paths[0]
backend_obj: str | None = paths[1] if len(paths) > 1 else None
return FrontendArgs(folder, backend_paths, backend_module, backend_obj, requires, reuse_backend=True)
return ( # simplint: ignore[long-tuple-return] # preserve plain tuple API
folder,
backend_paths,
backend_module,
backend_obj,
requires,
True,
)

def get_requires_for_build_sdist(self, config_settings: ConfigSettings | None = None) -> RequiresBuildSdistResult:
"""
Expand Down Expand Up @@ -601,7 +580,7 @@ def metadata_from_built(
metadata_directory: Path,
target: Literal["wheel", "editable"],
config_settings: ConfigSettings | None = None,
) -> BuiltMetadata:
) -> tuple[Path, str, str]:
"""
Create metadata from building the wheel (use when the prepare endpoints are not present or don't work).

Expand Down Expand Up @@ -633,7 +612,7 @@ def metadata_from_built(
if basename is None: # pragma: no branch # the missing-dist-info arm is covered by a separate test
msg = f"no .dist-info found inside generated wheel {wheel}"
raise RuntimeError(msg)
return BuiltMetadata(metadata_directory / basename, out, err)
return metadata_directory / basename, out, err # simplint: ignore[long-tuple-return] # preserve tuple API

@contextmanager
def _wheel_directory(self) -> Generator[Path, None, None]: # ruff:ignore[no-self-use] # shared with the build helpers that call it
Expand Down Expand Up @@ -663,13 +642,10 @@ def _in_tree_path(folder: Path, entry: str) -> Path:

__all__ = [
"BackendFailed",
"BuiltMetadata",
"CmdStatus",
"ConfigSettings",
"EditableResult",
"Frontend",
"FrontendArgs",
"JsonValue",
"MetadataForBuildEditableResult",
"MetadataForBuildWheelResult",
"OptionalHooks",
Expand Down
4 changes: 1 addition & 3 deletions src/pyproject_api/_via_fresh_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

from packaging.requirements import Requirement

from ._frontend import JsonValue


class SubprocessCmdStatus(CmdStatus, Thread):
def __init__(self, process: Popen[str], msg: str | None = None) -> None:
Expand Down Expand Up @@ -93,7 +91,7 @@ def send_cmd(
self,
cmd: str,
**kwargs: Any, # simplint: ignore[imprecise-annotation] # generic backend command transport
) -> tuple[JsonValue, str, str]:
) -> tuple[Any, str, str]: # simplint: ignore[imprecise-annotation] # public transport type
"""
Send a command to the backend.

Expand Down
21 changes: 10 additions & 11 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,9 @@ def test_metadata_from_built_wheel(
) -> None:
frontend = SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(demo_pkg_inline)[:-1])
monkeypatch.chdir(tmp_path)
path, out, err = frontend.metadata_from_built(tmp_path, target)
result = frontend.metadata_from_built(tmp_path, target)
assert type(result) is tuple
path, out, err = result
assert path == tmp_path / "demo_pkg_inline-1.0.0.dist-info"
assert {p.name for p in path.iterdir()} == {"top_level.txt", "WHEEL", "RECORD", "METADATA"}
assert f" build_{target}" in out
Expand All @@ -672,11 +674,9 @@ def test_metadata_from_built_removes_stale_files(
(metadata / "entry_points.txt").write_text("obsolete entry points")
(tmp_path / "unrelated.txt").write_text("keep")

metadata_path: Final[Path] = (
SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(demo_pkg_inline)[:-1])
.metadata_from_built(tmp_path, target)
.metadata
)
metadata_path, _, _ = SubprocessFrontend(
*SubprocessFrontend.create_args_from_folder(demo_pkg_inline)[:-1]
).metadata_from_built(tmp_path, target)

assert {entry.name for entry in metadata_path.iterdir()} == {"top_level.txt", "WHEEL", "RECORD", "METADATA"}
assert (tmp_path / "unrelated.txt").read_text() == "keep"
Expand All @@ -693,11 +693,9 @@ def test_metadata_from_built_replaces_directory_symlink(
output.mkdir()
(output / "demo_pkg_inline-1.0.0.dist-info").symlink_to(external, target_is_directory=True)

metadata_path: Final[Path] = (
SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(demo_pkg_inline)[:-1])
.metadata_from_built(output, "wheel")
.metadata
)
metadata_path, _, _ = SubprocessFrontend(
*SubprocessFrontend.create_args_from_folder(demo_pkg_inline)[:-1]
).metadata_from_built(output, "wheel")

assert not metadata_path.is_symlink()
assert (metadata_path / "METADATA").is_file()
Expand Down Expand Up @@ -726,6 +724,7 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):

def test_create_no_pyproject(tmp_path: Path) -> None:
result = SubprocessFrontend.create_args_from_folder(tmp_path)
assert type(result) is tuple
assert len(result) == 6
assert (result[0], result[1], result[2], result[3]) == (tmp_path, (), "setuptools.build_meta", "__legacy__")
assert all(isinstance(i, Requirement) for i in result[4])
Expand Down
Loading