-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
71 lines (56 loc) · 2 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
"""
This builds plumage (in a hacky way to not require autotools).
Taken from tkinter-polo repo.
"""
import os
import sys
import subprocess
from distutils.core import setup, Extension
SRCDIR = "src"
TESTDIR = "test"
class MissingTclTkConfig(EnvironmentError):
pass
def get_paths(path, prefix):
bash = subprocess.Popen(['bash'], stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
bash.stdin.write("source %s\n" % path)
for name in ("%s_LIB_SPEC", "%s_INCLUDE_SPEC"):
bash.stdin.write('echo `eval echo $%s`\n' % (name % prefix))
result = bash.communicate()[0].strip().split('\n')
if not result[0]:
raise MissingTclTkConfig("'%s' did not contain a (correct) '%s'" %
(os.path.dirname(path), "%sConfig.sh" % prefix.lower()))
libs = result[0].split()
yield libs[1][2:]
yield libs[0][2:]
yield result[1][2:]
def get_tcltk_paths():
tclconfig = os.environ.get('TCL_CONFIG')
tkconfig = os.environ.get('TK_CONFIG')
if not all((tclconfig, tkconfig)):
raise MissingTclTkConfig("TCL_CONFIG and TK_CONFIG env vars must "
"exist and should point to tclConfig.sh and tkConfig.sh ")
paths = zip(get_paths(tclconfig, 'TCL'), get_paths(tkconfig, 'TK'))
return dict(zip(('libraries', 'library_dirs', 'include_dirs'), paths))
def main(args):
if not len(args) or args[0].startswith('-'):
tcltk_paths = {}
else:
tcltk_paths = get_tcltk_paths()
c_tcltk_paths = tcltk_paths
c_tcltk_paths['include_dirs'] += (SRCDIR, )
setup(name="plumage",
ext_modules=[
Extension("plumage",
[os.path.join(SRCDIR, "plumage.c"),
os.path.join(SRCDIR, "utils.c")],
**tcltk_paths),
# C test
Extension("_utils_bridge",
[os.path.join(TESTDIR, "_utils_bridge.c"),
os.path.join(SRCDIR, "utils.c")],
**c_tcltk_paths),
]
)
if __name__ == "__main__":
main(sys.argv[1:])