Skip to content

Commit eff66b5

Browse files
umaannamalaimergify[bot]TimPansino
authored
Update testing matrix for supported packages. (#904)
* Remove testing for unsupported package versions. * Add no cover flags. * [Mega-Linter] Apply linters fixes --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> Co-authored-by: umaannamalai <[email protected]> Co-authored-by: Timothy Pansino <[email protected]>
1 parent e371b02 commit eff66b5

File tree

5 files changed

+89
-113
lines changed

5 files changed

+89
-113
lines changed

newrelic/hooks/framework_bottle.py

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@
1818

1919
import functools
2020

21-
from newrelic.api.function_trace import (FunctionTrace, FunctionTraceWrapper,
22-
wrap_function_trace)
21+
from newrelic.api.function_trace import (
22+
FunctionTrace,
23+
FunctionTraceWrapper,
24+
wrap_function_trace,
25+
)
2326
from newrelic.api.transaction import current_transaction
2427
from newrelic.api.wsgi_application import wrap_wsgi_application
2528
from newrelic.common.object_names import callable_name
26-
from newrelic.common.object_wrapper import (wrap_out_function,
27-
function_wrapper, ObjectProxy, wrap_object_attribute,
28-
wrap_function_wrapper)
29+
from newrelic.common.object_wrapper import (
30+
ObjectProxy,
31+
function_wrapper,
32+
wrap_function_wrapper,
33+
wrap_object_attribute,
34+
wrap_out_function,
35+
)
2936

3037
module_bottle = None
3138

@@ -34,17 +41,17 @@ def status_code(exc, value, tb):
3441
# The HTTPError class derives from HTTPResponse and so we do not
3542
# need to check for it seperately as isinstance() will pick it up.
3643

37-
if isinstance(value, module_bottle.HTTPResponse):
38-
if hasattr(value, 'status_code'):
44+
if isinstance(value, module_bottle.HTTPResponse): # pragma: no cover
45+
if hasattr(value, "status_code"):
3946
return value.status_code
40-
elif hasattr(value, 'status'):
47+
elif hasattr(value, "status"):
4148
return value.status
42-
elif hasattr(value, 'http_status_code'):
49+
elif hasattr(value, "http_status_code"):
4350
return value.http_status_code
4451

4552

4653
def should_ignore(exc, value, tb):
47-
if hasattr(module_bottle, 'RouteReset'):
54+
if hasattr(module_bottle, "RouteReset"):
4855
if isinstance(value, module_bottle.RouteReset):
4956
return True
5057

@@ -113,8 +120,7 @@ def get(self, status, default=None):
113120
transaction.set_transaction_name(name, priority=1)
114121
handler = FunctionTraceWrapper(handler, name=name)
115122
else:
116-
transaction.set_transaction_name(str(status),
117-
group='StatusCode', priority=1)
123+
transaction.set_transaction_name(str(status), group="StatusCode", priority=1)
118124

119125
return handler or default
120126

@@ -140,43 +146,39 @@ def instrument_bottle(module):
140146
global module_bottle
141147
module_bottle = module
142148

143-
framework_details = ('Bottle', getattr(module, '__version__'))
144-
145-
if hasattr(module.Bottle, 'wsgi'): # version >= 0.9
146-
wrap_wsgi_application(module, 'Bottle.wsgi',
147-
framework=framework_details)
148-
elif hasattr(module.Bottle, '__call__'): # version < 0.9
149-
wrap_wsgi_application(module, 'Bottle.__call__',
150-
framework=framework_details)
151-
152-
if (hasattr(module, 'Route') and
153-
hasattr(module.Route, '_make_callback')): # version >= 0.10
154-
wrap_out_function(module, 'Route._make_callback',
155-
output_wrapper_Route_make_callback)
156-
elif hasattr(module.Bottle, '_match'): # version >= 0.9
157-
wrap_out_function(module, 'Bottle._match',
158-
output_wrapper_Bottle_match)
159-
elif hasattr(module.Bottle, 'match_url'): # version < 0.9
160-
wrap_out_function(module, 'Bottle.match_url',
161-
output_wrapper_Bottle_match)
162-
163-
wrap_object_attribute(module, 'Bottle.error_handler',
164-
proxy_Bottle_error_handler)
165-
166-
if hasattr(module, 'auth_basic'):
167-
wrap_function_wrapper(module, 'auth_basic', wrapper_auth_basic)
168-
169-
if hasattr(module, 'SimpleTemplate'):
170-
wrap_function_trace(module, 'SimpleTemplate.render')
171-
172-
if hasattr(module, 'MakoTemplate'):
173-
wrap_function_trace(module, 'MakoTemplate.render')
174-
175-
if hasattr(module, 'CheetahTemplate'):
176-
wrap_function_trace(module, 'CheetahTemplate.render')
177-
178-
if hasattr(module, 'Jinja2Template'):
179-
wrap_function_trace(module, 'Jinja2Template.render')
180-
181-
if hasattr(module, 'SimpleTALTemplate'):
182-
wrap_function_trace(module, 'SimpleTALTemplate.render')
149+
framework_details = ("Bottle", getattr(module, "__version__"))
150+
# version >= 0.9
151+
if hasattr(module.Bottle, "wsgi"): # pragma: no cover
152+
wrap_wsgi_application(module, "Bottle.wsgi", framework=framework_details)
153+
# version < 0.9
154+
elif hasattr(module.Bottle, "__call__"): # pragma: no cover
155+
wrap_wsgi_application(module, "Bottle.__call__", framework=framework_details)
156+
# version >= 0.10
157+
if hasattr(module, "Route") and hasattr(module.Route, "_make_callback"): # pragma: no cover
158+
wrap_out_function(module, "Route._make_callback", output_wrapper_Route_make_callback)
159+
# version >= 0.9
160+
elif hasattr(module.Bottle, "_match"): # pragma: no cover
161+
wrap_out_function(module, "Bottle._match", output_wrapper_Bottle_match)
162+
# version < 0.9
163+
elif hasattr(module.Bottle, "match_url"): # pragma: no cover
164+
wrap_out_function(module, "Bottle.match_url", output_wrapper_Bottle_match)
165+
166+
wrap_object_attribute(module, "Bottle.error_handler", proxy_Bottle_error_handler)
167+
168+
if hasattr(module, "auth_basic"):
169+
wrap_function_wrapper(module, "auth_basic", wrapper_auth_basic)
170+
171+
if hasattr(module, "SimpleTemplate"):
172+
wrap_function_trace(module, "SimpleTemplate.render")
173+
174+
if hasattr(module, "MakoTemplate"):
175+
wrap_function_trace(module, "MakoTemplate.render")
176+
177+
if hasattr(module, "CheetahTemplate"):
178+
wrap_function_trace(module, "CheetahTemplate.render")
179+
180+
if hasattr(module, "Jinja2Template"):
181+
wrap_function_trace(module, "Jinja2Template.render")
182+
183+
if hasattr(module, "SimpleTALTemplate"): # pragma: no cover
184+
wrap_function_trace(module, "SimpleTALTemplate.render")

newrelic/hooks/framework_pyramid.py

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,29 @@
4848
from newrelic.api.transaction import current_transaction
4949
from newrelic.api.wsgi_application import wrap_wsgi_application
5050
from newrelic.common.object_names import callable_name
51-
from newrelic.common.object_wrapper import (FunctionWrapper, wrap_out_function,
52-
wrap_function_wrapper)
51+
from newrelic.common.object_wrapper import (
52+
FunctionWrapper,
53+
wrap_function_wrapper,
54+
wrap_out_function,
55+
)
5356

5457

5558
def instrument_pyramid_router(module):
5659
pyramid_version = None
5760

5861
try:
5962
import pkg_resources
60-
pyramid_version = pkg_resources.get_distribution('pyramid').version
63+
64+
pyramid_version = pkg_resources.get_distribution("pyramid").version
6165
except Exception:
6266
pass
6367

64-
wrap_wsgi_application(
65-
module, 'Router.__call__', framework=('Pyramid', pyramid_version))
68+
wrap_wsgi_application(module, "Router.__call__", framework=("Pyramid", pyramid_version))
6669

6770

6871
def status_code(exc, value, tb):
6972
from pyramid.httpexceptions import HTTPException
73+
7074
# Ignore certain exceptions based on HTTP status codes.
7175

7276
if isinstance(value, HTTPException):
@@ -75,6 +79,7 @@ def status_code(exc, value, tb):
7579

7680
def should_ignore(exc, value, tb):
7781
from pyramid.exceptions import PredicateMismatch
82+
7883
# Always ignore PredicateMismatch as it is raised by views to force
7984
# subsequent views to be consulted when multi views are being used.
8085
# It isn't therefore strictly an error as such as a subsequent view
@@ -100,9 +105,7 @@ def view_handler_wrapper(wrapped, instance, args, kwargs):
100105

101106
# set exception views to priority=1 so they won't take precedence over
102107
# the original view callable
103-
transaction.set_transaction_name(
104-
name,
105-
priority=1 if args and isinstance(args[0], Exception) else 2)
108+
transaction.set_transaction_name(name, priority=1 if args and isinstance(args[0], Exception) else 2)
106109

107110
with FunctionTrace(name, source=view_callable) as trace:
108111
try:
@@ -114,7 +117,7 @@ def view_handler_wrapper(wrapped, instance, args, kwargs):
114117

115118

116119
def wrap_view_handler(mapped_view):
117-
if hasattr(mapped_view, '_nr_wrapped'):
120+
if hasattr(mapped_view, "_nr_wrapped"): # pragma: no cover
118121
return mapped_view
119122
else:
120123
wrapped = FunctionWrapper(mapped_view, view_handler_wrapper)
@@ -157,7 +160,7 @@ def _wrapper(context, request):
157160
return wrapper(context, request)
158161
finally:
159162
attr = instance.attr
160-
inst = getattr(request, '__view__', None)
163+
inst = getattr(request, "__view__", None)
161164
if inst is not None:
162165
if attr:
163166
handler = getattr(inst, attr)
@@ -166,7 +169,7 @@ def _wrapper(context, request):
166169
tracer.name = name
167170
tracer.add_code_level_metrics(handler)
168171
else:
169-
method = getattr(inst, '__call__')
172+
method = getattr(inst, "__call__")
170173
if method:
171174
name = callable_name(method)
172175
transaction.set_transaction_name(name, priority=2)
@@ -180,22 +183,21 @@ def instrument_pyramid_config_views(module):
180183
# Location of the ViewDeriver class changed from pyramid.config to
181184
# pyramid.config.views so check if present before trying to update.
182185

183-
if hasattr(module, 'ViewDeriver'):
184-
wrap_out_function(module, 'ViewDeriver.__call__', wrap_view_handler)
185-
elif hasattr(module, 'Configurator'):
186-
wrap_out_function(module, 'Configurator._derive_view',
187-
wrap_view_handler)
186+
if hasattr(module, "ViewDeriver"): # pragma: no cover
187+
wrap_out_function(module, "ViewDeriver.__call__", wrap_view_handler)
188+
elif hasattr(module, "Configurator"):
189+
wrap_out_function(module, "Configurator._derive_view", wrap_view_handler)
188190

189-
if hasattr(module, 'DefaultViewMapper'):
191+
if hasattr(module, "DefaultViewMapper"):
190192
module.DefaultViewMapper.map_class_requestonly = FunctionWrapper(
191-
module.DefaultViewMapper.map_class_requestonly,
192-
default_view_mapper_wrapper)
193+
module.DefaultViewMapper.map_class_requestonly, default_view_mapper_wrapper
194+
)
193195
module.DefaultViewMapper.map_class_native = FunctionWrapper(
194-
module.DefaultViewMapper.map_class_native,
195-
default_view_mapper_wrapper)
196+
module.DefaultViewMapper.map_class_native, default_view_mapper_wrapper
197+
)
196198

