-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
398 lines (336 loc) · 11 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
"""
A script that allows automated project management (Python's solution to a
MAKEFILE).
The main commands of interest are located within the setup argument,
under cmdclass option.
Also for more details, checkout the README.md file within the project for
further instructions of use.
"""
import os
import subprocess
import shutil
import webbrowser
import sys
from sys import platform as _platform
from setuptools import setup, find_packages, Command
from setuptools.command.install import install
from setuptools.command.test import test
# Yet to be used. It seems that subprocess.call does not inherit the
# PYTHONPATH variable thus rendering this function useless.
# The alternative solution to solve import issues (although perhaps not
# optimal) is setting all import statements relative to the root directory
# and then calling any script from the project root directory only. This is
# specified by the cwd option in subprocess.call .
def loadPaths():
"""
Inserts the project paths into system path so that imports and running
scripts from other scripts does not result in import errors.
"""
rootPath = os.path.dirname(os.path.abspath(__file__))
pathList = [os.path.join(rootPath, 'aardvark'),
os.path.join(rootPath, 'aardvark', 'client')]
for path in pathList:
sys.path.append(path)
def readme():
"""
Opens the README file and returns it's contents
:return: String content of README file
"""
with open("README.md") as file:
return file.read()
class RunClientCommand(Command):
"""
A command class to runs the client GUI.
"""
description = "runs client gui"
# The format is (long option, short option, description).
user_options = []
def initialize_options(self):
"""
Overriding a required abstract method.
"""
pass
def finalize_options(self):
"""
"""
pass
def run(self):
"""
Semantically, runs 'python aardvark/client/controller.py' on the
command line.
"""
import aardvark.client.controller as controller
try:
controller.main()
except Exception:
raise SystemExit("Unable to run client GUI!")
class RunServerCommand(Command):
"""
A command class to runs the django server.
"""
description = "runs django server"
user_options = []
def initialize_options(self):
"""
Overriding a required abstract method.
"""
pass
def finalize_options(self):
"""
"""
pass
def run(self):
"""
Semantically, runs 'python aardvark/server/manage.py runserver'
on the command line.
"""
path = os.path.join("aardvark", "server", "manage.py")
errno = subprocess.call([sys.executable, path, "runserver"])
if errno != 0:
raise SystemExit("Unable to run the django server!")
class PyTestCommand(test):
"""
A command class to run tests.
"""
description = "runs all automatic tests"
user_options = []
def initialize_options(self):
"""
Overriding a required abstract method.
"""
pass
def finalize_options(self):
"""
Overriding a required abstract method.
"""
pass
def run(self):
"""
Runs both client and django server tests.
"""
# Not at top level to prevent initial dependency errors
import pytest
print("Starting Client Tests:")
args = ["test"]
errno1 = pytest.main(args)
if errno1 != 0:
raise SystemExit("Unable to run client tests or they failed!")
print("\n\nStarting Server Tests:")
serverTestFile = os.path.join(os.getcwd(),
"aardvark", "server", "manage.py")
errno2 = subprocess.call([sys.executable, serverTestFile, "test"],
cwd=os.path.dirname(serverTestFile))
if errno2 != 0:
raise SystemExit("Unable to run server tests or they failed!")
class ManualTestCommand(test):
"""
A command class to run semi-manual tests.
"""
description = "runs all manual tests"
user_options = []
def initialize_options(self):
"""
Overriding a required abstract method.
"""
pass
def finalize_options(self):
"""
Overriding a required abstract method.
"""
pass
def run(self):
"""
Semantically, runs 'python test/manual/gui_test.py' on the
command line.
"""
path = os.path.join("test", "manual")
errno = subprocess.call([sys.executable, "gui_test.py"], cwd=path)
if errno != 0:
raise SystemExit("Unable to run manual test!")
class CleanCommand(Command):
"""
A command class to clean the current directory (removes folders).
"""
description = "cleans the project directory"
user_options = []
def initialize_options(self):
"""
Overriding a required abstract method.
"""
pass
def finalize_options(self):
"""
Overriding a required abstract method.
"""
pass
def run(self):
"""
Deletes some folders that can be generated (cross-platform).
"""
ignoreDirs = ["aardvark", "test", "doc", ".git", ".idea", "asset"]
ignoreFiles = [".gitignore", ".gitlab-ci.yml", "README.md",
"setup.py", "settings.ini", "pytest.ini", "LICENSE",
"install.bat", "runClient.bat", "runServer.bat",
"requirements.txt"]
deleteDirs = [dir for dir in os.listdir(".")
if dir not in ignoreDirs and os.path.isdir(dir)]
deleteFiles = [file for file in os.listdir(".")
if file not in ignoreFiles and os.path.isfile(file)]
for file in deleteFiles:
os.remove(file)
for dir in deleteDirs:
shutil.rmtree(dir)
path = os.path.join("doc")
errno = subprocess.call('make clean', shell=True, cwd=path)
if errno != 0:
raise SystemExit("Unable to clean docs!")
class GenerateDocCommand(Command):
"""
A command class to generate the code documentation.
"""
description = "generates project documentation"
user_options = []
def initialize_options(self):
"""
Overriding a required abstract method.
"""
pass
def finalize_options(self):
"""
Overriding a required abstract method.
"""
pass
def run(self):
"""
Generates the project documentation.
"""
path = os.path.join("doc")
errno = subprocess.call('make clean && make html', shell=True,
cwd=path)
if errno != 0:
raise SystemExit("Unable to generate docs!")
class RunDocCommand(Command):
"""
A command class to open the documentation in the default browser.
"""
description = "opens documentation in browser"
user_options = []
def initialize_options(self):
"""
Overriding a required abstract method.
"""
pass
def finalize_options(self):
"""
Overriding a required abstract method.
"""
pass
def run(self):
"""
Opens the project documentation in a browser.
"""
relativePath = os.path.join("doc", "build", "html", "index.html")
webbrowser.open('file://' + os.path.realpath(relativePath))
# class InstallInVirtualEnv(install):
# """
# A command class to install the project in a virtual environment
# (cross-platform).
# """
#
# def run(self):
# """
# Setups up the virtual environment, activates it and then installs the
# project and it's dependencies (cross-platform).
# """
# errno1 = subprocess.call('virtualenv aardvark-venv', shell=True)
#
# if _platform == "win32":
# errno2 = subprocess.call('activate aardvark-venv', shell=True)
#
# elif _platform == "linux" or _platform == "linux2":
# path = os.path.join("aardvark-venv", "bin", "activate")
# errno2 = subprocess.call('source ' + path, shell=True)
#
# errno3 = subprocess.call('pip install requirements.txt', shell=True)
#
# install.run(self)
#
# if errno1 != 0:
# raise SystemExit("Unable to setup the virtual environment!")
# if errno2 != 0:
# raise SystemExit("Unable to activate the virtual environment!")
setup(
name='team_aardvark_restaurant',
version='1.0',
packages=find_packages(),
install_requires=['requests', 'Sphinx', 'Django',
'pytest', "model_mommy"],
cmdclass={
# 'runInstall': InstallInVirtualEnv,
'runClient': RunClientCommand,
'runServer': RunServerCommand,
'runTest': PyTestCommand,
'runManualTest': ManualTestCommand,
'runClean': CleanCommand,
'generateDoc': GenerateDocCommand,
'runDoc': RunDocCommand,
},
author='Team Aardvark',
author_email='[email protected]',
description='Restaurant Booking And Billing System (Client-Server)',
long_description=readme(),
url='https://gitlab.com/comp2541/aardvark',
classifiers=[
"Programming Language :: Python :: 3.4",
"Topic :: Management :: Restaurant"
],
)
# def generateCommand(command_subclass):
# """
# A decorator method that returns a standard class template for classes
# that inherit from setuptools command class.
#
# Specifically, it overrides the abstract methods required for a setuptools
# command class without adding any functionality.
# """
#
# orig_run = command_subclass.run
# orig_initialize = command_subclass.initialize_options
# orig_finalize = command_subclass.finalize_options
#
# def modified_initialize_options(self):
# """
# Overrides the empty abstract method.
#
# The original method is responsible for setting default values for
# all the options that the command supports.
#
# In practice, this is used as a lazy constructor.
# """
# # orig_initialize(self)
# pass
#
# def modified_finalize_options(self):
# """
# Overrides the empty abstract method.
#
# The original method is responsible for setting and checking the final
# values for all the options just before the method run is executed.
#
# In practice, this is where the values are assigned and verified.
# """
# # orig_finalize(self)
# pass
#
# def modified_run(self):
# """
# Overrides the default run method but doesn't add any additional
# functionality yet.
# """
# orig_run(self)
#
# command_subclass.initialize_options = modified_initialize_options
# command_subclass.finalize_options = modified_finalize_options
# command_subclass.run = modified_run
#
# return command_subclass