forked from Robpol86/Flask-Celery-Helper
/
setup.py
executable file
·136 lines (102 loc) · 4.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
#!/usr/bin/env python
import ast
import atexit
from codecs import open
from distutils.spawn import find_executable
import os
import sys
import subprocess
import setuptools.command.sdist
from setuptools.command.test import test
DESCRIPTION = 'Celery support for Flask without breaking PyCharm inspections.'
HERE = os.path.abspath(os.path.dirname(__file__))
KEYWORDS = 'flask celery redis'
NAME = 'Flask-Celery-Helper'
NAME_FILE = 'flask_celery'
PACKAGE = False
REQUIRES_INSTALL = ['Flask', 'celery']
REQUIRES_TEST = ['pytest-cov', 'Flask-Redis-Helper', 'Flask-SQLAlchemy', 'PyMySQL', 'pg8000']
REQUIRES_PIP = '"' + '" "'.join(set(REQUIRES_INSTALL + REQUIRES_TEST)) + '"'
def get_metadata(main_file):
"""Get metadata about the package/module.
Positional arguments:
main_file -- python file path within `HERE` which has __author__ and the others defined as global variables.
Returns:
Dictionary to be passed into setuptools.setup().
"""
with open(os.path.join(HERE, 'README.rst'), encoding='utf-8') as f:
long_description = f.read(100000)
with open(os.path.join(HERE, main_file), encoding='utf-8') as f:
lines = [l.strip() for l in f if l.startswith('__')]
metadata = ast.literal_eval("{'" + ", '".join([l.replace(' = ', "': ") for l in lines]) + '}')
__author__, __license__, __version__ = [metadata[k] for k in ('__author__', '__license__', '__version__')]
everything = dict(version=__version__, long_description=long_description, author=__author__, license=__license__)
if not all(everything.values()):
raise ValueError('Failed to obtain metadata from package/module.')
return everything
class PyTest(test):
description = 'Run all tests.'
TEST_ARGS = ['--cov-report', 'term-missing', '--cov', NAME_FILE, 'tests']
def finalize_options(self):
test.finalize_options(self)
setattr(self, 'test_args', self.TEST_ARGS)
setattr(self, 'test_suite', True)
def run_tests(self):
# Import here, cause outside the eggs aren't loaded.
pytest = __import__('pytest')
err_no = pytest.main(self.test_args)
sys.exit(err_no)
class PyTestPdb(PyTest):
description = 'Run all tests, drops to ipdb upon unhandled exception.'
TEST_ARGS = ['--ipdb', 'tests']
class PyTestCovWeb(PyTest):
description = 'Generates HTML report on test coverage.'
TEST_ARGS = ['--cov-report', 'html', '--cov', NAME_FILE, 'tests']
def run_tests(self):
if find_executable('open'):
atexit.register(lambda: subprocess.call(['open', os.path.join(HERE, 'htmlcov', 'index.html')]))
PyTest.run_tests(self)
class CmdStyle(setuptools.Command):
user_options = []
CMD_ARGS = ['flake8', '--max-line-length', '120', '--statistics', NAME_FILE + ('' if PACKAGE else '.py')]
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
subprocess.call(self.CMD_ARGS)
class CmdLint(CmdStyle):
description = 'Run pylint on entire project.'
CMD_ARGS = ['pylint', '--max-line-length', '120', NAME_FILE + ('' if PACKAGE else '.py')]
ALL_DATA = dict(
name=NAME,
description=DESCRIPTION,
url='https://github.com/Robpol86/{0}'.format(NAME),
author_email='robpol86@gmail.com',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Framework :: Flask',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'Operating System :: MacOS :: MacOS X',
'Operating System :: Microsoft :: Windows',
'Operating System :: POSIX',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Topic :: Software Development :: Libraries',
],
keywords=KEYWORDS,
py_modules=[NAME_FILE],
zip_safe=False,
install_requires=REQUIRES_INSTALL,
tests_require=REQUIRES_TEST,
cmdclass=dict(test=PyTest, testpdb=PyTestPdb, testcovweb=PyTestCovWeb, style=CmdStyle, lint=CmdLint),
# Pass the rest from get_metadata().
**get_metadata(os.path.join(NAME_FILE + ('/__init__.py' if PACKAGE else '.py')))
)
if __name__ == '__main__':
setuptools.setup(**ALL_DATA)