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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ repos:
priority: 4
files: ^src/pyproject_api/
- repo: https://github.com/gaborbernat/simplint-pre-commit
rev: "a12d8eaac290be24041a3e2778c636c56453722e" # frozen: v0.12.2
rev: "6f12a88d7d6ebf3dd09ebddb1e6541e533d4efe0" # frozen: v0.14.2
hooks:
- id: simplint
priority: 6
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 @@ -61,7 +61,7 @@ def _send_msg(self, cmd: str, result_file: Path, msg: str) -> Generator[Subproce
cwd=self._root,
env=env,
)
status: Final = SubprocessCmdStatus(process, f"{os.linesep}{msg}{os.linesep}")
status: Final[SubprocessCmdStatus] = SubprocessCmdStatus(process, f"{os.linesep}{msg}{os.linesep}")
try:
yield status
finally:
Expand Down
4 changes: 3 additions & 1 deletion tests/pyproject_api/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

import pytest_mock

from pyproject_api import SdistResult


def test_invalid_module(capsys: pytest.CaptureFixture[str]) -> None:
with pytest.raises(ImportError):
Expand Down Expand Up @@ -230,6 +232,6 @@ def test_backend_output_with_unencodable_path(tmp_path: Path, monkeypatch: pytes
root.mkdir()
(root / "build_tester.py").write_text("def build_sdist(sdist_directory, config_settings=None): return 'out.tar.gz'")

result: Final = SubprocessFrontend(root, (root,), "build_tester", None, ()).build_sdist(root / "dist")
result: Final[SdistResult] = SubprocessFrontend(root, (root,), "build_tester", None, ()).build_sdist(root / "dist")

assert (result.sdist, "pr\\xf6ject" in result.out) == (root / "dist" / "out.tar.gz", True)
16 changes: 9 additions & 7 deletions tests/pyproject_api/test_via_fresh_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import pytest_mock

from pyproject_api import SdistResult


@pytest.mark.parametrize(
"error_type",
Expand All @@ -40,14 +42,14 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):
"""),
encoding="utf-8",
)
process_constructor: Final = mocker.spy(sys.modules[SubprocessFrontend.__module__], "Popen")
process_constructor: Final[pytest_mock.SpyType] = 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())
threads_before: Final[set[threading.Thread]] = set(threading.enumerate())

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

process: Final = process_constructor.spy_return
process: Final[Popen[str]] = process_constructor.spy_return
assert isinstance(process, Popen)
try:
assert process.poll() is not None
Expand All @@ -59,12 +61,12 @@ def build_wheel(wheel_directory, config_settings=None, metadata_directory=None):


def test_backend_path_keeps_existing_pythonpath(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
deps: Final = tmp_path / "deps"
deps: Final[Path] = tmp_path / "deps"
deps.mkdir()
(deps / "helper.py").write_text('NAME = "demo-1.0.tar.gz"\n', encoding="utf-8")
# same name as the in-tree backend, so it would shadow it if PYTHONPATH came before backend-path
(deps / "build_tester.py").write_text('raise ImportError("PYTHONPATH shadowed backend-path")\n', encoding="utf-8")
project: Final = tmp_path / "project"
project: Final[Path] = tmp_path / "project"
(project / "_build").mkdir(parents=True)
(project / "pyproject.toml").write_text(
'[build-system]\nrequires=[]\nbuild-backend = "build_tester"\nbackend-path=["_build"]', encoding="utf-8"
Expand All @@ -80,7 +82,7 @@ def build_sdist(sdist_directory, config_settings=None):
)
monkeypatch.setenv("PYTHONPATH", str(deps))

frontend: Final = SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(project)[:-1])
result: Final = frontend.build_sdist(tmp_path / "dist")
frontend: Final[SubprocessFrontend] = SubprocessFrontend(*SubprocessFrontend.create_args_from_folder(project)[:-1])
result: Final[SdistResult] = frontend.build_sdist(tmp_path / "dist")

assert result.sdist == tmp_path / "dist" / "demo-1.0.tar.gz"
4 changes: 2 additions & 2 deletions tests/test_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def get_requires_for_build_wheel(config_settings=None):

@pytest.mark.skipif(sys.platform == "win32", reason="Windows drops trailing spaces from names")
def test_backend_path_with_trailing_space(tmp_path: Path) -> None: # pragma: win32 no cover
backend: Final = tmp_path / "backend "
backend: Final[Path] = tmp_path / "backend "
backend.mkdir()
(backend / "build_tester.py").write_text(
"def get_requires_for_build_wheel(config_settings=None):\n return ['wheel']\n"
)
frontend: Final = SubprocessFrontend(tmp_path, (backend,), "build_tester", None, ())
frontend: Final[SubprocessFrontend] = SubprocessFrontend(tmp_path, (backend,), "build_tester", None, ())

assert frontend.get_requires_for_build_wheel().requires == (Requirement("wheel"),)

Expand Down
Loading