forked from unbit/uwsgi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
141 lines (111 loc) · 3.5 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
import os
import sys
import uwsgiconfig as uc
from setuptools import setup
from setuptools.dist import Distribution
from setuptools.command.install import install
from setuptools.command.install_lib import install_lib
from setuptools.command.build_ext import build_ext
try:
from wheel.bdist_wheel import bdist_wheel
HAS_WHEEL = True
except ImportError:
HAS_WHEEL = False
"""
This is a hack allowing you installing
uWSGI and uwsgidecorators via pip and easy_install
since 1.9.11 it automatically detects pypy
"""
uwsgi_compiled = False
def get_profile():
is_pypy = False
try:
import __pypy__ # NOQA
is_pypy = True
except ImportError:
pass
if is_pypy:
profile = os.environ.get('UWSGI_PROFILE', 'buildconf/pypy.ini')
else:
profile = os.environ.get('UWSGI_PROFILE', 'buildconf/default.ini')
if not profile.endswith('.ini'):
profile = "%s.ini" % profile
if '/' not in profile:
profile = "buildconf/%s" % profile
return profile
def patch_bin_path(cmd, conf):
bin_name = conf.get('bin_name')
if not os.path.isabs(bin_name):
print('Patching "bin_name" to properly install_scripts dir')
try:
if not os.path.exists(cmd.install_scripts):
os.makedirs(cmd.install_scripts)
conf.set('bin_name',
os.path.join(cmd.install_scripts, conf.get('bin_name')))
except Exception:
conf.set('bin_name', sys.prefix + '/bin/' + bin_name)
class uWSGIBuilder(build_ext):
def run(self):
global uwsgi_compiled
if not uwsgi_compiled:
conf = uc.uConf(get_profile())
patch_bin_path(self, conf)
uc.build_uwsgi(conf)
uwsgi_compiled = True
class uWSGIInstall(install):
def run(self):
global uwsgi_compiled
if not uwsgi_compiled:
conf = uc.uConf(get_profile())
patch_bin_path(self, conf)
uc.build_uwsgi(conf)
uwsgi_compiled = True
install.run(self)
class uWSGIInstallLib(install_lib):
def run(self):
global uwsgi_compiled
if not uwsgi_compiled:
conf = uc.uConf(get_profile())
patch_bin_path(self, conf)
uc.build_uwsgi(conf)
uwsgi_compiled = True
install_lib.run(self)
if HAS_WHEEL:
class uWSGIWheel(bdist_wheel):
def finalize_options(self):
bdist_wheel.finalize_options(self)
self.root_is_pure = False
class uWSGIDistribution(Distribution):
def __init__(self, *attrs):
Distribution.__init__(self, *attrs)
self.cmdclass['install'] = uWSGIInstall
self.cmdclass['install_lib'] = uWSGIInstallLib
self.cmdclass['build_ext'] = uWSGIBuilder
if HAS_WHEEL:
self.cmdclass['bdist_wheel'] = uWSGIWheel
def is_pure(self):
return False
def get_extra_require():
req = []
conf = uc.uConf(get_profile())
plugins = conf.get('main_plugin')
if plugins:
plugins = plugins.split(',')
if 'greenlet' in plugins:
req.append('greenlet')
return req
setup(
name='uWSGI',
version=uc.uwsgi_version,
description='The uWSGI server',
author='Unbit',
author_email='[email protected]',
license='GPL2',
py_modules=['uwsgidecorators'],
distclass=uWSGIDistribution,
classifiers=[
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 3'
],
install_requires=get_extra_require()
)