-
Notifications
You must be signed in to change notification settings - Fork 109
/
setup.py
85 lines (73 loc) · 2.65 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
import sys
import os
import platform
import distutils.file_util
from setuptools import setup
from Cython.Build import cythonize
# Output annotated .html
import Cython.Compiler.Options
Cython.Compiler.Options.annotate = True
modules_map = {
"png": {"source": "cpngfilters.pyx",
"description": "Build the accelerator to work with PNG images."},
"nbt": {"source": "pymclevel/_nbt.pyx",
"description": "Build the accelerator to work with NBT data."}
}
__help__ = """setup.py
Build Cython extensions for MCEdit-Unified.
You have to use at least one argument on the command line to build extensions.
Valid arguments are:
help Print this message.
all Build all extensions.
%s
-- Makes this script send all remaing arguments to setuptool.
In case setuptools commands like 'build' or 'install are given after a doule
dash ('--'), you can expect unwanted behaviour, because the 'build_ext' and
'--inplace' are forced (added dynamicaly on the command line).
""" % "\n".join(["%s %s" % (k, v["description"]) for k, v in modules_map.items()])
# Let people choose what to build.
# If no argument is given on the command line, display help message.
# If a wrong argument is given, break.
if len(sys.argv) == 1:
print __help__
sys.exit(0)
else:
ext_modules = []
args = sys.argv[1:]
msg = "Following extensions will be built: %s."
ext_list = []
for arg in args:
# Let send setuptools argument be on the command line.
print arg
if arg == '--':
sys.argv.remove(arg)
break
if not arg.startswith('-'):
if arg == 'help':
print __help__
sys.exit(0)
elif arg == 'all':
ext_list = list(modules_map.keys())
ext_modules = [v["source"] for v in modules_map.values()]
elif arg not in modules_map.keys():
print "'%s' is not a valid argument. Use 'help' one for information." % arg
sys.exit(1)
else:
src = modules_map[arg]["source"]
if src not in ext_modules:
ext_list.append(arg)
ext_modules.append(src)
sys.argv.remove(arg)
print msg % ", ".join(ext_list)
sys.argv.insert(1, '--inplace')
sys.argv.insert(1, 'build_ext')
setup(
ext_modules=cythonize(ext_modules)
)
# On Linux, we want _nbt.so in pymclevel.
if platform.system() == "Linux":
if os.path.isfile("_nbt.so"):
nbt_dest = os.path.join("pymclevel", "_nbt.so")
if os.path.isfile(nbt_dest):
os.remove(nbt_dest)
distutils.file_util.move_file("_nbt.so", nbt_dest)