__init__.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 os
  10. import subprocess
  11. import sys
  12. import warnings
  13. from numpy.exceptions import VisibleDeprecationWarning
  14. from . import diagnose, f2py2e
  15. run_main = f2py2e.run_main
  16. main = f2py2e.main
  17. def get_include():
  18. """
  19. Return the directory that contains the ``fortranobject.c`` and ``.h`` files.
  20. .. note::
  21. This function is not needed when building an extension with
  22. `numpy.distutils` directly from ``.f`` and/or ``.pyf`` files
  23. in one go.
  24. Python extension modules built with f2py-generated code need to use
  25. ``fortranobject.c`` as a source file, and include the ``fortranobject.h``
  26. header. This function can be used to obtain the directory containing
  27. both of these files.
  28. Returns
  29. -------
  30. include_path : str
  31. Absolute path to the directory containing ``fortranobject.c`` and
  32. ``fortranobject.h``.
  33. Notes
  34. -----
  35. .. versionadded:: 1.21.1
  36. Unless the build system you are using has specific support for f2py,
  37. building a Python extension using a ``.pyf`` signature file is a two-step
  38. process. For a module ``mymod``:
  39. * Step 1: run ``python -m numpy.f2py mymod.pyf --quiet``. This
  40. generates ``mymodmodule.c`` and (if needed)
  41. ``mymod-f2pywrappers.f`` files next to ``mymod.pyf``.
  42. * Step 2: build your Python extension module. This requires the
  43. following source files:
  44. * ``mymodmodule.c``
  45. * ``mymod-f2pywrappers.f`` (if it was generated in Step 1)
  46. * ``fortranobject.c``
  47. See Also
  48. --------
  49. numpy.get_include : function that returns the numpy include directory
  50. """
  51. return os.path.join(os.path.dirname(__file__), 'src')
  52. def __getattr__(attr):
  53. # Avoid importing things that aren't needed for building
  54. # which might import the main numpy module
  55. if attr == "test":
  56. from numpy._pytesttester import PytestTester
  57. test = PytestTester(__name__)
  58. return test
  59. else:
  60. raise AttributeError(f"module {__name__!r} has no attribute {attr!r}")
  61. def __dir__():
  62. return list(globals().keys() | {"test"})