Skip to content

Commit 1178816

Browse files
committed
Merge branch 'release/v2.0.0'
2 parents 6310d88 + 508deeb commit 1178816

15 files changed

+114
-45
lines changed

.travis.yml

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1+
sudo: false
12
language: python
2-
33
python:
44
- "2.6"
55
- "2.7"
6-
- "3.2"
7-
- "3.3"
86
- "3.4"
7+
- "3.5"
98
- "pypy"
109
- "pypy3"
1110

1211
# command to install dependencies
1312
install:
14-
- pip install . --use-mirrors
15-
- pip install coveralls --use-mirrors
13+
- pip install .
14+
- pip install coveralls flake8
1615

1716
# command to run tests
1817
script:
1918
- python setup.py nosetests --cover-erase --with-coverage
2019
- nosetests --with-coverage --cover-min-percentage=100
2120

21+
before_script: flake8 --ignore=W391 statsd tests
22+
2223
after_success:
2324
- coveralls
2425

README.rst

+9-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ Introduction
1616
`statsd` is a client for Etsy's statsd server, a front end/proxy for the
1717
Graphite stats collection and graphing server.
1818

19-
* Graphite
20-
- http://graphite.wikidot.com
21-
* Statsd
22-
- code: https://github.com/etsy/statsd
23-
- blog post: http://codeascraft.etsy.com/2011/02/15/measure-anything-measure-everything/
19+
Links
20+
-----
2421

22+
- The source: https://github.com/WoLpH/python-statsd
23+
- Project page: https://pypi.python.org/pypi/python-statsd
24+
- Reporting bugs: https://github.com/WoLpH/python-statsd/issues
25+
- Documentation: http://python-statsd.readthedocs.io/en/latest/
26+
- My blog: http://w.wol.ph/
27+
- Statsd: https://github.com/etsy/statsd
28+
- Graphite: http://graphite.wikidot.com
2529

2630
Install
2731
-------

docs/conf.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,23 @@
6363
# The full version, including alpha/beta/rc tags.
6464
release = statsd.__version__
6565

66+
# Monkey patch to disable nonlocal image warning
67+
import sphinx
68+
original_warn_mode = sphinx.environment.BuildEnvironment.warn_node
69+
70+
71+
def allow_nonlocal_image_warn_node(self, msg, node):
72+
if not msg.startswith('nonlocal image URI found:'):
73+
original_warn_mode(self, msg, node)
74+
75+
sphinx.environment.BuildEnvironment.warn_node = allow_nonlocal_image_warn_node
76+
77+
suppress_warnings = [
78+
'image.nonlocal_uri',
79+
]
80+
81+
needs_sphinx = '1.4'
82+
6683
# The language for content autogenerated by Sphinx. Refer to documentation
6784
# for a list of supported languages.
6885
#language = None
@@ -134,7 +151,7 @@
134151
# Add any paths that contain custom static files (such as style sheets) here,
135152
# relative to this directory. They are copied after the builtin static files,
136153
# so a file named "default.css" will overwrite the builtin "default.css".
137-
html_static_path = ['_static']
154+
#html_static_path = ['_static']
138155

139156
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
140157
# using the given strftime format.

docs/index.rst

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,26 @@
11
Python Statsd Client
22
=========================================
33

4+
`statsd` is a client for Etsy's statsd server, a front end/proxy for the
5+
Graphite stats collection and graphing server.
6+
7+
Links
8+
-----
9+
10+
- The source: https://github.com/WoLpH/python-statsd
11+
- Project page: https://pypi.python.org/pypi/python-statsd
12+
- Reporting bugs: https://github.com/WoLpH/python-statsd/issues
13+
- Documentation: http://python-statsd.readthedocs.io/en/latest/
14+
- My blog: http://w.wol.ph/
15+
- Statsd: https://github.com/etsy/statsd
16+
- Graphite: http://graphite.wikidot.com
17+
418
Contents:
519

620
.. toctree::
721
:maxdepth: 2
822

923
usage
10-
1124
statsd
1225

1326
Indices and tables

