forked from clicheio/cliche
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
253 lines (214 loc) · 6.91 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
from __future__ import print_function
import distutils.core
import distutils.errors
import os.path
import sys
import warnings
try:
from setuptools import setup, find_packages
except ImportError:
from ez_setup import use_setuptools
use_setuptools()
from setuptools import setup, find_packages
from setuptools.command.test import test
if sys.version_info < (3, 3, 0):
warnings.warn(
'Cliche requires Python 3.3 or higher; the currently running '
'Python version is: ' + sys.version
)
def readme():
try:
with open(os.path.join(os.path.dirname(__file__), 'README.rst')) as f:
return f.read()
except (IOError, OSError):
return ''
install_requires = {
# Entity classes
'SQLAlchemy >= 0.9.0',
'alembic >= 0.6.0',
# Configuration
'PyYAML >= 3.10',
# Crawler
'celery >= 3.1.13',
'lxml >= 3.3.5',
'psycopg2 >= 2.5.3', # FIXME
'requests >= 2.3.0',
# Web
'Flask >= 0.10',
'Werkzeug >= 0.9',
# Sparql
'SPARQLWrapper >= 1.6.2',
# CLI
'click >= 3.3',
# Locale
'Babel >= 1.3',
# SCSS
'libsass >= 0.6.0',
# OAuth client
'Flask-OAuthlib >= 0.7.0',
# Sentry: Log Aggregation
'raven >= 5.1.1',
'blinker >= 1.3',
}
if sys.version_info < (3, 4, 0):
install_requires |= {
'pathlib >= 1.0',
'enum34 >= 1.0',
}
tests_require = {
'pytest >= 2.5.0',
'cssselect >= 0.9.1',
}
docs_require = {
'Sphinx >= 1.2',
}
class BaseAlembicCommand(distutils.core.Command):
"""Base class for commands provided by Alembic."""
user_options = [
('config=', 'c', 'Configuration file (YAML or Python)'),
('debug', 'd', 'Print debug logs'),
]
def initialize_options(self):
self.config = None
self.debug = False
def finalize_options(self):
if self.config is None:
try:
self.config = os.environ['CLICHE_CONFIG']
except KeyError:
raise distutils.errors.DistutilsOptionError(
'The -c/--config option or CLICHE_CONFIG environment '
'variable is required'
)
if not os.path.isfile(self.config):
raise distutils.errors.DistutilsOptionError(
self.config + ' cannot be found'
)
def run(self):
try:
from cliche.cli import initialize_app
from cliche.orm import Base, get_alembic_config, import_all_modules
from cliche.web.app import app
from cliche.web.db import get_database_engine
import_all_modules()
except ImportError as e:
raise ImportError('dependencies are not resolved yet; run '
'"pip install -e ." first\n' + str(e))
if self.debug:
print('These mapping classes are loaded into ORM registry:',
file=sys.stderr)
for cls in Base._decl_class_registry.values():
if isinstance(cls, type):
print('- {0.__module__}.{0.__name__}'.format(cls),
file=sys.stderr)
initialize_app(self.config)
with app.app_context():
engine = get_database_engine()
config = get_alembic_config(engine)
self.alembic_process(config)
def alembic_process(self, config):
raise NotImplementedError('override alembic_process() method')
class revision(BaseAlembicCommand):
"""Adds a new revision to the database migration history."""
description = __doc__
user_options = BaseAlembicCommand.user_options + [
('message=', 'm', 'Message string'),
('autogenerate', None, 'Populates revision script with candidate '
'migration operations, based on comparison '
'of database to model.')
]
def initialize_options(self):
BaseAlembicCommand.initialize_options(self)
self.message = None
self.autogenerate = False
def alembic_process(self, config):
from alembic.command import revision
revision(config, self.message, self.autogenerate)
class history(BaseAlembicCommand):
"""List revisions of the database migration history."""
description = __doc__
def alembic_process(self, config):
from alembic.command import history
from alembic.environment import EnvironmentContext
from alembic.script import ScriptDirectory
from cliche.web.app import app
from cliche.web.db import get_database_engine
with app.app_context():
engine = get_database_engine()
script = ScriptDirectory.from_config(config)
with EnvironmentContext(config, script, as_sql=False,
destination_rev=None, tag=None) as context:
context.configure(engine.contextual_connect(), engine.url)
history(config)
class pytest(test):
def finalize_options(self):
test.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
from pytest import main
errno = main(self.test_args)
raise SystemExit(errno)
cmdclass = {}
try:
__import__('pytest')
except ImportError:
pass
else:
cmdclass['test'] = pytest
try:
__import__('alembic')
except ImportError:
pass
else:
cmdclass.update(
revision=revision,
history=history
)
setup(
name='Cliche',
description='An ontology of fictional works',
long_description=readme(),
author='The Cliche team',
url='http://cliche.io/',
license='AGPLv3 or later',
packages=find_packages(exclude=['tests']),
package_data={
'cliche': [
'migrations/env.py',
'migrations/script.py.mako',
'migrations/versions/*.py'
]
},
zip_safe=False,
entry_points='''
[console_scripts]
cliche = cliche.cli:main
''',
install_requires=install_requires,
tests_require=tests_require,
extras_require={
'docs': docs_require,
'tests': tests_require
},
cmdclass=cmdclass,
classifiers=[
'Development Status :: 1 - Planning',
'Environment :: Web Environment',
'Intended Audience :: End Users/Desktop',
'License :: OSI Approved ::'
' GNU Affero General Public License v3 or later (AGPLv3+)',
'Operating System :: MacOS :: MacOS X',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Database',
'Topic :: Documentation',
'Topic :: Internet :: WWW/HTTP :: Dynamic Content',
'Topic :: Internet :: WWW/HTTP :: Indexing/Search',
'Topic :: Internet :: WWW/HTTP :: WSGI :: Application'
],
sass_manifests={
'cliche.web': ('static/sass', 'static/css', '/static/css')
}
)