197199

198200
def instrument_pyramid_config_tweens(module):
199-
wrap_function_wrapper(module, 'Tweens.add_explicit', wrap_add_tween)
201+
wrap_function_wrapper(module, "Tweens.add_explicit", wrap_add_tween)
200202

201-
wrap_function_wrapper(module, 'Tweens.add_implicit', wrap_add_tween)
203+
wrap_function_wrapper(module, "Tweens.add_implicit", wrap_add_tween)

newrelic/hooks/logger_loguru.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def patch_loguru_logger(logger):
134134
if not hasattr(logger._core, "_nr_instrumented"):
135135
logger.add(_nr_log_forwarder, format="{message}")
136136
logger._core._nr_instrumented = True
137-
elif not hasattr(logger, "_nr_instrumented"):
137+
elif not hasattr(logger, "_nr_instrumented"): # pragma: no cover
138138
for _, handler in six.iteritems(logger._handlers):
139139
if handler._writer is _nr_log_forwarder:
140140
logger._nr_instrumented = True

newrelic/hooks/messagebroker_pika.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737

3838
def _add_consume_rabbitmq_trace(transaction, method, properties, nr_start_time, queue_name=None):
39-
4039
routing_key = None
4140
if hasattr(method, "routing_key"):
4241
routing_key = method.routing_key
@@ -197,7 +196,7 @@ def _wrap_basic_get_Channel(wrapper, queue, callback, *args, **kwargs):
197196
return queue, args, kwargs
198197

