PageRenderTime 38ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/src/igraph-r2810/interfaces/python/setup.py

https://bitbucket.org/mvngu/suppdycom
Python | 157 lines | 139 code | 13 blank | 5 comment | 19 complexity | 1748e63d1d449d2257a7348d7740c4f3 MD5 | raw file
Possible License(s): LGPL-2.0, 0BSD, GPL-3.0, GPL-2.0, LGPL-2.1
  1. #!/usr/bin/env python
  2. try:
  3. from setuptools import setup
  4. build_py = None
  5. except ImportError:
  6. from distutils.core import setup
  7. try:
  8. from distutils.command.build_py import build_py_2to3 as build_py
  9. except ImportError:
  10. from distutils.command.build_py import build_py
  11. from distutils.core import Extension
  12. from distutils.file_util import copy_file
  13. from distutils.util import get_platform
  14. from sys import argv, version_info, exit
  15. import os.path
  16. import glob
  17. from os import mkdir
  18. from shutil import copy2
  19. from subprocess import Popen, PIPE
  20. LIBIGRAPH_FALLBACK_INCLUDE_DIRS = ['/usr/include', '/usr/local/include']
  21. LIBIGRAPH_FALLBACK_LIBRARIES = ['igraph']
  22. LIBIGRAPH_FALLBACK_LIBRARY_DIRS = []
  23. if version_info < (2, 5):
  24. print("This module requires Python >= 2.5")
  25. exit(0)
  26. def get_output(command):
  27. """Returns the output of a command returning a single line of output"""
  28. p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
  29. p.stdin.close()
  30. p.stderr.close()
  31. line=p.stdout.readline().strip()
  32. p.wait()
  33. if type(line).__name__ == "bytes":
  34. line = str(line, encoding="utf-8")
  35. return line, p.returncode
  36. def detect_igraph_include_dirs(default = LIBIGRAPH_FALLBACK_INCLUDE_DIRS):
  37. """Tries to detect the igraph include directory"""
  38. line, exit_code = get_output("pkg-config igraph --cflags")
  39. if exit_code > 0 or len(line) == 0:
  40. return default
  41. opts=line.split()
  42. return [opt[2:] for opt in opts if opt.startswith("-I")]
  43. def detect_igraph_libraries(default = LIBIGRAPH_FALLBACK_LIBRARIES):
  44. """Tries to detect the libraries that igraph uses"""
  45. line, exit_code = get_output("pkg-config igraph --libs")
  46. if exit_code>0 or len(line) == 0:
  47. return default
  48. opts=line.split()
  49. return [opt[2:] for opt in opts if opt.startswith("-l")]
  50. def detect_igraph_library_dirs(default = LIBIGRAPH_FALLBACK_LIBRARY_DIRS):
  51. """Tries to detect the igraph library directory"""
  52. line, exit_code = get_output("pkg-config igraph --libs")
  53. if exit_code>0 or len(line) == 0: return default
  54. opts=line.split()
  55. return [opt[2:] for opt in opts if opt[0:2]=="-L"]
  56. sources=glob.glob(os.path.join('src', '*.c'))
  57. include_dirs=[]
  58. library_dirs=[]
  59. libraries=[]
  60. line, exit_code = get_output("pkg-config igraph")
  61. if exit_code>0:
  62. print("Using default include and library paths for compilation")
  63. print("If the compilation fails, please edit the LIBIGRAPH_FALLBACK_*")
  64. print("variables in setup.py or include_dirs and library_dirs in ")
  65. print("setup.cfg to point to the correct directories and libraries")
  66. print("where the C core of igraph is installed")
  67. print()
  68. include_dirs.extend(detect_igraph_include_dirs())
  69. library_dirs.extend(detect_igraph_library_dirs())
  70. libraries.extend(detect_igraph_libraries())
  71. print("Include path: %s" % " ".join(include_dirs))
  72. print("Library path: %s" % " ".join(library_dirs))
  73. igraph_extension = Extension('igraph._igraph', sources, \
  74. library_dirs=library_dirs, libraries=libraries, \
  75. include_dirs=include_dirs)
  76. description = """Python interface to the igraph high performance graph
  77. library, primarily aimed at complex network research and analysis.
  78. Graph plotting functionality is provided by the Cairo library, so make
  79. sure you install the Python bindings of Cairo if you want to generate
  80. publication-quality graph plots.
  81. See the `Cairo homepage <http://cairographics.org/pycairo>`_ for details.
  82. From release 0.5, the C core of the igraph library is **not** included
  83. in the Python distribution - you must compile and install the C core
  84. separately. Windows installers already contain a compiled igraph DLL,
  85. so they should work out of the box. Linux users should refer to the
  86. `igraph homepage <http://igraph.sourceforge.net>`_ for
  87. compilation instructions (but check your distribution first, maybe
  88. there are pre-compiled packages available). OS X Snow Leopard users may
  89. benefit from the disk images in the Python Package Index.
  90. """
  91. plat = get_platform()
  92. options = dict(
  93. name = 'python-igraph',
  94. version = '0.6',
  95. description = 'High performance graph data structures and algorithms',
  96. long_description = description,
  97. license = 'GNU General Public License (GPL)',
  98. author = 'Tamas Nepusz',
  99. author_email = 'tamas@cs.rhul.ac.uk',
  100. ext_modules = [igraph_extension],
  101. package_dir = {'igraph': 'igraph'},
  102. packages = ['igraph', 'igraph.test', 'igraph.app', 'igraph.drawing'],
  103. scripts = ['scripts/igraph'],
  104. test_suite = "igraph.test.suite",
  105. headers = ['src/igraphmodule_api.h'],
  106. platforms = 'ALL',
  107. keywords = ['graph', 'network', 'mathematics', 'math', 'graph theory', 'discrete mathematics'],
  108. classifiers = [
  109. 'Development Status :: 4 - Beta',
  110. 'Intended Audience :: Developers',
  111. 'Intended Audience :: Science/Research',
  112. 'Operating System :: OS Independent',
  113. 'Programming Language :: C',
  114. 'Programming Language :: Python',
  115. 'Topic :: Scientific/Engineering',
  116. 'Topic :: Scientific/Engineering :: Information Analysis',
  117. 'Topic :: Scientific/Engineering :: Mathematics',
  118. 'Topic :: Scientific/Engineering :: Physics',
  119. 'Topic :: Scientific/Engineering :: Bio-Informatics',
  120. 'Topic :: Software Development :: Libraries :: Python Modules'
  121. ]
  122. )
  123. if "macosx" in plat and "bdist_mpkg" in argv:
  124. # OS X specific stuff to build the .mpkg installer
  125. options["data_files"] = [ \
  126. ('/usr/local/lib', [os.path.join('..', '..', 'fatbuild', 'libigraph.0.dylib')])
  127. ]
  128. if version_info > (3, 0):
  129. if build_py is None:
  130. options["use_2to3"] = True
  131. else:
  132. options["cmdclass"] = { "build_py": build_py }
  133. setup(**options)