forked from anntzer/redeal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
93 lines (81 loc) · 3.23 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
from __future__ import division, print_function
# for distutils compatibility we do not use unicode_literals in this module
import contextlib
from distutils.command.build_py import build_py
import io
import os
import shutil
import subprocess
import sys
if sys.version_info < (3,):
from cStringIO import StringIO as BytesIO
from urllib2 import urlopen, URLError
else:
from io import BytesIO
from urllib.request import urlopen, URLError
from zipfile import ZipFile
def _abort(msg):
print(msg, file=sys.stderr)
sys.exit(1)
try:
from setuptools import setup
except ImportError:
_abort("Please install setuptools by following the instructions at\n"
" https://pypi.python.org/pypi/setuptools")
if sys.platform == "win32":
PACKAGE_DATA = ["dds-32.dll", "dds-64.dll"]
else:
# On a POSIX system, libdds.so will be moved to its correct location by
# make_build.
PACKAGE_DATA = []
class make_build(build_py, object):
def run(self):
base_dir = os.path.dirname(os.path.abspath(__file__))
super(make_build, self).run()
if sys.platform.startswith("linux") or sys.platform == "darwin":
orig_dir = os.getcwd()
try:
os.chdir(os.path.join(base_dir, "dds", "src"))
except OSError as exc:
if exc.errno == 2: # FileNotFoundError
_abort("""\
DDS sources are missing.
If you are using a git checkout, run
git submodule init && git submodule update
On a Unix system, do not use the zip archives from github.""")
if sys.platform.startswith("linux"):
subprocess.check_call(
["make", "-f", "Makefiles/Makefile_linux_shared"])
elif sys.platform == "darwin":
with open("Makefiles/Makefile_Mac_clang") as file:
contents = file.read()
contents = contents.replace(
"ar rcs $(STATIC_LIB) $(O_FILES)\n",
"$(CC) -dynamiclib -o lib$(DLLBASE).so $(O_FILES) -lc++\n")
with open("Makefiles/Makefile_Mac_clang_patched", "w") as file:
file.write(contents)
subprocess.check_call(
["make", "-f", "Makefiles/Makefile_Mac_clang_patched",
"CC=gcc"])
os.remove("Makefiles/Makefile_Mac_clang_patched")
os.chdir(orig_dir)
shutil.move(os.path.join(base_dir, "dds", "src", "libdds.so"),
os.path.join(self.build_lib, "redeal", "libdds.so"))
setup(
cmdclass={"build_py": make_build},
name="redeal",
version="0.2.0",
author="Antony Lee",
author_email="anntzer.lee@gmail.com",
packages=["redeal"],
package_data={"redeal": PACKAGE_DATA},
entry_points={"console_scripts": ["redeal = redeal.__main__:console_entry"],
"gui_scripts": ["redeal-gui = redeal.__main__:gui_entry"]},
url="http://github.com/anntzer/redeal",
license="LICENSE.txt",
description="A reimplementation of Thomas Andrews' Deal in Python.",
long_description=io.open("README.rst", encoding="utf-8").read(),
install_requires=
["colorama>=0.2.4"] +
(["enum34>=1.0.4"] if sys.version_info < (3, 4) else [])
)