8000 flake8 test passing (#373) · prometheus/client_python@3cb4c92 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3cb4c92

Browse files
tusharmakkar08brian-brazil
authored andcommitted
flake8 test passing (#373)
* flake8 test passing * Added E129 in ignore tox Author: tusharmakkar08 [tusharmakkar08@gmail.com] Signed-off-by: Tushar Makkar <tushar.makkar@vyom.com>
1 parent d85d120 commit 3cb4c92

26 files changed

+446
-431
lines changed

prometheus_client/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#!/usr/bin/python
22

3-
from . import core
43
from . import exposition
54
from . import gc_collector
5+
from . import metrics
6+
from . import metrics_core
67
from . import platform_collector
78
from . import process_collector
89
from . import registry
9-
from . import metrics_core
10-
from . import metrics
1110

1211
__all__ = ['Counter', 'Gauge', 'Summary', 'Histogram', 'Info', 'Enum']
1312

@@ -57,5 +56,6 @@
5756

5857
start_http_server(8000)
5958
import time
59+
6060
while True:
6161
time.sleep(1)

prometheus_client/core.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
from .metrics import Counter, Enum, Gauge, Histogram, Info, Summary
44
from .metrics_core import (
5-
CounterMetricFamily, GaugeHistogramMetricFamily, GaugeMetricFamily,
6-
HistogramMetricFamily, InfoMetricFamily, Metric, Sample,
7-
StateSetMetricFamily, SummaryMetricFamily, UnknownMetricFamily,
8-
UntypedMetricFamily,
9-
)
5+
CounterMetricFamily, GaugeHistogramMetricFamily, GaugeMetricFamily, HistogramMetricFamily, InfoMetricFamily,
6+
Metric, StateSetMetricFamily, SummaryMetricFamily, UnknownMetricFamily, UntypedMetricFamily)
107
from .registry import CollectorRegistry, REGISTRY
118
from .samples import Exemplar, Sample, Timestamp
129

prometheus_client/decorator.py

Lines changed: 8 additions & 1 deletion
Original fi 3419 le line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
if sys.version_info >= (3,):
4646
from inspect import getfullargspec
4747

48+
4849
def get_init(cls):
4950
return cls.__init__
5051
else:
@@ -65,6 +66,7 @@ def __iter__(self):
6566

6667
getargspec = inspect.getargspec
6768

69+
6870
def get_init(cls):
6971
return cls.__init__.__func__
7072

@@ -246,7 +248,7 @@ def decorator(caller, _func=None):
246248
if inspect.isclass(caller):
247249
name = caller.__name__.lower()
248250
doc = 'decorator(%s) converts functions/generators into ' \
249-
'factories of %s objects' % (caller.__name__, caller.__name__)
251+
'factories of %s objects' % (caller.__name__, caller.__name__)
250252
elif inspect.isfunction(caller):
251253
if caller.__name__ == '<lambda>':
252254
name = '_lambda_'
@@ -284,12 +286,16 @@ def __call__(self, func):
284286
if n_args == 2 and not init.varargs: # (self, genobj) Python 2.7
285287
def __init__(self, g, *a, **k):
286288
return _GeneratorContextManager.__init__(self, g(*a, **k))
289+
290+
287291
ContextManager.__init__ = __init__
288292
elif n_args == 2 and init.varargs: # (self, gen, *a, **k) Python 3.4
289293
pass
290294
elif n_args == 4: # (self, gen, args, kwds) Python 3.5
291295
def __init__(self, g, *a, **k):
292296
return _GeneratorContextManager.__init__(self, g, a, k)
297+
298+
293299
ContextManager.__init__ = __init__
294300

295301
contextmanager = decorator(ContextManager)
@@ -380,6 +386,7 @@ def dec(f):
380386
check(getfullargspec(f).args, operator.lt, ' in ' + f.__name__)
381387
typemap[types] = f
382388
return f
389+
383390
return dec
384391

385392
def dispatch_info(*types):

prometheus_client/exposition.py

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
from urllib.request import build_opener, Request, HTTPHandler
2828
from urllib.parse import quote_plus, parse_qs, urlparse
2929

30-
3130
CONTENT_TYPE_LATEST = str('text/plain; version=0.0.4; charset=utf-8')
32-
'''Content type of the latest text format'''
31+
"""Content type of the latest text format"""
3332

3433
PYTHON26_OR_OLDER = sys.version_info < (2, 7)
3534

3635

3736
def make_wsgi_app(registry=REGISTRY):
38-
'''Create a WSGI app which serves the metrics from a registry.'''
37+
"""Create a WSGI app which serves the metrics from a registry."""
38+
3939
def prometheus_app(environ, start_response):
4040
params = parse_qs(environ.get('QUERY_STRING', ''))
4141
r = registry
@@ -48,6 +48,7 @@ def prometheus_app(environ, start_response):
4848
headers = [(str('Content-type'), content_type)]
4949
start_response(status, headers)
5050
return [output]
51+
5152
return prometheus_app
5253

5354

@@ -68,22 +69,22 @@ def start_wsgi_server(port, addr='', registry=REGISTRY):
6869

6970

7071
def generate_latest(registry=REGISTRY):
71-
'''Returns the metrics from the registry in latest text format as a string.'''
72+
"""Returns the metrics from the registry in latest text format as a string."""
7273

73-
def sample_line(s):
74-
if s.labels:
74+
def sample_line(line):
75+
if line.labels:
7576
labelstr = '{{{0}}}'.format(','.join(
7677
['{0}="{1}"'.format(
77-
k, v.replace('\\', r'\\').replace('\n', r'\n').replace('"', r'\"'))
78-
for k, v in sorted(s.labels.items())]))
78+
k, v.replace('\\', r'\\').replace('\n', r'\n').replace('"', r'\"'))
79+
for k, v in sorted(line.labels.items())]))
7980
else:
8081
labelstr = ''
8182
timestamp = ''
82-
if s.timestamp is not None:
83+
if line.timestamp is not None:
8384
# Convert to milliseconds.
84-
timestamp = ' {0:d}'.format(int(float(s.timestamp) * 1000))
85+
timestamp = ' {0:d}'.format(int(float(line.timestamp) * 1000))
8586
return '{0}{1} {2}{3}\n'.format(
86-
s.name, labelstr, floatToGoString(s.value), timestamp)
87+
line.name, labelstr, floatToGoString(line.value), timestamp)
8788

