forked from clab/dynet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
189 lines (165 loc) · 6.67 KB
/
setup.py
File metadata and controls
189 lines (165 loc) · 6.67 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import logging as log
import os
import platform
import sys
from distutils.command.build import build as _build
from distutils.errors import DistutilsSetupError
from distutils.spawn import find_executable
from distutils.sysconfig import get_python_lib
from multiprocessing import cpu_count
from shutil import rmtree
from subprocess import Popen
from setuptools import setup
def run_process(cmds):
p = Popen(cmds)
p.wait()
return p.returncode
log.basicConfig(stream=sys.stdout, level=log.INFO)
# Change the cwd to our source dir
try:
this_file = __file__
except NameError:
this_file = sys.argv[0]
this_file = os.path.abspath(this_file)
if os.path.dirname(this_file):
os.chdir(os.path.dirname(this_file))
script_dir = os.getcwd()
# Clean up temp and package folders
d = os.path.join(script_dir, "build")
if os.path.isdir(d):
log.info("Removing " + d)
rmtree(d)
class build(_build):
def __init__(self, *args, **kwargs):
_build.__init__(self, *args, **kwargs)
self.script_dir = None
self.build_dir = None
self.cmake_path = None
self.make_path = None
self.hg_path = None
self.cxx_path = None
self.cc_path = None
self.install_prefix = None
self.py_executable = None
self.py_version = None
def run(self):
py_executable = sys.executable
py_version = "%s.%s" % (sys.version_info[0], sys.version_info[1])
build_name = "py%s-%s" % (py_version, platform.architecture()[0])
build_dir = os.path.join(script_dir, "build", build_name)
self.script_dir = script_dir
self.build_dir = build_dir
self.cmake_path = os.environ.get("CMAKE", find_executable("cmake"))
if not self.cmake_path:
raise DistutilsSetupError("`cmake` not found, and `CMAKE` is not set.")
self.make_path = os.environ.get("MAKE", find_executable("make"))
if not self.make_path:
raise DistutilsSetupError("`make` not found, and `MAKE` is not set.")
self.make_flags = os.environ.get("MAKE_FLAGS", "-j %d" % cpu_count()).split()
self.hg_path = find_executable("hg")
if not self.hg_path:
raise DistutilsSetupError("`hg` not found.")
self.cc_path = os.environ.get("CC", find_executable("gcc"))
if not self.cc_path:
raise DistutilsSetupError("`gcc` not found, and `CC` is not set.")
self.cxx_path = os.environ.get("CXX", find_executable("g++"))
if not self.cxx_path:
raise DistutilsSetupError("`g++` not found, and `CXX` is not set.")
self.install_prefix = os.path.join(get_python_lib(), os.pardir, os.pardir, os.pardir)
self.py_executable = py_executable
self.py_version = py_version
log.info("=" * 30)
log.info("CMake path: " + self.cmake_path)
log.info("Make path: " + self.make_path)
log.info("Make flags: " + " ".join(self.make_flags))
log.info("Mercurial path: " + self.hg_path)
log.info("C compiler path: " + self.cc_path)
log.info("CXX compiler path: " + self.cxx_path)
log.info("-" * 3)
log.info("Script directory: " + self.script_dir)
log.info("Build directory: " + self.build_dir)
log.info("Library installation directory: " + self.install_prefix)
log.info("Python executable: " + self.py_executable)
log.info("=" * 30)
run_process([self.cmake_path, "--version"])
run_process([self.cxx_path, "--version"])
# Prepare folders
if not os.path.exists(self.build_dir):
log.info("Creating build directory " + self.build_dir)
os.makedirs(self.build_dir)
os.chdir(self.build_dir)
hg_cmd = [self.hg_path, "clone", "https://bitbucket.org/eigen/eigen"]
log.info("Cloning Eigen...")
if run_process(hg_cmd) != 0:
raise DistutilsSetupError(" ".join(hg_cmd))
os.environ["CXX"] = self.cxx_path
os.environ["CC"] = self.cc_path
# Build module
cmake_cmd = [
self.cmake_path,
script_dir,
"-DCMAKE_INSTALL_PREFIX=" + self.install_prefix,
"-DEIGEN3_INCLUDE_DIR=" + os.path.join(self.build_dir, "eigen"),
"-DPYTHON=" + self.py_executable,
]
log.info("Configuring...")
if run_process(cmake_cmd) != 0:
raise DistutilsSetupError(" ".join(cmake_cmd))
make_cmd = [self.make_path] + self.make_flags
log.info("Compiling...")
if run_process(make_cmd) != 0:
raise DistutilsSetupError(" ".join(make_cmd))
make_cmd = [self.make_path, "install"]
log.info("Installing...")
if run_process(make_cmd) != 0:
raise DistutilsSetupError(" ".join(make_cmd))
setup_cmd = [sys.executable, "setup.py", "install"]
log.info("Installing Python modules...")
os.chdir("python")
if run_process(setup_cmd) != 0:
raise DistutilsSetupError(" ".join(setup_cmd))
os.chdir(self.script_dir)
try:
import pypandoc
long_description = pypandoc.convert("README.md", "rst")
except (IOError, ImportError):
long_description = ""
setup(
name="dyNET",
#version="0.0.0",
install_requires=["cython", "numpy"],
description="The Dynamic Neural Network Toolkit",
long_description=long_description,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Environment :: MacOS X",
"Environment :: Win32 (MS Windows)",
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Operating System :: MacOS :: MacOS X",
"Operating System :: POSIX",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft",
"Operating System :: Microsoft :: Windows",
"Programming Language :: C++",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.2",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
author="Graham Neubig",
author_email="dynet-users@googlegroups.com",
url="https://github.com/clab/dynet",
download_url="https://github.com/clab/dynet/releases",
license="Apache 2.0",
cmdclass={"build": build},
)