File: test_pyproject_extra_dirs.py

package info (click to toggle)
scikit-build-core 0.11.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,408 kB
  • sloc: python: 13,380; ansic: 140; cpp: 134; sh: 27; fortran: 18; makefile: 7
file content (66 lines) | stat: -rw-r--r-- 2,135 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import zipfile
from pathlib import Path

import pytest

from scikit_build_core.build import build_wheel
from scikit_build_core.errors import CMakeConfigError

from pathutils import contained


@pytest.mark.compile
@pytest.mark.configure
@pytest.mark.usefixtures("package_filepath_pure")
def test_pep517_wheel_extra_dirs(monkeypatch, tmp_path: Path):
    monkeypatch.setenv("SKBUILD_CMAKE_DEFINE", "SOME_DEFINE3=baz;SOME_DEFINE4=baz")
    monkeypatch.setenv("SKBUILD_CMAKE_ARGS", "-DSOME_ARGS1=baz")

    dist = tmp_path / "dist"
    out = build_wheel(
        str(dist),
        {"cmake.define.SOME_DEFINE2": "bar", "cmake.define.SOME_DEFINE3": "bar"},
    )
    (wheel,) = dist.glob("cmake_dirs-0.0.1-*.whl")
    assert wheel == dist / out

    with zipfile.ZipFile(wheel) as zf:
        file_paths = {Path(n) for n in zf.namelist()}
    data_paths = set(contained(file_paths, "cmake_dirs-0.0.1.data"))

    file_names = {p.parts[0] for p in file_paths}
    data_dir = {p.parts[0] for p in data_paths}
    package = {p.name for p in contained(file_paths, "cmake_dirs")}
    data = {p.name for p in contained(data_paths, "data")}
    headers = {p.name for p in contained(data_paths, "headers")}
    scripts = {p.name for p in contained(data_paths, "scripts")}

    assert {
        "cmake_dirs-0.0.1.dist-info",
        "cmake_dirs-0.0.1.data",
        "cmake_dirs",
        "random_file.py",
    } == file_names

    assert data_dir == {"data", "headers", "scripts"}

    assert package == {"main.py"}
    assert data == {"in_data.txt"}
    assert headers == {"in_headers.h"}
    assert scripts == {"in_scripts.py"}


@pytest.mark.usefixtures("package_filepath_pure")
def test_pep517_wheel_too_old_core(monkeypatch):
    monkeypatch.setenv("SKBUILD_CMAKE_DEFINE", "SOME_DEFINE3=baz;SOME_DEFINE4=baz")
    monkeypatch.setenv("SKBUILD_CMAKE_ARGS", "-DSOME_ARGS1=baz")

    with pytest.raises(CMakeConfigError):
        build_wheel(
            "dist",
            {
                "cmake.define.SOME_DEFINE2": "bar",
                "cmake.define.SOME_DEFINE3": "bar",
                "minimum-version": "99",
            },
        )