File: test_fortran.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 (65 lines) | stat: -rw-r--r-- 1,909 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
import shutil
import sysconfig
import zipfile
from pathlib import Path

import pytest
from packaging.specifiers import SpecifierSet

from scikit_build_core.build import build_wheel
from scikit_build_core.program_search import (
    best_program,
    get_cmake_programs,
    get_ninja_programs,
)

np = pytest.importorskip("numpy")

DIR = Path(__file__).parent.resolve()
FORTRAN_EXAMPLE = DIR / "packages/fortran_example"


cmake_info = best_program(get_cmake_programs(), version=SpecifierSet(">=3.17.2"))
ninja_info = best_program(get_ninja_programs(), version=SpecifierSet(">=1.10"))


@pytest.mark.compile
@pytest.mark.configure
@pytest.mark.fortran
@pytest.mark.network
@pytest.mark.skipif(shutil.which("gfortran") is None, reason="gfortran not available")
@pytest.mark.skipif(
    sysconfig.get_platform().startswith("win"),
    reason="No reasonable Fortran compiler for MSVC",
)
@pytest.mark.skipif(
    cmake_info is None, reason="CMake needs to be 3.17.2+ to support Fortran with Ninja"
)
@pytest.mark.skipif(
    ninja_info is None, reason="Ninja needs to be 1.10+ to support Fortran with CMake"
)
def test_pep517_wheel(tmp_path, monkeypatch, virtualenv):
    dist = tmp_path / "dist"
    monkeypatch.chdir(FORTRAN_EXAMPLE)
    out = build_wheel(str(dist))
    (wheel,) = dist.glob("fibby-0.0.1-*.whl")
    assert wheel == dist / out

    with zipfile.ZipFile(wheel) as zf:
        file_names = {Path(n).parts[0] for n in zf.namelist()}

    assert len(file_names) == 2
    assert "fibby-0.0.1.dist-info" in file_names
    file_names.remove("fibby-0.0.1.dist-info")
    (so_file,) = file_names

    assert so_file.startswith("fibby")
    print("SOFILE:", so_file)

    virtualenv.install(wheel)

    output = virtualenv.execute(
        "import fibby; import numpy as np; a = np.zeros(9); fibby.fib(a); print(a)",
    )

    assert output == str(np.array([0, 1, 1, 2, 3, 5, 8, 13, 21], dtype=float))