forked from getlogbook/logbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
149 lines (114 loc) · 3.89 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
r"""
Logbook
-------
An awesome logging implementation that is fun to use.
Quickstart
``````````
::
from logbook import Logger
log = Logger('A Fancy Name')
log.warn('Logbook is too awesome for most applications')
log.error("Can't touch this")
Works for web apps too
``````````````````````
::
from logbook import MailHandler, Processor
mailhandler = MailHandler(from_addr='[email protected]',
recipients=['[email protected]'],
level='ERROR', format_string=u'''\
Subject: Application Error for {record.extra[path]} [{record.extra[method]}]
Message type: {record.level_name}
Location: {record.filename}:{record.lineno}
Module: {record.module}
Function: {record.func_name}
Time: {record.time:%Y-%m-%d %H:%M:%S}
Remote IP: {record.extra[ip]}
Request: {record.extra[path]} [{record.extra[method]}]
Message:
{record.message}
''')
def handle_request(request):
def inject_extra(record, handler):
record.extra['ip'] = request.remote_addr
record.extra['method'] = request.method
record.extra['path'] = request.path
with Processor(inject_extra):
with mailhandler:
# execute code that might fail in the context of the
# request.
"""
import os
import sys
from setuptools import setup, Extension, Feature
from distutils.command.build_ext import build_ext
from distutils.errors import CCompilerError, DistutilsExecError, \
DistutilsPlatformError
extra = {}
cmdclass = {}
class BuildFailed(Exception):
pass
ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
if sys.platform == 'win32' and sys.version_info > (2, 6):
# 2.6's distutils.msvc9compiler can raise an IOError when failing to
# find the compiler
ext_errors += (IOError,)
class ve_build_ext(build_ext):
"""This class allows C extension building to fail."""
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError:
raise BuildFailed()
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except ext_errors:
raise BuildFailed()
cmdclass['build_ext'] = ve_build_ext
# Don't try to compile the extension if we're running on PyPy
if os.path.isfile('logbook/_speedups.c') and not hasattr(sys, "pypy_translation_info"):
speedups = Feature('optional C speed-enhancement module', standard=True,
ext_modules=[Extension('logbook._speedups',
['logbook/_speedups.c'])])
else:
speedups = None
def run_setup(with_binary):
features = {}
if with_binary and speedups is not None:
features['speedups'] = speedups
setup(
name='Logbook',
version='0.7.1-dev',
license='BSD',
url='http://logbook.pocoo.org/',
author='Armin Ronacher, Georg Brandl',
author_email='[email protected]',
description='A logging replacement for Python',
long_description=__doc__,
packages=['logbook'],
zip_safe=False,
platforms='any',
cmdclass=cmdclass,
features=features,
install_requires=[
],
**extra
)
def echo(msg=''):
sys.stdout.write(msg + '\n')
try:
run_setup(True)
except BuildFailed:
LINE = '=' * 74
BUILD_EXT_WARNING = ('WARNING: The C extension could not be compiled, '
'speedups are not enabled.')
echo(LINE)
echo(BUILD_EXT_WARNING)
echo('Failure information, if any, is above.')
echo('Retrying the build without the C extension now.')
echo()
run_setup(False)
echo(LINE)
echo(BUILD_EXT_WARNING)
echo('Plain-Python installation succeeded.')
echo(LINE)