Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
__init__.py87 linesDownload Raw Back to f2py
1"""Fortran to Python Interface Generator.
2
3Copyright 1999 -- 2011 Pearu Peterson all rights reserved.
4Copyright 2011 -- present NumPy Developers.
5Permission to use, modify, and distribute this software is given under the terms
6of the NumPy License.
7
8NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.
9"""
10__all__ = ['run_main', 'get_include']
11
12import os
13import subprocess
14import sys
15import warnings
16
17from numpy.exceptions import VisibleDeprecationWarning
18
19from . import diagnose, f2py2e
20
21run_main = f2py2e.run_main
22main = f2py2e.main
23
24
25def get_include():
26    """
27    Return the directory that contains the ``fortranobject.c`` and ``.h`` files.
28
29    .. note::
30
31        This function is not needed when building an extension with
32        `numpy.distutils` directly from ``.f`` and/or ``.pyf`` files
33        in one go.
34
35    Python extension modules built with f2py-generated code need to use
36    ``fortranobject.c`` as a source file, and include the ``fortranobject.h``
37    header. This function can be used to obtain the directory containing
38    both of these files.
39
40    Returns
41    -------
42    include_path : str
43        Absolute path to the directory containing ``fortranobject.c`` and
44        ``fortranobject.h``.
45
46    Notes
47    -----
48    .. versionadded:: 1.21.1
49
50    Unless the build system you are using has specific support for f2py,
51    building a Python extension using a ``.pyf`` signature file is a two-step
52    process. For a module ``mymod``:
53
54    * Step 1: run ``python -m numpy.f2py mymod.pyf --quiet``. This
55      generates ``mymodmodule.c`` and (if needed)
56      ``mymod-f2pywrappers.f`` files next to ``mymod.pyf``.
57    * Step 2: build your Python extension module. This requires the
58      following source files:
59
60      * ``mymodmodule.c``
61      * ``mymod-f2pywrappers.f`` (if it was generated in Step 1)
62      * ``fortranobject.c``
63
64    See Also
65    --------
66    numpy.get_include : function that returns the numpy include directory
67
68    """
69    return os.path.join(os.path.dirname(__file__), 'src')
70
71
72def __getattr__(attr):
73
74    # Avoid importing things that aren't needed for building
75    # which might import the main numpy module
76    if attr == "test":
77        from numpy._pytesttester import PytestTester
78        test = PytestTester(__name__)
79        return test
80
81    else:
82        raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")
83
84
85def __dir__():
86    return list(globals().keys() | {"test"})
87 
codekingpro/portable-devtools · Team Ai