-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
136 lines (104 loc) · 3.69 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
import distutils.log
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py as _build_py
from setuptools.command.install import install as _install
import os
import subprocess
with open("version.txt") as f:
PACKAGE_NAME, VERSION, COMPATIBLE_VERSION = \
(x.strip() for x in f.read().strip().split())
with open('requirements.txt') as f:
INSTALL_REQUIRES = [
x.strip('\n')
for x in f.readlines()
if x and x[0] != '#'
]
SHORT_DESCRIPTION = "Election of Faculty members"
PACKAGES_ROOT = '.'
PACKAGES = find_packages(PACKAGES_ROOT)
# Package meta
CLASSIFIERS = []
EXTRAS_REQUIRES = {
}
TESTS_REQUIRES = [
]
def get_all_data_files(dest_path, source_path):
dest_path = dest_path.strip('/')
source_path = source_path.strip('/')
source_len = len(source_path)
return [
(
os.path.join(dest_path, path[source_len:].strip('/')),
[os.path.join(path, f) for f in files],
)
for path, _, files in os.walk(source_path)
]
UI_DATA_FILES = get_all_data_files('lib/apella/resources/www/ui', 'ui/dist')
APELLA_TEMPLATE_FILES = get_all_data_files(
'lib/apella/resources/templates',
'apella/templates')
MIGRATION_QUERY_FILES = get_all_data_files(
'lib/apella/resources/migration_queries',
'resources/migration_queries')
class BuildUiCommand(_build_py):
""" Extend build_py to build Apella UI. """
description = 'build Apella UI'
user_options = _build_py.user_options + [
('no-ui', None, 'skip Apella UI build'),
]
boolean_options = _build_py.boolean_options + ['no-ui']
def initialize_options(self):
""" Set default values for options. """
_build_py.initialize_options(self)
self.no_ui = None
def run(self):
if not self.no_ui:
command = ['./build_ui.sh', 'production']
self.announce('building ui: %s' % ' '.join(command),
level=distutils.log.INFO)
subprocess.call(command, cwd='./ui/')
_build_py.run(self)
class InstallCommand(_install):
""" Extend install command with --no-build-ui option. """
user_options = _install.user_options + [
('no-build-ui', None, 'skip Apella UI build'),
]
boolean_options = _install.boolean_options + ['no-build-ui']
def initialize_options(self):
""" Set default values for options. """
_install.initialize_options(self)
self.no_build_ui = None
def run(self):
if self.no_build_ui:
self.reinitialize_command('build_py', no_ui=True)
_install.run(self)
setup(
name=PACKAGE_NAME,
version=VERSION,
license='GPLv3',
description=SHORT_DESCRIPTION,
classifiers=CLASSIFIERS,
packages=PACKAGES,
package_dir={'': PACKAGES_ROOT},
data_files=[
('lib/apella/resources', ['resources/common.json',
'resources/holidays.json',
'resources/apella.apimas',
'resources/schools.csv',
'resources/subject_areas_subjects.csv',
'resources/institutions.csv',
'resources/departments.csv']),
('lib/apella/scripts', ['scripts/apella_init.sh']),
] + UI_DATA_FILES + MIGRATION_QUERY_FILES + APELLA_TEMPLATE_FILES,
zip_safe=False,
install_requires=INSTALL_REQUIRES,
extras_require=EXTRAS_REQUIRES,
tests_require=TESTS_REQUIRES,
entry_points={
'console_scripts': [
'apella = apella.management:main',
],
},
cmdclass={'install': InstallCommand,
'build_py': BuildUiCommand},
)