1
1
#!/usr/bin/env python
3
3
from setuptools import setup
5
6
from distutils.core import setup
8
from distutils.command.build_py import build_py_2to3 as build_py
10
from distutils.command.build_py import build_py
6
12
from distutils.core import Extension
7
13
from distutils.file_util import copy_file
8
14
from distutils.util import get_platform
13
19
from shutil import copy2
14
20
from subprocess import Popen, PIPE
16
LIBIGRAPH_FALLBACK_INCLUDE_DIRS = ['/usr/include', '/usr/local/include']
22
LIBIGRAPH_FALLBACK_INCLUDE_DIRS = ['/usr/include/igraph', '/usr/local/include/igraph']
17
23
LIBIGRAPH_FALLBACK_LIBRARIES = ['igraph']
18
24
LIBIGRAPH_FALLBACK_LIBRARY_DIRS = []
20
if version_info < (2, 4):
21
print "This module requires Python >= 2.4"
26
if version_info < (2, 5):
27
print("This module requires Python >= 2.5")
24
30
def get_output(command):
25
31
"""Returns the output of a command returning a single line of output"""
26
32
p = Popen(command, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
29
35
line=p.stdout.readline().strip()
30
exit_code=p.stdout.close()
31
return line, exit_code
37
if type(line).__name__ == "bytes":
38
line = str(line, encoding="utf-8")
39
return line, p.returncode
33
41
def detect_igraph_include_dirs(default = LIBIGRAPH_FALLBACK_INCLUDE_DIRS):
34
42
"""Tries to detect the igraph include directory"""
35
43
line, exit_code = get_output("pkg-config igraph --cflags")
36
if exit_code>0 or len(line) == 0: return default
44
if exit_code > 0 or len(line) == 0:
38
return [opt[2:] for opt in opts if opt[0:2]=="-I"]
47
return [opt[2:] for opt in opts if opt.startswith("-I")]
40
49
def detect_igraph_libraries(default = LIBIGRAPH_FALLBACK_LIBRARIES):
41
50
"""Tries to detect the libraries that igraph uses"""
42
51
line, exit_code = get_output("pkg-config igraph --libs")
43
if exit_code>0 or len(line) == 0: return default
52
if exit_code>0 or len(line) == 0:
45
return [opt[2:] for opt in opts if opt[0:2]=="-l"]
55
return [opt[2:] for opt in opts if opt.startswith("-l")]
47
57
def detect_igraph_library_dirs(default = LIBIGRAPH_FALLBACK_LIBRARY_DIRS):
48
58
"""Tries to detect the igraph library directory"""
59
line, exit_code = get_output("pkg-config igraph")
61
print "Using default include and library paths for compilation"
62
print "If the compilation fails, please edit the LIBIGRAPH_FALLBACK_*"
63
print "variables in setup.py or include_dirs and library_dirs in "
64
print "setup.cfg to point to the correct directories and libraries"
65
print "where the C core of igraph is installed"
68
include_dirs.extend(detect_igraph_include_dirs())
69
library_dirs.extend(detect_igraph_library_dirs())
70
libraries.extend(detect_igraph_libraries())
72
print "Include path:", " ".join(include_dirs)
73
print "Library path:", " ".join(library_dirs)
75
igraph_extension = Extension('igraph.core', sources, \
69
if "--no-pkg-config" in argv:
70
argv.remove("--no-pkg-config")
71
libraries.append("igraph")
73
line, exit_code = get_output("pkg-config igraph")
75
print("Using default include and library paths for compilation")
76
print("If the compilation fails, please edit the LIBIGRAPH_FALLBACK_*")
77
print("variables in setup.py or include_dirs and library_dirs in ")
78
print("setup.cfg to point to the correct directories and libraries")
79
print("where the C core of igraph is installed")
82
include_dirs.extend(detect_igraph_include_dirs())
83
library_dirs.extend(detect_igraph_library_dirs())
84
libraries.extend(detect_igraph_libraries())
86
print("Include path: %s" % " ".join(include_dirs))
87
print("Library path: %s" % " ".join(library_dirs))
89
igraph_extension = Extension('igraph._igraph', sources, \
76
90
library_dirs=library_dirs, libraries=libraries, \
77
91
include_dirs=include_dirs)
91
105
so they should work out of the box. Linux users should refer to the
92
106
`igraph homepage <http://igraph.sourceforge.net>`_ for
93
107
compilation instructions (but check your distribution first, maybe
94
there are pre-compiled packages available). OS X Leopard users may
95
benefit from the meta-package in the Python Package Index.
108
there are pre-compiled packages available). OS X Snow Leopard users may
109
benefit from the disk images in the Python Package Index.
111
Unofficial installers for 64-bit Windows machines and/or different Python
112
versions can also be found `here <http://www.lfd.uci.edu/~gohlke/pythonlibs>`_.
113
Many thanks to the maintainers of this page!
98
116
plat = get_platform()
100
118
name = 'python-igraph',
102
120
description = 'High performance graph data structures and algorithms',
103
121
long_description = description,
104
122
license = 'GNU General Public License (GPL)',
109
127
ext_modules = [igraph_extension],
110
128
package_dir = {'igraph': 'igraph'},
111
packages = ['igraph', 'igraph.test', 'igraph.app'],
129
packages = ['igraph', 'igraph.test', 'igraph.app', 'igraph.drawing',
130
'igraph.remote', 'igraph.vendor'],
112
131
scripts = ['scripts/igraph'],
113
132
test_suite = "igraph.test.suite",
134
headers = ['src/igraphmodule_api.h'],
115
136
platforms = 'ALL',
116
137
keywords = ['graph', 'network', 'mathematics', 'math', 'graph theory', 'discrete mathematics'],
133
154
if "macosx" in plat and "bdist_mpkg" in argv:
134
155
# OS X specific stuff to build the .mpkg installer
135
156
options["data_files"] = [ \
136
('/usr/local/lib', [os.path.join('..', '..', 'fatbuild', '.libs', 'libigraph.0.dylib')])
157
('/usr/local/lib', [os.path.join('..', '..', 'fatbuild', 'libigraph.0.dylib')])
160
if version_info > (3, 0):
162
options["use_2to3"] = True
164
options["cmdclass"] = { "build_py": build_py }