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
10 changes: 2 additions & 8 deletions src/pyproject_api/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ._frontend import EditableResult, SdistResult, WheelResult


def main_parser() -> argparse.ArgumentParser:
def main_parser() -> argparse.ArgumentParser: # simplint: ignore[unexported-public-name] # CLI parser is internal
parser = argparse.ArgumentParser(
description=(
"A pyproject.toml-based build frontend. "
Expand Down Expand Up @@ -61,7 +61,7 @@ def main_parser() -> argparse.ArgumentParser:
return parser


def main(argv: list[str]) -> None:
def main(argv: list[str]) -> None: # simplint: ignore[unexported-public-name] # CLI entry point is not library API
args = main_parser().parse_args(argv)

outdir = (args.outdir or args.srcdir / "dist").absolute()
Expand Down Expand Up @@ -90,11 +90,5 @@ def main(argv: list[str]) -> None:
print(res.err, file=sys.stderr) # ruff:ignore[print] # CLI output for the user


__all__ = [
"main",
"main_parser", # simplint: ignore[unused-export] # the CLI parser is public API, importable from this module
]


if __name__ == "__main__":
main(sys.argv[1:])
19 changes: 5 additions & 14 deletions src/pyproject_api/_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
import traceback


class MissingCommand(TypeError): # ruff:ignore[error-suffix-on-exception-name] # the frontend reports it by this name
class MissingCommand(TypeError): # ruff:ignore[error-suffix-on-exception-name] # the frontend reports it by this name # simplint: ignore[missing-from-all] # backend-only exception
...


class BackendProxy:
class BackendProxy: # simplint: ignore[missing-from-all] # backend-only proxy
def __init__(self, backend_module, backend_obj):
self.backend_module = backend_module
self.backend_object = backend_obj
Expand Down Expand Up @@ -54,12 +54,12 @@ def _optional_hooks(self):
}


def flush():
def flush(): # simplint: ignore[missing-from-all] # backend-only output helper
sys.stderr.flush()
sys.stdout.flush()


def run(argv):
def run(argv): # simplint: ignore[missing-from-all] # backend script entry point
reuse_process = argv[0].lower() == "true"
try:
backend_proxy = BackendProxy(argv[1], None if len(argv) == 2 else argv[2]) # ruff:ignore[magic-value-comparison] # argv may omit the backend object
Expand Down Expand Up @@ -141,7 +141,7 @@ def _write_response(result_file, result, response):
flush() # pragma: no branch # the finally runs on every path


def read_line(fd=0):
def read_line(fd=0): # simplint: ignore[missing-from-all] # backend-only input helper
# for some reason input() seems to break (hangs forever) so instead we read byte by byte the unbuffered stream
content = bytearray()
while True:
Expand All @@ -158,15 +158,6 @@ def read_line(fd=0):
return content


__all__ = [
"BackendProxy",
"MissingCommand",
"flush",
"read_line",
"run",
]


if __name__ == "__main__":
# printed paths may hold characters the stdout encoding cannot represent
sys.stdout.reconfigure(errors="backslashreplace") # type: ignore[unresolved-attribute] # stub says TextIO
Expand Down
3 changes: 1 addition & 2 deletions src/pyproject_api/_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@


_HERE: Final[Path] = Path(__file__).parent
ConfigSettings = dict[str, Any] | None
ConfigSettings = dict[str, Any] | None # simplint: ignore[missing-from-all] # used only in this module's annotations
# the backend answers over a JSON protocol, so every value it returns is one of these
JsonValue: TypeAlias = str | int | float | bool | list["JsonValue"] | dict[str, "JsonValue"] | None
# tomllib yields these types for every value in a parsed document
Expand Down Expand Up @@ -643,7 +643,6 @@ def _in_tree_path(folder: Path, entry: str) -> Path:
__all__ = [
"BackendFailed",
"CmdStatus",
"ConfigSettings",
"EditableResult",
"Frontend",
"MetadataForBuildEditableResult",
Expand Down
2 changes: 1 addition & 1 deletion src/pyproject_api/_via_fresh_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from packaging.requirements import Requirement


class SubprocessCmdStatus(CmdStatus, Thread):
class SubprocessCmdStatus(CmdStatus, Thread): # simplint: ignore[unexported-public-name] # internal worker status
def __init__(self, process: Popen[str], msg: str | None = None) -> None:
super().__init__()
self.process = process
Expand Down
25 changes: 14 additions & 11 deletions tests/pyproject_api/test_via_fresh_subprocess.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import annotations

import sys
import threading
from subprocess import Popen # ruff:ignore[suspicious-subprocess-import] # inspect the spawned backend
from textwrap import dedent
from typing import TYPE_CHECKING, Final

import pytest

from pyproject_api import SubprocessFrontend
from pyproject_api._via_fresh_subprocess import SubprocessCmdStatus

if TYPE_CHECKING:
from pathlib import Path
Expand Down Expand Up @@ -38,18 +40,19 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
"""),
encoding="utf-8",
)
status_constructor: Final = mocker.spy(SubprocessCmdStatus, "__init__")
process_constructor: Final = mocker.spy(sys.modules[SubprocessFrontend.__module__], "Popen")
mocker.patch("pyproject_api._frontend.sleep", autospec=True, side_effect=error_type("build interrupted"))
threads_before: Final = set(threading.enumerate())

try:
with pytest.raises(error_type):
SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(tmp_path)[:-1]).build_wheel(
tmp_path / "dist"
)
with pytest.raises(error_type):
SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(tmp_path)[:-1]).build_wheel(tmp_path / "dist")

assert not status_constructor.call_args.args[0].is_alive()
process: Final = process_constructor.spy_return
assert isinstance(process, Popen)
try:
assert process.poll() is not None
assert all(thread.daemon for thread in set(threading.enumerate()) - threads_before)
finally:
# A failed cleanup test must not leave a live child process.
status: Final = status_constructor.call_args.args[0]
status.process.kill()
status.join(timeout=10)
process.kill()
process.wait(timeout=10)
Loading