forked from numenta/nupic-legacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
149 lines (128 loc) · 4.48 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
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
import shutil
import sys
import os
import subprocess
from setuptools import setup
"""
This file only will call CMake process to generate scripts, build, and then
install the NuPIC binaries. ANY EXTRA code related to build process MUST be
put into CMake file.
"""
repositoryDir = os.getcwd()
# Read command line options looking for extra options for CMake and Make
# For example, an user could type:
# python setup.py install make_options="-j3"
# which will add "-j3" option to Make commandline
cmakeOptions = ""
makeOptions = "install"
setupOptions = ""
mustBuildExtensions = False
for arg in sys.argv[:]:
if ("cmake_options" in arg) or ("make_options" in arg):
(option, _, rhs) = arg.partition("=")
if option == "--cmake_options":
cmakeOptions = rhs
sys.argv.remove(arg)
if option == "--make_options":
makeOptions = makeOptions + " " + rhs
sys.argv.remove(arg)
elif not "setup.py" in arg:
if ("build" in arg) or ("install" in arg):
mustBuildExtensions = True
setupOptions += arg + " "
# Check if no option was passed, i.e. if "setup.py" is the only option
# If True, "develop" is passed by default
# This is useful when a developer wish build the project directly from an IDE
if len(sys.argv) == 1:
print "No command passed. Using 'develop' as default command. Use " \
"'python setup.py --help' for more information."
sys.argv.append("develop")
mustBuildExtensions = True
# Get version from local file.
version = None
with open("VERSION", "r") as versionFile:
version = versionFile.read().strip()
def findPackages(repositoryDir):
"""
Traverse nupic directory and create packages for each subdir containing a
__init__.py file
"""
packages = []
for root, _, files in os.walk(repositoryDir + "/nupic"):
if "__init__.py" in files:
subdir = root.replace(repositoryDir + "/", "")
packages.append(subdir.replace("/", "."))
return packages
def buildExtensionsNupic():
"""
CMake-specific build operations
"""
# Prepare directories to the CMake process
sourceDir = repositoryDir
buildScriptsDir = repositoryDir + "/build/scripts"
if os.path.exists(buildScriptsDir):
shutil.rmtree(buildScriptsDir)
os.makedirs(buildScriptsDir)
os.chdir(buildScriptsDir)
# Generate build files with CMake
returnCode = subprocess.call(
"cmake %s %s" % (sourceDir, cmakeOptions), shell=True
)
if returnCode != 0:
sys.exit("Unable to generate build scripts!")
# Build library with Make
returnCode = subprocess.call("make " + makeOptions, shell=True)
if returnCode != 0:
sys.exit("Unable to build the library!")
def setupNupic():
"""
Package setup operations
"""
# Setup library
os.chdir(repositoryDir)
setup(
name = "nupic",
version = version,
packages = findPackages(repositoryDir),
package_data = {
"nupic": ["README.md", "LICENSE.txt",
"CMakeLists.txt", "*.so", "*.dll", "*.dylib"],
"nupic.bindings": ["_*.so", "_*.dll"],
"nupic.data": ["*.json"],
"nupic.frameworks.opf.exp_generator": ["*.json", "*.tpl"],
"nupic.frameworks.opf.jsonschema": ["*.json"],
"nupic.support.resources.images": ["*.png", "*.gif",
"*.ico", "*.graffle"],
"nupic.swarming.jsonschema": ["*.json"]
},
data_files=[
("", [
"CMakeLists.txt",
"config/default/nupic-default.xml"
]
)
],
include_package_data = True,
description = "Numenta Platform for Intelligent Computing",
author="Numenta",
author_email="help@numenta.org",
url="https://github.com/numenta/nupic",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"License :: OSI Approved :: GNU General Public License (GPL)",
"Operating System :: OS Independent",
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Science/Research",
"Topic :: Scientific/Engineering :: Artificial Intelligence"
],
long_description = """\
NuPIC is a library that provides the building blocks for online prediction systems. The library contains the Cortical Learning Algorithm (CLA), but also the Online Prediction Framework (OPF) that allows clients to build prediction systems out of encoders, models, and metrics.
For more information, see numenta.org or the NuPIC wiki (https://github.com/numenta/nupic/wiki).
"""
)
# Build and setup NuPIC
if mustBuildExtensions:
buildExtensionsNupic()
setupNupic()