setup.cfg

+6
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ all_files = 1
1919
[upload_sphinx]
2020
upload-dir = docs/_build/html
2121

22+
[bdist_wheel]
23+
universal = 1
24+
25+
[flake8]
26+
ignore = W391
27+
exclude = docs/*,statsd/compat.py

statsd/__init__.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
]
2020

2121
__package_name__ = 'python-statsd'
22-
__version__ = '1.7.2'
22+
__version__ = '2.0.0'
2323
__author__ = 'Rick van Hattem'
2424
__author_email__ = '[email protected]'
2525
__description__ = (
@@ -28,8 +28,8 @@
2828
__url__ = 'https://github.com/WoLpH/python-statsd'
2929

3030

31-
# The doctests in this package, when run, will try to send data on the wire. To
32-
# keep this from happening, we hook into nose's machinery to mock out
31+
# The doctests in this package, when run, will try to send data on the wire.
32+
# To keep this from happening, we hook into nose's machinery to mock out
3333
# `Connection.send` at the beginning of testing this package, and reset it at
3434
# the end.
3535
_connection_patch = None

statsd/client.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66

77
class Client(object):
8+
89
'''Statsd Client Object
910
1011
:keyword name: The name for this client
1112
:type name: str
12-
:keyword connection: The connection to use, will be automatically created if
13-
not given
13+
:keyword connection: The connection to use, will be automatically created
14+
if not given
1415
:type connection: :class:`~statsd.connection.Connection`
1516
1617
>>> client = Client('test')

statsd/compat.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
"""
2-
Compatability library for python2 and python3 support.
3-
"""
1+
'''
2+
Compatibility library for python2 and python3 support.
3+
'''
44
import sys
55
import decimal
66

77
PY3K = sys.version_info >= (3, 0)
88

9+
910
def iter_dict(dict_): # pragma: no cover
1011
if PY3K:
1112
return dict_.items()

statsd/gauge.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44

55

66
class Gauge(statsd.Client):
7-
'''Class to implement a statsd gauge
87

9-
'''
8+
'Class to implement a statsd gauge'
109

1110
def _send(self, subname, value):
1211
'''Send the data to statsd via self.connection
@@ -98,20 +97,22 @@ def __sub__(self, delta):
9897
return self
9998

10099
def set(self, subname, value):
101-
'''Set the data ignoring the sign, ie set("test", -1) will
102-
set "test" exactly to -1 (not decrement it by 1)
103-
104-
See
105-
https://github.com/etsy/statsd/blob/master/docs/metric_types.md
100+
'''
101+
Set the data ignoring the sign, ie set("test", -1) will set "test"
102+
exactly to -1 (not decrement it by 1)
103+
104+
See https://github.com/etsy/statsd/blob/master/docs/metric_types.md
106105
"Adding a sign to the gauge value will change the value, rather
107-
than setting it.
108-
gaugor:-10|g
109-
gaugor:+4|g
110-
So if gaugor was 333, those commands would set it to 333 - 10 + 4,
111-
or 327.
112-
Note:
113-
This implies you can't explicitly set a gauge to a negative number
114-
without first setting it to zero."
106+
than setting it.
107+
108+
gaugor:-10|g
109+
gaugor:+4|g
110+
111+
So if gaugor was 333, those commands would set it to 333 - 10 + 4, or
112+
327.
113+
114+
Note: This implies you can't explicitly set a gauge to a negative
115+
number without first setting it to zero."
115116
116117
:keyword subname: The subname to report the data to (appended to the
117118
client name)

statsd/timer.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import contextlib
22
import time
3-
from functools import wraps
3+
from functools import wraps, partial
44

55
import statsd
66

77

88
class Timer(statsd.Client):
9+
910
'''
1011
Statsd Timer Object
1112
@@ -14,11 +15,11 @@ class Timer(statsd.Client):
1415
1516
:keyword name: The name for this timer
1617
:type name: str
17-
:keyword connection: The connection to use, will be automatically created if
18-
not given
18+
:keyword connection: The connection to use, will be automatically created
19+
if not given
1920
:type connection: :class:`~statsd.connection.Connection`
20-
:keyword min_send_threshold: Timings smaller than this will not be sent so -1
21-
can be used for all.
21+
:keyword min_send_threshold: Timings smaller than this will not be sent so
22+
-1 can be used for all.
2223
:type min_send_threshold: int
2324
2425
>>> timer = Timer('application_name').start()
@@ -127,7 +128,7 @@ def decorate(self, function_or_name):
127128
if callable(function_or_name):
128129
return self._decorate(function_or_name.__name__, function_or_name)
129130
else:
130-
return lambda f: self._decorate(function_or_name, f)
131+
return partial(self._decorate, function_or_name)
131132

132133
@contextlib.contextmanager
133134
def time(self, subname=None, class_=None):

tests/test_client.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import statsd
22
from unittest import TestCase
33

4+
45
class TestClient(TestCase):
6+
57
def test_average_shortcut(self):
68
average = statsd.Client('average').get_average()
79
assert isinstance(average, statsd.Average)

tests/test_connection.py

+4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
import statsd
33
import unittest
44

5+
56
class ConnectionException(Exception):
7+
68
pass
79

10+
811
class TestConnection(unittest.TestCase):
12+
913
def test_set_disabled_to_false_by_default(self):
1014
result = statsd.connection.Connection()
1115
assert result._disabled is False

tests/test_gauge.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ def setUp(self):
1313
def test_send_float(self):
1414
with mock.patch('statsd.Client') as mock_client:
1515
self.gauge.send('', 10.5)
16-
mock_client._send.assert_called_with(mock.ANY, {'testing': '10.5|g'})
16+
mock_client._send.assert_called_with(mock.ANY,
17+
{'testing': '10.5|g'})
1718

1819
def test_send_decimal(self):
1920
with mock.patch('statsd.Client') as mock_client:
2021
self.gauge.send('', Decimal('6.576'))
21-
mock_client._send.assert_called_with(mock.ANY, {'testing': '6.576|g'})
22+
mock_client._send.assert_called_with(mock.ANY,
23+
{'testing': '6.576|g'})
2224

2325
def test_send_integer(self):
2426
with mock.patch('statsd.Client') as mock_client:
2527
self.gauge.send('', 1)
26-
mock_client._send.assert_called_with(mock.ANY, {'testing': '1|g'})
28+
mock_client._send.assert_called_with(mock.ANY,
29+
{'testing': '1|g'})
2730

2831
def test_set(self):
2932
with mock.patch('statsd.Client') as mock_client:

tests/test_timer.py

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66

77
class TestTimerBase(TestCase):
8+
89
def tearDown(self):
910
self._time_patch.stop()
1011

@@ -16,6 +17,7 @@ def get_arg(self, mock_client, key):
1617

1718

1819
class TestTimerDecorator(TestTimerBase):
20+
1921
def setUp(self):
2022
self.timer = statsd.Timer('timer')
2123

@@ -149,6 +151,7 @@ def test_timer_intermediate(self, mock_client):
149151

150152

151153
class TestTimerZero(TestTimerBase):
154+
152155
def setUp(self):
153156
# get time.time() to always return the same value so that this test
154157
# isn't system load dependant.

tox.ini

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[tox]
2-
envlist = py26, py27, py34, pypy, pypy3
2+
envlist = py26, py27, py34, py35, pypy, pypy3, flake8, docs
3+
skip_missing_interpreters = True
34

45
[testenv]
56
deps =
@@ -11,3 +12,14 @@ commands =
1112
python setup.py nosetests --cover-erase --with-coverage
1213
nosetests --with-coverage --cover-min-percentage=100
1314

15+
[testenv:flake8]
16+
deps = flake8
17+
commands = flake8 --ignore=W391 statsd
18+
19+
[testenv:docs]
20+
deps = sphinx
21+
basepython=python
22+
changedir=docs
23+
commands=
24+
sphinx-build -W -b html -d {envtmpdir}/doctrees . {envtmpdir}/html
25+

0 commit comments

Comments
 (0)