PageRenderTime 62ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/py3k/setup.py

https://github.com/ericliang/matplotlib
Python | 296 lines | 273 code | 7 blank | 16 comment | 11 complexity | 084274d3aebc5fcb312331d6e3e63281 MD5 | raw file
  1. """
  2. You will need to have freetype, libpng and zlib installed to comile
  3. matplotlib, inlcuding the *-devel versions of these libraries if you
  4. are using a package manager like RPM or debian.
  5. The matplotlib build options can be modified with a setup.cfg file. See
  6. setup.cfg.template for more information.
  7. """
  8. # distutils is breaking our sdists for files in symlinked dirs.
  9. # distutils will copy if os.link is not available, so this is a hack
  10. # to force copying
  11. import os
  12. try:
  13. del os.link
  14. except AttributeError:
  15. pass
  16. # This dict will be updated as we try to select the best option during
  17. # the build process. However, values in setup.cfg will be used, if
  18. # defined.
  19. rc = {'backend':'Agg'}
  20. # BEFORE importing disutils, remove MANIFEST. distutils doesn't properly
  21. # update it when the contents of directories change.
  22. import os
  23. if os.path.exists('MANIFEST'): os.remove('MANIFEST')
  24. import sys
  25. major, minor1, minor2, s, tmp = sys.version_info
  26. if major==2 and minor1<4 or major<2:
  27. raise SystemExit("""matplotlib requires Python 2.4 or later.""")
  28. import glob
  29. from distutils.core import setup
  30. try:
  31. from distutils.command.build_py import build_py_2to3 as build_py
  32. except ImportError:
  33. from distutils.command.build_py import build_py
  34. from setupext import build_agg, build_gtkagg, build_tkagg, build_wxagg,\
  35. build_macosx, build_ft2font, build_image, build_windowing, build_path, \
  36. build_contour, build_delaunay, build_gdk, \
  37. build_ttconv, print_line, print_status, print_message, \
  38. print_raw, check_for_freetype, check_for_libpng, check_for_gtk, \
  39. check_for_tk, check_for_wx, check_for_macosx, check_for_numpy, \
  40. check_for_qt, check_for_qt4, check_for_cairo, \
  41. check_provide_pytz, check_provide_dateutil,\
  42. check_for_dvipng, check_for_ghostscript, check_for_latex, \
  43. check_for_pdftops, check_for_datetime, options, build_png, build_tri
  44. #import distutils.sysconfig
  45. # jdh
  46. packages = [
  47. 'matplotlib',
  48. 'matplotlib.backends',
  49. 'matplotlib.backends.qt4_editor',
  50. 'matplotlib.projections',
  51. 'matplotlib.testing',
  52. 'matplotlib.testing.jpl_units',
  53. 'matplotlib.tests',
  54. # 'matplotlib.toolkits',
  55. 'mpl_toolkits',
  56. 'mpl_toolkits.mplot3d',
  57. 'mpl_toolkits.axes_grid',
  58. 'mpl_toolkits.axes_grid1',
  59. 'mpl_toolkits.axisartist',
  60. 'matplotlib.sphinxext',
  61. # The following are deprecated and will be removed.
  62. 'matplotlib.numerix',
  63. 'matplotlib.numerix.mlab',
  64. 'matplotlib.numerix.ma',
  65. 'matplotlib.numerix.linear_algebra',
  66. 'matplotlib.numerix.random_array',
  67. 'matplotlib.numerix.fft',
  68. 'matplotlib.tri',
  69. ]
  70. py_modules = ['pylab']
  71. ext_modules = []
  72. for line in open('lib/matplotlib/__init__.py').readlines():
  73. if (line.startswith('__version__')):
  74. exec(line.strip())
  75. print_line()
  76. print_raw("BUILDING MATPLOTLIB")
  77. print_status('matplotlib', __version__)
  78. print_status('python', sys.version)
  79. print_status('platform', sys.platform)
  80. if sys.platform == 'win32':
  81. print_status('Windows version', sys.getwindowsversion())
  82. print_raw("")
  83. print_raw("REQUIRED DEPENDENCIES")
  84. # Specify all the required mpl data
  85. package_data = {'matplotlib':['mpl-data/fonts/afm/*.afm',
  86. 'mpl-data/fonts/pdfcorefonts/*.afm',
  87. 'mpl-data/fonts/pdfcorefonts/*.txt',
  88. 'mpl-data/fonts/ttf/*.ttf',
  89. 'mpl-data/fonts/ttf/LICENSE_STIX',
  90. 'mpl-data/fonts/ttf/COPYRIGHT.TXT',
  91. 'mpl-data/fonts/ttf/README.TXT',
  92. 'mpl-data/fonts/ttf/RELEASENOTES.TXT',
  93. 'mpl-data/images/*.xpm',
  94. 'mpl-data/images/*.svg',
  95. 'mpl-data/images/*.png',
  96. 'mpl-data/images/*.ppm',
  97. 'mpl-data/example/*.npy',
  98. 'mpl-data/matplotlibrc',
  99. 'mpl-data/matplotlib.conf',
  100. 'mpl-data/*.glade',
  101. 'backends/Matplotlib.nib/*',
  102. ]}
  103. if 1:
  104. # TODO: exclude these when making release?
  105. baseline_images = glob.glob(os.path.join('lib','matplotlib','tests',
  106. 'baseline_images','*','*'))
  107. def chop_package(fname):
  108. badstr = os.path.join('lib','matplotlib','')
  109. assert fname.startswith(badstr)
  110. result = fname[ len(badstr): ]
  111. return result
  112. baseline_images = [chop_package(f) for f in baseline_images]
  113. package_data['matplotlib'].extend(baseline_images)
  114. if not check_for_numpy():
  115. sys.exit(1)
  116. if not check_for_freetype():
  117. sys.exit(1)
  118. build_ft2font(ext_modules, packages)
  119. build_ttconv(ext_modules, packages)
  120. build_contour(ext_modules, packages)
  121. build_delaunay(ext_modules, packages)
  122. build_path(ext_modules, packages)
  123. build_tri(ext_modules, packages)
  124. print_raw("")
  125. print_raw("OPTIONAL BACKEND DEPENDENCIES")
  126. has_libpng = check_for_libpng()
  127. if has_libpng and options['build_agg']:
  128. build_agg(ext_modules, packages)
  129. rc['backend'] = 'Agg'
  130. else:
  131. rc['backend'] = 'SVG'
  132. if has_libpng and options['build_image']:
  133. build_image(ext_modules, packages)
  134. if has_libpng and options['build_agg'] or options['build_image']:
  135. build_png(ext_modules, packages)
  136. if options['build_windowing'] and sys.platform=='win32':
  137. build_windowing(ext_modules, packages)
  138. # the options can be True, False, or 'auto'. If True, try to build
  139. # regardless of the lack of dependencies. If auto, silently skip
  140. # when dependencies are missing.
  141. if options['build_tkagg']:
  142. if check_for_tk() or (options['build_tkagg'] is True):
  143. options['build_agg'] = 1
  144. build_tkagg(ext_modules, packages)
  145. rc['backend'] = 'TkAgg'
  146. if options['build_wxagg']:
  147. if check_for_wx() or (options['build_wxagg'] is True):
  148. options['build_agg'] = 1
  149. import wx
  150. if getattr(wx, '__version__', '0.0')[0:3] < '2.8' :
  151. build_wxagg(ext_modules, packages)
  152. wxagg_backend_status = "yes"
  153. else:
  154. print_message("WxAgg extension not required for wxPython >= 2.8")
  155. rc['backend'] = 'WXAgg'
  156. hasgtk = check_for_gtk()
  157. if options['build_gtk']:
  158. if hasgtk or (options['build_gtk'] is True):
  159. build_gdk(ext_modules, packages)
  160. if options['build_gtkagg']:
  161. if hasgtk or (options['build_gtkagg'] is True):
  162. options['build_agg'] = 1
  163. build_gtkagg(ext_modules, packages)
  164. rc['backend'] = 'GTKAgg'
  165. if options['build_macosx']:
  166. if check_for_macosx() or (options['build_macosx'] is True):
  167. build_macosx(ext_modules, packages)
  168. rc['backend'] = 'MacOSX'
  169. # These are informational only. We don't build any extensions for them.
  170. check_for_qt()
  171. check_for_qt4()
  172. check_for_cairo()
  173. print_raw("")
  174. print_raw("OPTIONAL DATE/TIMEZONE DEPENDENCIES")
  175. hasdatetime = check_for_datetime()
  176. provide_dateutil = check_provide_dateutil(hasdatetime)
  177. provide_pytz = check_provide_pytz(hasdatetime)
  178. if hasdatetime: # dates require python23 datetime
  179. # only install pytz and dateutil if the user hasn't got them
  180. def add_pytz():
  181. packages.append('pytz')
  182. resources = ['zone.tab', 'locales/pytz.pot']
  183. for dirpath, dirnames, filenames in os.walk(os.path.join('lib', 'pytz', 'zoneinfo')):
  184. if '.svn' in dirpath: continue
  185. # remove the 'pytz' part of the path
  186. basepath = os.path.join(*dirpath.split(os.path.sep)[2:])
  187. #print dirpath, basepath
  188. resources.extend([os.path.join(basepath, filename)
  189. for filename in filenames])
  190. package_data['pytz'] = resources
  191. #print resources
  192. assert len(resources) > 10, 'zoneinfo files not found!'
  193. def add_dateutil():
  194. packages.append('dateutil')
  195. packages.append('dateutil/zoneinfo')
  196. package_data['dateutil'] = ['zoneinfo/zoneinfo*.tar.*']
  197. if sys.platform=='win32':
  198. # always add these to the win32 installer
  199. add_pytz()
  200. add_dateutil()
  201. else:
  202. # only add them if we need them
  203. if provide_pytz:
  204. add_pytz()
  205. print_raw("adding pytz")
  206. if provide_dateutil: add_dateutil()
  207. print_raw("")
  208. print_raw("OPTIONAL USETEX DEPENDENCIES")
  209. check_for_dvipng()
  210. check_for_ghostscript()
  211. check_for_latex()
  212. check_for_pdftops()
  213. print_raw("")
  214. print_raw("[Edit setup.cfg to suppress the above messages]")
  215. print_line()
  216. # Write the default matplotlibrc file
  217. if options['backend']: rc['backend'] = options['backend']
  218. template = open('matplotlibrc.template').read()
  219. open('lib/matplotlib/mpl-data/matplotlibrc', 'w').write(template%rc)
  220. # Write the default matplotlib.conf file
  221. template = open('lib/matplotlib/mpl-data/matplotlib.conf.template').read()
  222. template = template.replace("datapath = ", "#datapath = ")
  223. template = template.replace(" use = 'Agg'", " use = '%s'"%rc['backend'])
  224. open('lib/matplotlib/mpl-data/matplotlib.conf', 'w').write(template)
  225. try: additional_params # has setupegg.py provided
  226. except NameError: additional_params = {}
  227. for mod in ext_modules:
  228. if options['verbose']:
  229. mod.extra_compile_args.append('-DVERBOSE')
  230. print_raw("pymods %s" % py_modules)
  231. print_raw("packages %s" % packages)
  232. distrib = setup(name="matplotlib",
  233. version= __version__,
  234. description = "Python plotting package",
  235. author = "John D. Hunter",
  236. author_email="jdh2358@gmail.com",
  237. url = "http://matplotlib.sourceforge.net",
  238. long_description = """
  239. matplotlib strives to produce publication quality 2D graphics
  240. for interactive graphing, scientific publishing, user interface
  241. development and web application servers targeting multiple user
  242. interfaces and hardcopy output formats. There is a 'pylab' mode
  243. which emulates matlab graphics
  244. """,
  245. packages = packages,
  246. platforms='any',
  247. py_modules = py_modules,
  248. ext_modules = ext_modules,
  249. package_dir = {'': 'lib'},
  250. package_data = package_data,
  251. cmdclass = {'build_py': build_py},
  252. **additional_params
  253. )