~ubuntu-branches/ubuntu/vivid/python-igraph/vivid

« back to all changes in this revision

Viewing changes to setup.py

  • Committer: Package Import Robot
  • Author(s): TANIGUCHI Takaki
  • Date: 2013-06-06 10:57:53 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20130606105753-v39qe4228ni86953
Tags: upstream-0.6.5
ImportĀ upstreamĀ versionĀ 0.6.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
try:
3
3
    from setuptools import setup
 
4
    build_py = None
4
5
except ImportError:
5
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
 
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
15
21
 
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 = []
19
25
 
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")
22
28
    exit(0)
23
 
    
 
29
 
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)
27
33
    p.stdin.close()
28
34
    p.stderr.close()
29
35
    line=p.stdout.readline().strip()
30
 
    exit_code=p.stdout.close()
31
 
    return line, exit_code
 
36
    p.wait()
 
37
    if type(line).__name__ == "bytes":
 
38
        line = str(line, encoding="utf-8")
 
39
    return line, p.returncode
32
40
    
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:
 
45
        return default
37
46
    opts=line.split()
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")]
39
48
 
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:
 
53
        return default
44
54
    opts=line.split()
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")]
46
56
    
47
57
def detect_igraph_library_dirs(default = LIBIGRAPH_FALLBACK_LIBRARY_DIRS):
48
58
    """Tries to detect the igraph library directory"""
56
66
library_dirs=[]
57
67
libraries=[]
58
68
 
59
 
line, exit_code = get_output("pkg-config igraph")
60
 
if exit_code>0:
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"
66
 
    print
67
 
    
68
 
include_dirs.extend(detect_igraph_include_dirs())
69
 
library_dirs.extend(detect_igraph_library_dirs())
70
 
libraries.extend(detect_igraph_libraries())
71
 
 
72
 
print "Include path:", " ".join(include_dirs)
73
 
print "Library path:", " ".join(library_dirs)
74
 
 
75
 
igraph_extension = Extension('igraph.core', sources, \
 
69
if "--no-pkg-config" in argv:
 
70
    argv.remove("--no-pkg-config")
 
71
    libraries.append("igraph")
 
72
else:
 
73
    line, exit_code = get_output("pkg-config igraph")
 
74
    if exit_code>0:
 
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")
 
80
        print("")
 
81
 
 
82
    include_dirs.extend(detect_igraph_include_dirs())
 
83
    library_dirs.extend(detect_igraph_library_dirs())
 
84
    libraries.extend(detect_igraph_libraries())
 
85
 
 
86
print("Include path: %s" % " ".join(include_dirs))
 
87
print("Library path: %s" % " ".join(library_dirs))
 
88
 
 
89
igraph_extension = Extension('igraph._igraph', sources, \
76
90
  library_dirs=library_dirs, libraries=libraries, \
77
91
  include_dirs=include_dirs)
78
92
       
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.
 
110
 
 
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!
96
114
"""
97
115
 
98
116
plat = get_platform()
99
117
options = dict(
100
118
    name = 'python-igraph',
101
 
    version = '0.5.4',
 
119
    version = '0.6.5',
102
120
    description = 'High performance graph data structures and algorithms',
103
121
    long_description = description,
104
122
    license = 'GNU General Public License (GPL)',
108
126
 
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",
114
133
 
 
134
    headers = ['src/igraphmodule_api.h'],
 
135
 
115
136
    platforms = 'ALL',
116
137
    keywords = ['graph', 'network', 'mathematics', 'math', 'graph theory', 'discrete mathematics'],
117
138
    classifiers = [
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')])
137
158
    ]
138
159
 
 
160
if version_info > (3, 0):
 
161
    if build_py is None:
 
162
        options["use_2to3"] = True
 
163
    else:
 
164
        options["cmdclass"] = { "build_py": build_py }
 
165
 
139
166
setup(**options)