Skip to content

Commit c52556c

Browse files
committed
TYP: stub numpy.f2py
Ported from numpy/numtype#279
1 parent 82610b4 commit c52556c

21 files changed

+1160
-39
lines changed

numpy/f2py/__init__.pyi

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
1-
from _typeshed import StrOrBytesPath
2-
import subprocess
3-
from collections.abc import Iterable
4-
from typing import Literal as L, overload, TypedDict, type_check_only
1+
from .f2py2e import main as main
2+
from .f2py2e import run_main
53

6-
__all__ = ["run_main", "get_include"]
7-
8-
@type_check_only
9-
class _F2PyDictBase(TypedDict):
10-
csrc: list[str]
11-
h: list[str]
12-
13-
@type_check_only
14-
class _F2PyDict(_F2PyDictBase, total=False):
15-
fsrc: list[str]
16-
ltx: list[str]
17-
18-
def run_main(comline_list: Iterable[str]) -> dict[str, _F2PyDict]: ...
19-
20-
@overload
21-
def compile(
22-
source: str | bytes,
23-
modulename: str = ...,
24-
extra_args: str | list[str] = ...,
25-
verbose: bool = ...,
26-
source_fn: StrOrBytesPath | None = ...,
27-
extension: L[".f", ".f90"] = ...,
28-
full_output: L[False] = ...,
29-
) -> int: ...
30-
@overload
31-
def compile(
32-
source: str | bytes,
33-
modulename: str = ...,
34-
extra_args: str | list[str] = ...,
35-
verbose: bool = ...,
36-
source_fn: StrOrBytesPath | None = ...,
37-
extension: L[".f", ".f90"] = ...,
38-
*,
39-
full_output: L[True],
40-
) -> subprocess.CompletedProcess[bytes]: ...
4+
__all__ = ["get_include", "run_main"]
415

426
def get_include() -> str: ...

numpy/f2py/__version__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from numpy.version import version as version

numpy/f2py/_backends/__init__.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from typing import Literal as L
2+
3+
from ._backend import Backend
4+
5+
def f2py_build_generator(name: L["distutils", "meson"]) -> Backend: ...

numpy/f2py/_backends/_backend.pyi

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import abc
2+
from pathlib import Path
3+
from typing import Any, Final
4+
5+
class Backend(abc.ABC):
6+
modulename: Final[str]
7+
sources: Final[list[str | Path]]
8+
extra_objects: Final[list[str]]
9+
build_dir: Final[str | Path]
10+
include_dirs: Final[list[str | Path]]
11+
library_dirs: Final[list[str | Path]]
12+
libraries: Final[list[str]]
13+
define_macros: Final[list[tuple[str, str | None]]]
14+
undef_macros: Final[list[str]]
15+
f2py_flags: Final[list[str]]
16+
sysinfo_flags: Final[list[str]]
17+
fc_flags: Final[list[str]]
18+
flib_flags: Final[list[str]]
19+
setup_flags: Final[list[str]]
20+
remove_build_dir: Final[bool]
21+
extra_dat: Final[dict[str, Any]]
22+
23+
def __init__(
24+
self,
25+
/,
26+
modulename: str,
27+
sources: list[str | Path],
28+
extra_objects: list[str],
29+
build_dir: str | Path,
30+
include_dirs: list[str | Path],
31+
library_dirs: list[str | Path],
32+
libraries: list[str],
33+
define_macros: list[tuple[str, str | None]],
34+
undef_macros: list[str],
35+
f2py_flags: list[str],
36+
sysinfo_flags: list[str],
37+
fc_flags: list[str],
38+
flib_flags: list[str],
39+
setup_flags: list[str],
40+
remove_build_dir: bool,
41+
extra_dat: dict[str, Any],
42+
) -> None: ...
43+
44+
#
45+
@abc.abstractmethod
46+
def compile(self) -> None: ...
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing_extensions import deprecated, override
2+
3+
from ._backend import Backend
4+
5+
class DistutilsBackend(Backend):
6+
@deprecated(
7+
"distutils has been deprecated since NumPy 1.26.x. Use the Meson backend instead, or generate wrappers without -c and "
8+
"use a custom build script"
9+
)
10+
# NOTE: the `sef` typo matches runtime
11+
def __init__(sef, *args: object, **kwargs: object) -> None: ...
12+
@override
13+
def compile(self) -> None: ...

