forked from kpn/py-fqn-decorators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
188 lines (187 loc) · 8.79 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
from setuptools import setup
setup(**{'author': 'Mattias Sluis',
'author_email': '[email protected]',
'classifiers': ['Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: Internet :: WWW/HTTP'],
'description': 'Easily create multi-purpose decorators that have access to '
'the FQN of the original function.',
'include_package_data': True,
'install_requires': [],
'long_description': 'FQN Decorators\n'
'==============\n'
'\n'
'.. image:: '
'https://secure.travis-ci.org/kpn-digital/py-fqn-decorators.svg?branch=master\n'
' :target: '
'http://travis-ci.org/kpn-digital/py-fqn-decorators?branch=master\n'
'\n'
'.. image:: '
'https://img.shields.io/codecov/c/github/kpn-digital/py-fqn-decorators/master.svg\n'
' :target: '
'http://codecov.io/github/kpn-digital/py-fqn-decorators?branch=master\n'
'\n'
'.. image:: '
'https://img.shields.io/pypi/v/fqn-decorators.svg\n'
' :target: '
'https://pypi.python.org/pypi/fqn-decorators\n'
'\n'
'.. image:: '
'https://readthedocs.org/projects/fqn-decorators/badge/?version=latest\n'
' :target: '
'http://fqn-decorators.readthedocs.org/en/latest/?badge=latest\n'
'\n'
'\n'
'Installation\n'
'------------\n'
'.. start_installation\n'
'\n'
'At the command line::\n'
'\n'
' $ pip install fqn-decorators\n'
'\n'
'\n'
'.. end_installation\n'
'\n'
'Usage\n'
'-----\n'
'.. start_usage\n'
'.. py:currentmodule:: fqn_decorators.decorators\n'
'\n'
'Introduction\n'
'------------\n'
'\n'
'By extending the :class:`~Decorator` class you can '
'create simple decorators.\n'
'Implement the :meth:`~Decorator.before` and/or '
':meth:`~Decorator.after` methods to perform actions '
'before or after execution of the decorated item.\n'
'The :meth:`~Decorator.before` method can access the '
'arguments of the decorated item by changing the '
':attr:`~Decorator.args` and :attr:`~Decorator.kwargs` '
'attributes.\n'
'The :meth:`~Decorator.after` method can access or change '
'the result using the :attr:`~Decorator.result` '
'attribute.\n'
'The :meth:`~Decorator.exception` method can be used for '
'do something with an Exception that has been raised.\n'
'In all three methods the :attr:`~Decorator.fqn` and '
':attr:`~Decorator.func` attributes are available.\n'
'\n'
'Simple decorator\n'
'----------------\n'
'\n'
'Create a simple decorator::\n'
'\n'
' import fqn_decorators\n'
' import time\n'
'\n'
' class time_it(fqn_decorators.Decorator):\n'
'\n'
' def before(self):\n'
' self.start = time.time()\n'
'\n'
' def after(self):\n'
' duration = time.time() - self.start\n'
' print("{0} took {1} '
'seconds".format(self.fqn, duration))\n'
'\n'
'\n'
' @time_it\n'
' def my_function():\n'
' time.sleep(1)\n'
'\n'
' >>>my_function()\n'
' __main__.my_function took 1.00293397903 seconds\n'
'\n'
'\n'
'Decorator with arguments\n'
'------------------------\n'
'\n'
'It is also very easy to create a decorator with '
'arguments.\n'
'\n'
'.. note::\n'
' It is not possible to create decorators with '
'*non-keyworded* arguments.\n'
' To create a decorator that supports non-keyworded '
'arguments see the :ref:`Advanced Usage '
'<usage_advanced_non_keyword_decorators>` section.\n'
'\n'
'Example::\n'
'\n'
' import fqn_decorators\n'
' import time\n'
'\n'
' class threshold(fqn_decorators.Decorator):\n'
'\n'
' def before(self):\n'
' self.start = time.time()\n'
'\n'
' def after(self):\n'
' duration = time.time() - self.start\n'
" treshold = self.params.get('threshold')\n"
' if threshold and duration > threshold:\n'
" raise Exception('Execution took longer "
"than the threshold')\n"
'\n'
'\n'
' @threshold(threshold=2)\n'
' def my_function():\n'
' time.sleep(3)\n'
'\n'
' >>> my_function()\n'
' Exception: Execution took longer than the threshold\n'
'\n'
'\n'
'Async Decorator\n'
'---------------\n'
'\n'
"There's also support for decorating coroutines (or any "
'awaitable), for Python >=3.5 only.\n'
'\n'
'The implementation is the same as with the sync version, '
'just inherit from\n'
':class:`~fqn_decorators.async.AsyncDecorator` instead.\n'
'\n'
'Example::\n'
'\n'
' import asyncio\n'
' import time\n'
' from fqn_decorators.async import AsyncDecorator\n'
'\n'
' class time_it_async(AsyncDecorator):\n'
'\n'
' def before(self):\n'
' self.start = time.time()\n'
'\n'
' def after(self):\n'
' duration = time.time() - self.start\n'
' print("{0} took {1} '
'seconds".format(self.fqn, duration))\n'
'\n'
' @time_it_async\n'
' async def coro():\n'
' await asyncio.sleep(1)\n'
'\n'
' >>> loop = asyncio.get_event_loop()\n'
' >>> loop.run_until_complete(coro())\n'
' __main__.coro took 1.001493215560913 seconds\n'
'\n'
'\n'
'.. end_usage\n',
'name': 'fqn-decorators',
'packages': ['fqn_decorators'],
'tests_require': ['tox'],
'url': 'https://github.com/kpn-digital/py-fqn-decorators',
'version': '1.2.0',
'zip_safe': False})