8889
output = []
8990
for metric in registry.collect():
@@ -121,7 +122,7 @@ def sample_line(s):
121122
except Exception as exception:
122123
exception.args = (exception.args or ('',)) + (metric,)
123124
raise
124-
125+
125126
for suffix, lines in sorted(om_samples.items()):
126127
output.append('# TYPE {0}{1} gauge\n'.format(metric.name, suffix))
127128
output.extend(lines)
@@ -134,7 +135,7 @@ def choose_encoder(accept_header):
134135
if accepted.split(';')[0].strip() == 'application/openmetrics-text':
135136
return (openmetrics.generate_latest,
136137
openmetrics.CONTENT_TYPE_LATEST)
137-
return (generate_latest, CONTENT_TYPE_LATEST)
138+
return generate_latest, CONTENT_TYPE_LATEST
138139

139140

140141
class MetricsHandler(BaseHTTPRequestHandler):
@@ -196,10 +197,10 @@ def start_http_server(port, addr='', registry=REGISTRY):
196197

197198

198199
def write_to_textfile(path, registry):
199-
'''Write metrics to the given path.
200+
"""Write metrics to the given path.
200201
201202
This is intended for use with the Node exporter textfile collector.
202-
The path must end in .prom for the textfile collector to process it.'''
203+
The path must end in .prom for the textfile collector to process it."""
203204
tmppath = '%s.%s.%s' % (path, os.getpid(), threading.current_thread().ident)
204205
with open(tmppath, 'wb') as f:
205206
f.write(generate_latest(registry))
@@ -208,9 +209,10 @@ def write_to_textfile(path, registry):
208209

209210

210211
def default_handler(url, method, timeout, headers, data):
211-
'''Default handler that implements HTTP/HTTPS connections.
212+
"""Default handler that implements HTTP/HTTPS connections.
213+
214+
Used by the push_to_gateway functions. Can be re-used by other handlers."""
212215

213-
Used by the push_to_gateway functions. Can be re-used by other handlers.'''
214216
def handle():
215217
request = Request(url, data=data)
216218
request.get_method = lambda: method
@@ -225,13 +227,14 @@ def handle():
225227

226228

227229
def basic_auth_handler(url, method, timeout, headers, data, username=None, password=None):
228-
'''Handler that implements HTTP/HTTPS connections with Basic Auth.
230+
"""Handler that implements HTTP/HTTPS connections with Basic Auth.
229231
230232
Sets auth headers using supplied 'username' and 'password', if set.
231-
Used by the push_to_gateway functions. Can be re-used by other handlers.'''
233+
Used by the push_to_gateway functions. Can be re-used by other handlers."""
234+
232235
def handle():
233-
'''Handler that implements HTTP Basic Auth.
234-
'''
236+
"""Handler that implements HTTP Basic Auth.
237+
"""
235238
if username is not None and password is not None:
236239
auth_value = '{0}:{1}'.format(username, password).encode('utf-8')
237240
auth_token = base64.b64encode(auth_value)
@@ -245,7 +248,7 @@ def handle():
245248
def push_to_gateway(
246249
gateway, job, registry, grouping_key=None, timeout=30,
247250
handler=default_handler):
248-
'''Push metrics to the given pushgateway.
251+
"""Push metrics to the given pushgateway.
249252
250253
`gateway` the url for your push gateway. Either of the form
251254
'http://pushgateway.local', or 'pushgateway.local'.
@@ -282,14 +285,14 @@ def push_to_gateway(
282285
Message Body.
283286
284287
This overwrites all metrics with the same job and grouping_key.
285-
This uses the PUT HTTP method.'''
288+
This uses the PUT HTTP method."""
286289
_use_gateway('PUT', gateway, job, registry, grouping_key, timeout, handler)
287290