numpy/f2py/_backends/_meson.pyi

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from collections.abc import Callable
2+
from pathlib import Path
3+
from typing import Final
4+
from typing import Literal as L
5+
6+
from typing_extensions import override
7+
8+
from ._backend import Backend
9+
10+
class MesonTemplate:
11+
modulename: Final[str]
12+
build_template_path: Final[Path]
13+
sources: Final[list[str | Path]]
14+
deps: Final[list[str]]
15+
libraries: Final[list[str]]
16+
library_dirs: Final[list[str | Path]]
17+
include_dirs: Final[list[str | Path]]
18+
substitutions: Final[dict[str, str]]
19+
objects: Final[list[str | Path]]
20+
fortran_args: Final[list[str]]
21+
pipeline: Final[list[Callable[[], None]]]
22+
build_type: Final[str]
23+
python_exe: Final[str]
24+
indent: Final[str]
25+
26+
def __init__(
27+
self,
28+
/,
29+
modulename: str,
30+
sources: list[Path],
31+
deps: list[str],
32+
libraries: list[str],
33+
library_dirs: list[str | Path],
34+
include_dirs: list[str | Path],
35+
object_files: list[str | Path],
36+
linker_args: list[str],
37+
fortran_args: list[str],
38+
build_type: str,
39+
python_exe: str,
40+
) -> None: ...
41+
42+
#
43+
def initialize_template(self) -> None: ...
44+
def sources_substitution(self) -> None: ...
45+
def deps_substitution(self) -> None: ...
46+
def libraries_substitution(self) -> None: ...
47+
def include_substitution(self) -> None: ...
48+
def fortran_args_substitution(self) -> None: ...
49+
50+
#
51+
def meson_build_template(self) -> str: ...
52+
def generate_meson_build(self) -> str: ...
53+
54+
class MesonBackend(Backend):
55+
dependencies: list[str]
56+
meson_build_dir: L["bdir"]
57+
build_type: L["debug", "release"]
58+
59+
def __init__(self, /, *args: object, **kwargs: object) -> None: ...
60+
def write_meson_build(self, /, build_dir: Path) -> None: ...
61+
def run_meson(self, /, build_dir: Path) -> None: ...
62+
@override
63+
def compile(self) -> None: ...

numpy/f2py/_isocbind.pyi

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Any, Final
2+
3+
iso_c_binding_map: Final[dict[str, dict[str, str]]] = ...
4+
5+
isoc_c2pycode_map: Final[dict[str, Any]] = {} # not implemented
6+
iso_c2py_map: Final[dict[str, Any]] = {} # not implemented
7+
8+
isoc_kindmap: Final[dict[str, str]] = ...
9+
10+
# namespace pollution
11+
c_type: str
12+
c_type_dict: dict[str, str]
13+
fortran_type: str

numpy/f2py/_src_pyf.pyi

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import re
2+
from collections.abc import Mapping
3+
from typing import Final
4+
5+
from _typeshed import StrOrBytesPath
6+
7+
routine_start_re: Final[re.Pattern[str]] = ...
8+
routine_end_re: Final[re.Pattern[str]] = ...
9+
function_start_re: Final[re.Pattern[str]] = ...
10+
template_re: Final[re.Pattern[str]] = ...
11+
named_re: Final[re.Pattern[str]] = ...
12+
list_re: Final[re.Pattern[str]] = ...
13+
item_re: Final[re.Pattern[str]] = ...
14+
template_name_re: Final[re.Pattern[str]] = ...
15+
include_src_re: Final[re.Pattern[str]] = ...
16+
17+
def parse_structure(astr: str) -> list[tuple[int, int]]: ...
18+
def find_repl_patterns(astr: str) -> dict[str, str]: ...
19+
def find_and_remove_repl_patterns(astr: str) -> tuple[str, dict[str, str]]: ...
20+
def conv(astr: str) -> str: ...
21+
22+
#
23+
def unique_key(adict: Mapping[str, object]) -> str: ...
24+
def expand_sub(substr: str, names: dict[str, str]) -> str: ...
25+
def process_str(allstr: str) -> str: ...
26+
27+
#
28+
def resolve_includes(source: StrOrBytesPath) -> list[str]: ...
29+
def process_file(source: StrOrBytesPath) -> str: ...

0 commit comments

Comments
 (0)