From 4f694f45c29badf6c40541098930c1441559557b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 13 Nov 2026 10:13:01 -0800 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=94=A7=20build(lint):=20pin=20simplin?= =?UTF-8?q?t=200.12.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9562753..607a83f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -45,7 +45,7 @@ repos: priority: 5 args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"] - repo: https://github.com/gaborbernat/simplint-pre-commit - rev: "5f12b15e1199c42bdeb3e13ea1c8b45952fbd802" # frozen: v0.11.0 + rev: "a12d8eaac290be24041a3e2778c636c56453722e" # frozen: v0.12.2 hooks: - id: simplint priority: 6 From dea689ae1824fdd1ec2632834f28fa4fede88d04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 13 Nov 2026 10:13:01 -0800 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=9A=A8=20fix:=20apply=20simplint=200.?= =?UTF-8?q?12.0=20automatic=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/demo_pkg_inline/build.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/demo_pkg_inline/build.py b/tests/demo_pkg_inline/build.py index 974f5f1..df7ea6e 100644 --- a/tests/demo_pkg_inline/build.py +++ b/tests/demo_pkg_inline/build.py @@ -5,6 +5,7 @@ import tarfile from pathlib import Path from textwrap import dedent +from types import MappingProxyType from typing import Final from zipfile import ZipFile @@ -17,10 +18,10 @@ _METADATA_FILE: Final[str] = f"{_DIST_INFO}/METADATA" _WHEEL: Final[str] = f"{_DIST_INFO}/WHEEL" _RECORD: Final[str] = f"{_DIST_INFO}/RECORD" -_CONTENT: Final[dict[str, str]] = { +_CONTENT: Final[MappingProxyType[str, str]] = MappingProxyType({ _LOGIC: f"def do():\n print('greetings from {_NAME}')", -} -_METADATA: Final[dict[str, str]] = { +}) +_METADATA: Final[MappingProxyType[str, str]] = MappingProxyType({ _METADATA_FILE: f""" Metadata-Version: 2.1 Name: {_PKG_NAME} @@ -48,7 +49,7 @@ {_DIST_INFO}/top_level.txt,, {_DIST_INFO}/RECORD,, """, -} +}) def get_requires_for_build_wheel(config_settings: dict[str, str] | None = None) -> list[str]: # ruff:ignore[unused-function-argument] # the hook signature is fixed by PEP 517 From f07808f93c47ef4183fa6fb093bc867f0c74c98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 13 Nov 2026 12:25:44 -0800 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=94=A7=20build(lint):=20drop=20the=20?= =?UTF-8?q?inline-regex=20Ruff=20ignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 27e814c..9620e62 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -142,7 +142,6 @@ lint.ignore = [ "undocumented-public-init", # undocumented-public-api (simplint) covers the public API instead "undocumented-public-method", # undocumented-public-api (simplint) covers the public API instead "undocumented-public-nested-class", # undocumented-public-api (simplint) covers the public API instead - "unnecessary-regular-expression-compile", # conflicts with simplint inline-regex ] lint.per-file-ignores."src/pyproject_api/_backend.py" = [ "ANN", From 69f24e4e476c3675eda708b2048b5eb1c4b8cdeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Fri, 13 Nov 2026 12:26:11 -0800 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=8E=A8=20style:=20order=20definitions?= =?UTF-8?q?=20below=20their=20users?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pyproject_api/_frontend.py | 342 ++++++++++----------- src/pyproject_api/_via_fresh_subprocess.py | 44 +-- 2 files changed, 193 insertions(+), 193 deletions(-) diff --git a/src/pyproject_api/_frontend.py b/src/pyproject_api/_frontend.py index 0f4ca6a..b71d4f0 100644 --- a/src/pyproject_api/_frontend.py +++ b/src/pyproject_api/_frontend.py @@ -68,170 +68,6 @@ def out_err(self) -> tuple[str, str]: raise NotImplementedError -class RequiresBuildSdistResult(NamedTuple): - """ - Information collected while acquiring the source distribution build dependencies. - - :param requires: source distribution build dependencies - :param out: backend standard output while acquiring the source distribution build dependencies - :param err: backend standard error while acquiring the source distribution build dependencies - """ - - requires: tuple[Requirement, ...] - out: str - err: str - - -class RequiresBuildWheelResult(NamedTuple): - """ - Information collected while acquiring the wheel build dependencies. - - :param requires: wheel build dependencies - :param out: backend standard output while acquiring the wheel build dependencies - :param err: backend standard error while acquiring the wheel build dependencies - """ - - requires: tuple[Requirement, ...] - out: str - err: str - - -class RequiresBuildEditableResult(NamedTuple): - """ - Information collected while acquiring the editable wheel build dependencies. - - :param requires: editable wheel build dependencies - :param out: backend standard output while acquiring the editable wheel build dependencies - :param err: backend standard error while acquiring the editable wheel build dependencies - """ - - requires: tuple[Requirement, ...] - out: str - err: str - - -class MetadataForBuildWheelResult(NamedTuple): - """ - Information collected while acquiring the wheel metadata. - - :param metadata: path to the wheel metadata - :param out: backend standard output while generating the wheel metadata - :param err: backend standard error while generating the wheel metadata - """ - - metadata: Path - out: str - err: str - - -class MetadataForBuildEditableResult(NamedTuple): - """ - Information collected while acquiring the editable metadata. - - :param metadata: path to the wheel metadata - :param out: backend standard output while generating the editable wheel metadata - :param err: backend standard error while generating the editable wheel metadata - """ - - metadata: Path - out: str - err: str - - -class SdistResult(NamedTuple): - """ - Information collected while building a source distribution. - - :param sdist: path to the built source distribution - :param out: backend standard output while building the source distribution - :param err: backend standard error while building the source distribution - """ - - sdist: Path - out: str - err: str - - -class WheelResult(NamedTuple): - """ - Information collected while building a wheel. - - :param wheel: path to the built wheel artifact - :param out: backend standard output while building the wheel - :param err: backend standard error while building the wheel - """ - - wheel: Path - out: str - err: str - - -class EditableResult(NamedTuple): - """ - Information collected while building an editable wheel. - - :param wheel: path to the built wheel artifact - :param out: backend standard output while building the wheel - :param err: backend standard error while building the wheel - """ - - wheel: 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. - - :param result: the backend response, with the ``code``, ``exc_type`` and ``exc_msg`` keys - :param out: standard output collected while running the command - :param err: standard error collected while running the command - """ - - def __init__(self, result: dict[str, Any], out: str, err: str) -> None: - super().__init__() - #: standard output collected while running the command - self.out = out - #: standard error collected while running the command - self.err = err - #: exit code of the command - self.code: int | None = result.get("code", -2) - #: the type of exception thrown - self.exc_type: str = result.get("exc_type", "missing Exception type") - #: 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, 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__ - - def __str__(self) -> str: - return ( - f"packaging backend failed{'' if self.code is None else f' (code={self.code})'}, " - f"with {self.exc_type}: {self.exc_msg}\n{self.err}{self.out}" - ).rstrip() - - def __repr__(self) -> str: - return ( - f"{self.__class__.__name__}(" - f"result=dict(code={self.code}, exc_type={self.exc_type!r},exc_msg={self.exc_msg!r})," - f" out={self.out!r}, err={self.err!r})" - ) - - -class _SendResult(NamedTuple): - value: JsonValue - out: str - err: str - - class Frontend(ABC): """Abstract base class for a pyproject frontend.""" @@ -620,13 +456,6 @@ def _wheel_directory(self) -> Generator[Path, None, None]: # ruff:ignore[no-sel yield Path(wheel_directory) -def _str_list(build_system: dict[str, _TomlValue], key: str) -> list[str]: - if not isinstance(value := build_system[key], list) or not all(isinstance(entry, str) for entry in value): - msg = f"build-system.{key} must be a list of strings, got {value!r}" - raise ValueError(msg) - return value - - def _in_tree_path(folder: Path, entry: str) -> Path: path = folder / entry # Python 3.15 on Windows resolves a path containing NUL instead of raising @@ -640,6 +469,177 @@ def _in_tree_path(folder: Path, entry: str) -> Path: return path +def _str_list(build_system: dict[str, _TomlValue], key: str) -> list[str]: + if not isinstance(value := build_system[key], list) or not all(isinstance(entry, str) for entry in value): + msg = f"build-system.{key} must be a list of strings, got {value!r}" + raise ValueError(msg) + return value + + +class RequiresBuildSdistResult(NamedTuple): + """ + Information collected while acquiring the source distribution build dependencies. + + :param requires: source distribution build dependencies + :param out: backend standard output while acquiring the source distribution build dependencies + :param err: backend standard error while acquiring the source distribution build dependencies + """ + + requires: tuple[Requirement, ...] + out: str + err: str + + +class _SendResult(NamedTuple): + value: JsonValue + 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. + + :param result: the backend response, with the ``code``, ``exc_type`` and ``exc_msg`` keys + :param out: standard output collected while running the command + :param err: standard error collected while running the command + """ + + def __init__(self, result: dict[str, Any], out: str, err: str) -> None: + super().__init__() + #: standard output collected while running the command + self.out = out + #: standard error collected while running the command + self.err = err + #: exit code of the command + self.code: int | None = result.get("code", -2) + #: the type of exception thrown + self.exc_type: str = result.get("exc_type", "missing Exception type") + #: 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, 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__ + + def __str__(self) -> str: + return ( + f"packaging backend failed{'' if self.code is None else f' (code={self.code})'}, " + f"with {self.exc_type}: {self.exc_msg}\n{self.err}{self.out}" + ).rstrip() + + def __repr__(self) -> str: + return ( + f"{self.__class__.__name__}(" + f"result=dict(code={self.code}, exc_type={self.exc_type!r},exc_msg={self.exc_msg!r})," + f" out={self.out!r}, err={self.err!r})" + ) + + +class RequiresBuildWheelResult(NamedTuple): + """ + Information collected while acquiring the wheel build dependencies. + + :param requires: wheel build dependencies + :param out: backend standard output while acquiring the wheel build dependencies + :param err: backend standard error while acquiring the wheel build dependencies + """ + + requires: tuple[Requirement, ...] + out: str + err: str + + +class RequiresBuildEditableResult(NamedTuple): + """ + Information collected while acquiring the editable wheel build dependencies. + + :param requires: editable wheel build dependencies + :param out: backend standard output while acquiring the editable wheel build dependencies + :param err: backend standard error while acquiring the editable wheel build dependencies + """ + + requires: tuple[Requirement, ...] + out: str + err: str + + +class MetadataForBuildWheelResult(NamedTuple): + """ + Information collected while acquiring the wheel metadata. + + :param metadata: path to the wheel metadata + :param out: backend standard output while generating the wheel metadata + :param err: backend standard error while generating the wheel metadata + """ + + metadata: Path + out: str + err: str + + +class MetadataForBuildEditableResult(NamedTuple): + """ + Information collected while acquiring the editable metadata. + + :param metadata: path to the wheel metadata + :param out: backend standard output while generating the editable wheel metadata + :param err: backend standard error while generating the editable wheel metadata + """ + + metadata: Path + out: str + err: str + + +class SdistResult(NamedTuple): + """ + Information collected while building a source distribution. + + :param sdist: path to the built source distribution + :param out: backend standard output while building the source distribution + :param err: backend standard error while building the source distribution + """ + + sdist: Path + out: str + err: str + + +class WheelResult(NamedTuple): + """ + Information collected while building a wheel. + + :param wheel: path to the built wheel artifact + :param out: backend standard output while building the wheel + :param err: backend standard error while building the wheel + """ + + wheel: Path + out: str + err: str + + +class EditableResult(NamedTuple): + """ + Information collected while building an editable wheel. + + :param wheel: path to the built wheel artifact + :param out: backend standard output while building the wheel + :param err: backend standard error while building the wheel + """ + + wheel: Path + out: str + err: str + + __all__ = [ "BackendFailed", "CmdStatus", diff --git a/src/pyproject_api/_via_fresh_subprocess.py b/src/pyproject_api/_via_fresh_subprocess.py index 5b1220b..e8b754a 100644 --- a/src/pyproject_api/_via_fresh_subprocess.py +++ b/src/pyproject_api/_via_fresh_subprocess.py @@ -16,28 +16,6 @@ from packaging.requirements import Requirement -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 - self._msg = msg - self._out_err: tuple[str, str] | None = None - self.start() - - @property - def done(self) -> bool: - # communicate() sets returncode before run() stores what it returned, so a caller polling the process can - # reach out_err() while it still holds None. Free-threaded builds land in that window; report the command - # finished only once its output is actually there. - return self._out_err is not None - - def run(self) -> None: - self._out_err = self.process.communicate(input=self._msg) - - def out_err(self) -> tuple[str, str]: - return cast("tuple[str, str]", self._out_err) - - class SubprocessFrontend(Frontend): """ A frontend that creates fresh subprocess at every call to communicate with the backend. @@ -102,6 +80,28 @@ def send_cmd( return self._send(cmd, **kwargs) +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 + self._msg = msg + self._out_err: tuple[str, str] | None = None + self.start() + + @property + def done(self) -> bool: + # communicate() sets returncode before run() stores what it returned, so a caller polling the process can + # reach out_err() while it still holds None. Free-threaded builds land in that window; report the command + # finished only once its output is actually there. + return self._out_err is not None + + def run(self) -> None: + self._out_err = self.process.communicate(input=self._msg) + + def out_err(self) -> tuple[str, str]: + return cast("tuple[str, str]", self._out_err) + + __all__ = [ "SubprocessFrontend", ]