extension.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. from __future__ import division, absolute_import, print_function
  7. import sys
  8. import re
  9. from distutils.extension import Extension as old_Extension
  10. if sys.version_info[0] >= 3:
  11. basestring = str
  12. cxx_ext_re = re.compile(r'.*[.](cpp|cxx|cc)\Z', re.I).match
  13. fortran_pyf_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f|pyf)\Z', re.I).match
  14. class Extension(old_Extension):
  15. def __init__ (
  16. self, name, sources,
  17. include_dirs=None,
  18. define_macros=None,
  19. undef_macros=None,
  20. library_dirs=None,
  21. libraries=None,
  22. runtime_library_dirs=None,
  23. extra_objects=None,
  24. extra_compile_args=None,
  25. extra_link_args=None,
  26. export_symbols=None,
  27. swig_opts=None,
  28. depends=None,
  29. language=None,
  30. f2py_options=None,
  31. module_dirs=None,
  32. extra_f77_compile_args=None,
  33. extra_f90_compile_args=None,):
  34. old_Extension.__init__(
  35. self, name, [],
  36. include_dirs=include_dirs,
  37. define_macros=define_macros,
  38. undef_macros=undef_macros,
  39. library_dirs=library_dirs,
  40. libraries=libraries,
  41. runtime_library_dirs=runtime_library_dirs,
  42. extra_objects=extra_objects,
  43. extra_compile_args=extra_compile_args,
  44. extra_link_args=extra_link_args,
  45. export_symbols=export_symbols)
  46. # Avoid assert statements checking that sources contains strings:
  47. self.sources = sources
  48. # Python 2.4 distutils new features
  49. self.swig_opts = swig_opts or []
  50. # swig_opts is assumed to be a list. Here we handle the case where it
  51. # is specified as a string instead.
  52. if isinstance(self.swig_opts, basestring):
  53. import warnings
  54. msg = "swig_opts is specified as a string instead of a list"
  55. warnings.warn(msg, SyntaxWarning, stacklevel=2)
  56. self.swig_opts = self.swig_opts.split()
  57. # Python 2.3 distutils new features
  58. self.depends = depends or []
  59. self.language = language
  60. # numpy_distutils features
  61. self.f2py_options = f2py_options or []
  62. self.module_dirs = module_dirs or []
  63. self.extra_f77_compile_args = extra_f77_compile_args or []
  64. self.extra_f90_compile_args = extra_f90_compile_args or []
  65. return
  66. def has_cxx_sources(self):
  67. for source in self.sources:
  68. if cxx_ext_re(str(source)):
  69. return True
  70. return False
  71. def has_f2py_sources(self):
  72. for source in self.sources:
  73. if fortran_pyf_ext_re(source):
  74. return True
  75. return False
  76. # class Extension