288291

289292
def pushadd_to_gateway(
290293
gateway, job, registry, grouping_key=None, timeout=30,
291294
handler=default_handler):
292-
'''PushAdd metrics to the given pushgateway.
295+
"""PushAdd metrics to the given pushgateway.
293296
294297
`gateway` the url for your push gateway. Either of the form
295298
'http://pushgateway.local', or 'pushgateway.local'.
@@ -308,13 +311,13 @@ def pushadd_to_gateway(
308311
for implementation requirements.
309312
310313
This replaces metrics with the same name, job and grouping_key.
311-
This uses the POST HTTP method.'''
314+
This uses the POST HTTP method."""
312315
_use_gateway('POST', gateway, job, registry, grouping_key, timeout, handler)
313316

314317

315318
def delete_from_gateway(
316319
gateway, job, grouping_key=None, timeout=30, handler=default_handler):
317-
'''Delete metrics from the given pushgateway.
320+
"""Delete metrics from the given pushgateway.
318321
319322
`gateway` the url for your push gateway. Either of the form
320323
'http://pushgateway.local', or 'pushgateway.local'.
@@ -332,7 +335,7 @@ def delete_from_gateway(
332335
for implementation requirements.
333336
334337
This deletes metrics with the given job and grouping_key.
335-
This uses the DELETE HTTP method.'''
338+
This uses the DELETE HTTP method."""
336339
_use_gateway('DELETE', gateway, job, None, grouping_key, timeout, handler)
337340

338341

@@ -359,7 +362,7 @@ def _use_gateway(method, gateway, job, registry, grouping_key, timeout, handler)
359362

360363

361364
def instance_ip_grouping_key():
362-
'''Grouping key with instance set to the IP Address of this host.'''
365+
"""Grouping key with instance set to the IP Address of this host."""
363366
with closing(socket.socket(socket.AF_INET, socket.SOCK_DGRAM)) as s:
364367
s.connect(('localhost', 0))
365368
return {'instance': s.getsockname()[0]}

0 commit comments

Comments
 (0)
0