199198

200-
def _wrap_basic_get_Channel_old(wrapper, callback=None, queue="", *args, **kwargs):
199+
def _wrap_basic_get_Channel_old(wrapper, callback=None, queue="", *args, **kwargs): # pragma: no cover
201200
if callback is not None:
202201
callback = wrapper(callback)
203202
args = (callback, queue) + args
@@ -368,7 +367,6 @@ def callback_wrapper(wrapped, instance, args, kwargs):
368367
correlation_id=correlation_id,
369368
source=wrapped,
370369
) as mt:
371-
372370
# Improve transaction naming
373371
_new_txn_name = "RabbitMQ/Exchange/%s/%s" % (exchange, name)
374372
mt.set_transaction_name(_new_txn_name, group="Message")
@@ -404,7 +402,7 @@ def instrument_pika_adapters(module):
404402

405403
version = tuple(int(num) for num in pika.__version__.split(".", 1)[0])
406404

407-
if version[0] < 1:
405+
if version[0] < 1: # pragma: no cover
408406
wrap_consume = _wrap_basic_consume_BlockingChannel_old
409407
else:
410408
wrap_consume = _wrap_basic_consume_Channel
@@ -426,7 +424,7 @@ def instrument_pika_channel(module):
426424

427425
version = tuple(int(num) for num in pika.__version__.split(".", 1)[0])
428426

429-
if version[0] < 1:
427+
if version[0] < 1: # pragma: no cover
430428
wrap_consume = _wrap_basic_consume_Channel_old
431429
wrap_get = _wrap_basic_get_Channel_old
432430
else:

0 commit comments

Comments
 (0)