-
Notifications
You must be signed in to change notification settings - Fork 14
/
setup.py
193 lines (138 loc) · 4.83 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
import os
import os.path
import textwrap
import git
from setuptools import setup, find_packages
from setuptools.command.develop import develop
from setuptools.command.install import install
from lingvodoc import (
get_git_version,
get_uniparser_version)
here = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(here, 'README.md')) as f:
README = f.read()
with open(os.path.join(here, 'CHANGES.md')) as f:
CHANGES = f.read()
class React_Interface_Mixin(object):
"""
Adds ability to set up React-based interface to setuptools commands.
"""
user_options = [
('react-interface=', None, 'path to React-based interface distribution')]
def initialize_options(self):
"""
Initializes standard setuptools' command options and a React interface option.
"""
super().initialize_options()
self.react_interface = None
def run(self):
"""
Sets up React-based interface if required.
"""
super().run()
if self.react_interface is not None:
self.setup_react_interface(
os.path.join(
getattr(self, self.__react_path_attr__),
'lingvodoc'))
def setup_react_interface(self, lingvodoc_dir):
"""
Sets up React-based interface by copying its distribution files to appropriate locations.
"""
self.announce('Installing React-based interface')
interface_dir = os.path.expanduser(self.react_interface)
index_from_path = os.path.join(interface_dir, 'index.html')
index_to_path = os.path.join(lingvodoc_dir,
'views', 'v2', 'templates', 'new_interface.pt')
if os.path.exists(index_to_path):
os.remove(index_to_path)
self.copy_file(index_from_path, index_to_path)
assets_dir = os.path.join(interface_dir, 'assets')
self.copy_tree(assets_dir, os.path.join(
lingvodoc_dir, 'assets'))
class Version_Mixin(object):
"""
Tries to determine version from the Git repository state and pip installation state.
"""
version_py_template = textwrap.dedent(
'''\
# This file is overwritten on setup.
#
# Please do not modify it and ignore its changes in version control.
__version__ = {}
uniparser_version_dict = {}
''')
def run(self):
"""
Tries to determine version info from the Git repository and pip installation state, saves it to
'lingvodoc/version.py' if required.
"""
version_str = (
get_git_version(here))
version_uniparser_dict = (
get_uniparser_version())
if (version_str is not None or
version_uniparser_dict is not None):
with open(
os.path.join(here, 'lingvodoc', 'version.py'), 'w',
encoding = 'utf-8') as version_py_file:
version_py_file.write(
self.version_py_template.format(
repr(version_str),
repr(version_uniparser_dict)))
# Continuing with setup.
super().run()
class develop_with_interface(
React_Interface_Mixin,
develop):
"""
Extends 'develop' setup.py command with ability to develop React-based interface.
"""
__react_path_attr__ = 'egg_path'
user_options = (
develop.user_options +
React_Interface_Mixin.user_options)
class install_with_interface(
React_Interface_Mixin,
Version_Mixin,
install):
"""
Extends 'install' setup.py command with ability to install React-based interface and update version from
the Git repository state.
"""
__react_path_attr__ = 'install_lib'
user_options = (
install.user_options +
React_Interface_Mixin.user_options)
requires = [
'pyramid',
]
setup(name='lingvodoc',
version='2.1.1',
description='lingvodoc',
long_description=README + '\n\n' + CHANGES,
classifiers=[
"Programming Language :: Python",
"Framework :: Pyramid",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Internet :: WWW/HTTP :: WSGI :: Application",
],
author='Oleg Borisenko',
author_email='[email protected]',
url='https://lingvodoc.ispras.ru/',
keywords='web wsgi bfg pylons pyramid sqlalchemy',
packages=find_packages(exclude=['tests', 'tests.*']),
include_package_data=True,
zip_safe=False,
test_suite='lingvodoc',
install_requires=requires,
entry_points="""\
[paste.app_factory]
main = lingvodoc:main
[console_scripts]
initialize_lingvodoc_db = lingvodoc.scripts.initializedb:main
""",
cmdclass={
'develop': develop_with_interface,
'install': install_with_interface},
)