extension.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. """distutils.extension
  2. Provides the Extension class, used to describe C/C++ extension
  3. modules in setup scripts.
  4. Overridden to support f2py.
  5. """
  6. import re
  7. from distutils.extension import Extension as old_Extension
  8. cxx_ext_re = re.compile(r'.*\.(cpp|cxx|cc)\Z', re.I).match
  9. fortran_pyf_ext_re = re.compile(r'.*\.(f90|f95|f77|for|ftn|f|pyf)\Z', re.I).match
  10. class Extension(old_Extension):
  11. """
  12. Parameters
  13. ----------
  14. name : str
  15. Extension name.
  16. sources : list of str
  17. List of source file locations relative to the top directory of
  18. the package.
  19. extra_compile_args : list of str
  20. Extra command line arguments to pass to the compiler.
  21. extra_f77_compile_args : list of str
  22. Extra command line arguments to pass to the fortran77 compiler.
  23. extra_f90_compile_args : list of str
  24. Extra command line arguments to pass to the fortran90 compiler.
  25. """
  26. def __init__(
  27. self, name, sources,
  28. include_dirs=None,
  29. define_macros=None,
  30. undef_macros=None,
  31. library_dirs=None,
  32. libraries=None,
  33. runtime_library_dirs=None,
  34. extra_objects=None,
  35. extra_compile_args=None,
  36. extra_link_args=None,
  37. export_symbols=None,
  38. swig_opts=None,
  39. depends=None,
  40. language=None,
  41. f2py_options=None,
  42. module_dirs=None,
  43. extra_f77_compile_args=None,
  44. extra_f90_compile_args=None,):
  45. old_Extension.__init__(
  46. self, name, [],
  47. include_dirs=include_dirs,
  48. define_macros=define_macros,
  49. undef_macros=undef_macros,
  50. library_dirs=library_dirs,
  51. libraries=libraries,
  52. runtime_library_dirs=runtime_library_dirs,
  53. extra_objects=extra_objects,
  54. extra_compile_args=extra_compile_args,
  55. extra_link_args=extra_link_args,
  56. export_symbols=export_symbols)
  57. # Avoid assert statements checking that sources contains strings:
  58. self.sources = sources
  59. # Python 2.4 distutils new features
  60. self.swig_opts = swig_opts or []
  61. # swig_opts is assumed to be a list. Here we handle the case where it
  62. # is specified as a string instead.
  63. if isinstance(self.swig_opts, str):
  64. import warnings
  65. msg = "swig_opts is specified as a string instead of a list"
  66. warnings.warn(msg, SyntaxWarning, stacklevel=2)
  67. self.swig_opts = self.swig_opts.split()
  68. # Python 2.3 distutils new features
  69. self.depends = depends or []
  70. self.language = language
  71. # numpy_distutils features
  72. self.f2py_options = f2py_options or []
  73. self.module_dirs = module_dirs or []
  74. self.extra_f77_compile_args = extra_f77_compile_args or []
  75. self.extra_f90_compile_args = extra_f90_compile_args or []
  76. return
  77. def has_cxx_sources(self):
  78. for source in self.sources:
  79. if cxx_ext_re(str(source)):
  80. return True
  81. return False
  82. def has_f2py_sources(self):
  83. for source in self.sources:
  84. if fortran_pyf_ext_re(source):
  85. return True
  86. return False
  87. # class Extension