-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
183 lines (141 loc) · 5.33 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
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
''' '''
'''
ISC License
Copyright (c) 2016, Autonomous Vehicle Systems Lab, University of Colorado at Boulder
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
'''
import os
import sys
from setuptools import Command, setup
from setuptools.command.test import test as TestCommand
# Just a function to run a command
verbose = False
def runCommand(cmd, dir=None):
if not verbose:
cmd += "> /dev/null"
print("Running command:", cmd)
originalDir = os.getcwd()
if dir is not None:
os.chdir(dir)
os.system(cmd)
os.chdir(originalDir)
else:
os.system(cmd)
class PyTestCommand(TestCommand):
# Here we define a command to use for testing installed Basilisk
# Taken from pytest documentation found https://docs.pytest.org/en/latest/goodpractices.html
description = "Custom test command that runs pytest"
user_options = [('pytest-args=', 'a', "Arguments to pass to pytest")]
def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = ''
def run_tests(self):
import shlex
# import here, cause outside the eggs aren't loaded
import pytest
errno = pytest.main(['src'] + shlex.split(self.pytest_args))
sys.exit(errno)
class CleanCommand(Command):
# Custom command to clean up
description = "Custom clean command that removes dist3/build and artifacts"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
to_delete = [
"dist3/",
"docs/build",
"docs/source/_images/Scenarios"
]
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
runCommand('rm -rf ' + " ".join(to_delete))
class CMakeBuildCommand(Command):
# Custom command to build with cmake and xcode
description = "Custom build command that runs CMake"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
print("Making distribution directory")
runCommand("mkdir dist3/")
print("Executing CMake build into dist3/ directory")
# if we switch to using mostly setup.py for the build, install will not be done by CMake
print("This also will install Basilisk locally...")
runCommand("cmake -G Xcode ../src/", "dist3/")
class XCodeBuildCommand(Command):
description = "Custom build command that runs XCode"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
print("Executing XCode build into dist3/ directory")
runCommand("xcodebuild -project dist3/basilisk.xcodeproj -target ALL_BUILD")
# Lint command
class LintCommand(Command):
description = "Custom lint command that displays pep8 violations"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
print("Executing linter")
runCommand("flake8 src/")
class BuildDocsCommand(Command):
# Custom command to build with cmake and xcode
description = "Custom build command to build the documentation with doxygen"
user_options = []
def initialize_options(self):
self.cwd = None
def finalize_options(self):
self.cwd = os.getcwd()
def run(self):
assert os.getcwd() == self.cwd, 'Must be in package root: %s' % self.cwd
print("Building documentation")
runCommand("make html", "docs/source")
package_dir = "dist3"
f = open('docs/source/bskVersion.txt', 'r')
bskVersion = f.read().strip()
setup(
name='Basilisk',
version=bskVersion,
description="Astrodynamics Simulation Library",
packages=['Basilisk', ],
license=open('./LICENSE').read(),
long_description=open('./README.md').read(),
url='https://hanspeterschaub.info/basilisk/',
package_dir={'': package_dir},
# install_requires=[
# 'matplotlib',
# 'numpy',
# 'pandas'
# ],
setup_requires=['pytest-runner'],
tests_require=['pytest', 'flake8'],
cmdclass={
'clean': CleanCommand,
'xcode': XCodeBuildCommand,
'cmake': CMakeBuildCommand,
'test': PyTestCommand,
'docs': BuildDocsCommand,
'lint': LintCommand
}
)