forked from jvkersch/pyconcorde
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
97 lines (84 loc) · 2.78 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import os
from os.path import dirname
from functools import partial
import glob
import setuptools # noqa
from Cython.Build import cythonize
from distutils.core import setup
from distutils.extension import Extension
import numpy as np
def validate_folder(path, required_fnames):
missing = set()
for fname in required_fnames:
f = os.path.isfile(os.path.join(path, fname))
print(os.path.join(path, fname))
if not f:
missing.add(fname)
if missing:
raise RuntimeError("In folder {}: missing {}".format(
path, ', '.join(missing)))
return path
def get_concorde_base_dir():
v = partial(validate_folder,
required_fnames=['concorde.h', 'concorde.a'])
# Environment variable
concorde_dir = os.environ.get('CONCORDE_DIR')
if concorde_dir is not None:
return v(concorde_dir)
# Homebrew
for location in glob.glob("/usr/local/Cellar/concorde/*/lib/concorde.a"):
concorde_dir = dirname(dirname(location))
return v(concorde_dir)
# $HOME/data
concorde_dir = os.path.normpath(os.path.expanduser("~/data"))
if os.path.exists(concorde_dir):
return v(concorde_dir)
# That's it, we're all out of ideas
raise RuntimeError(
"Install Concorde and set the CONCORDE_DIR environment variable "
"to point to the Concorde base folder."
)
def get_qsopt_base_dir():
v = partial(validate_folder,
required_fnames=['qsopt.h', 'qsopt.a'])
# Environment variable
qsopt_dir = os.environ.get('QSOPT_DIR')
if qsopt_dir is not None:
return v(qsopt_dir)
# Homebrew
for location in glob.glob("/usr/local/Cellar/qsopt/*/lib/qsopt.a"):
qsopt_dir = dirname(dirname(location))
return v(qsopt_dir)
# $HOME/data
qsopt_dir = os.path.normpath(os.path.expanduser("~/data"))
if os.path.exists(qsopt_dir):
return v(qsopt_dir)
# That's it, we're all out of ideas
raise RuntimeError(
"Install Qsopt and set the QSOPT_DIR environment variable "
"to point to the Qsopt base folder."
)
CONCORDE_DIR = get_concorde_base_dir()
QSOPT_DIR = get_qsopt_base_dir()
print('CONCORDE_DIR = {}'.format(CONCORDE_DIR))
print('QSOPT_DIR = {}'.format(QSOPT_DIR))
setup(
name='pytsp',
ext_modules=cythonize([
Extension(
'pytsp._concorde',
sources=["pytsp/_concorde.pyx"],
include_dirs=[os.path.join(CONCORDE_DIR, "include"),
np.get_include()],
extra_objects=[
os.path.join(CONCORDE_DIR, "lib", "concorde.a"),
os.path.join(QSOPT_DIR, "lib", "qsopt.a"),
],
)
]),
version='0.1.0',
install_requires=[
'cython>=0.22.0',
'numpy>=1.10.0',
]
)