__init__.py 2.4 KB

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