diff options
author | James Socol <me@jamessocol.com> | 2014-05-09 11:34:55 -0400 |
---|---|---|
committer | James Socol <me@jamessocol.com> | 2014-05-09 11:34:55 -0400 |
commit | bc6ab7b576b5b9b9662bfd426c1e319aa4d9013d (patch) | |
tree | d71b3718b1aa440863f2aa30286934e930d07528 | |
parent | 269565b9fa5eab7069a162f68f9aaf2ac5341799 (diff) | |
parent | 6970d7fcea3bc6766502d8e4be89072019ba4e63 (diff) | |
download | pystatsd-bc6ab7b576b5b9b9662bfd426c1e319aa4d9013d.tar.gz |
Merge branch 'branch-3.x'v3.0
-rw-r--r-- | .travis.yml | 2 | ||||
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | docs/conf.py | 4 | ||||
-rw-r--r-- | docs/configure.rst | 26 | ||||
-rw-r--r-- | docs/contributing.rst | 4 | ||||
-rw-r--r-- | docs/reference.rst | 1 | ||||
-rw-r--r-- | docs/timing.rst | 12 | ||||
-rw-r--r-- | setup.py | 7 | ||||
-rw-r--r-- | statsd/__init__.py | 40 | ||||
-rw-r--r-- | statsd/defaults/__init__.py | 4 | ||||
-rw-r--r-- | statsd/defaults/django.py | 15 | ||||
-rw-r--r-- | statsd/defaults/env.py | 15 | ||||
-rw-r--r-- | statsd/tests.py | 2 | ||||
-rw-r--r-- | tox.ini | 2 |
14 files changed, 72 insertions, 68 deletions
diff --git a/.travis.yml b/.travis.yml index 4f70a82..9208899 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ python: - "2.7" - "3.2" - "3.3" + - "3.4" - "pypy" -install: pip install -r requirements.txt --use-mirrors script: nosetests @@ -1,6 +1,12 @@ Statsd Changelog ================ +Version 3.0 +----------- + +- Moved default client instances out of __init__.py. Now find them in + the `statsd.defaults.{django,env}` modules. + Version 2.1.2 ------------- diff --git a/docs/conf.py b/docs/conf.py index d0ec1dc..4e75a4b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -48,9 +48,9 @@ copyright = u'2014, James Socol' # built documents. # # The short X.Y version. -version = '2.1' +version = '3.0' # The full version, including alpha/beta/rc tags. -release = '2.1.2' +release = '3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/configure.rst b/docs/configure.rst index 752898a..bc945e3 100644 --- a/docs/configure.rst +++ b/docs/configure.rst @@ -77,39 +77,35 @@ Here are the settings and their defaults:: You can use the default ``StatsClient`` simply:: - from statsd import statsd + from statsd.defaults.django import statsd statsd.incr('foo') -This instance will use the settings, if provided by Django. If no Django -settings can be imported, it won't be available. - From the Environment ==================== Statsd isn't only useful in Django or on the web. A default instance -will also be available if you configure at least two environment -variables. These do not have defaults. +can also be configured via environment variables. -You can set these variables in the environment:: +Here are the environment variables and their defaults:: - STATSD_HOST - STATSD_PORT - STATSD_PREFIX - STATSD_MAXUDPSIZE + STATSD_HOST=localhost + STATSD_PORT=8125 + STATSD_PREFIX=None + STATSD_MAXUDPSIZE=512 and then in your Python application, you can simply do:: - from statsd import statsd + from statsd.defaults.env import statsd statsd.incr('foo') .. note:: - To make this default instance available, you will need to set at - least ``STATSD_HOST`` and ``STATSD_PORT``, even if using the default - values of ``localhost`` and ``8125``. + As of version 3.0, this default instance is always available, + configured with the default values, unless overridden by the + environment. .. _statsd: https://github.com/etsy/statsd .. _Django: https://www.djangoproject.com/ diff --git a/docs/contributing.rst b/docs/contributing.rst index 08cf6e5..f700d5b 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -36,8 +36,8 @@ You can also run the tests with tox:: $ tox -Tox will run the tests in Pythons 2.5, 2.6, 2.7, 3.2, 3.3, and PyPy, if -they're available. +Tox will run the tests in Pythons 2.5, 2.6, 2.7, 3.2, 3.3, 3.4, and +PyPy, if they're available. Writing Tests diff --git a/docs/reference.rst b/docs/reference.rst index 651944e..0c0202e 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -277,3 +277,4 @@ stats. .. _statsd: https://github.com/etsy/statsd .. _0ed78be: https://github.com/etsy/statsd/commit/0ed78be7 +.. _1c10cfc0ac: https://github.com/etsy/statsd/commit/1c10cfc0ac diff --git a/docs/timing.rst b/docs/timing.rst index 051f42e..ed85481 100644 --- a/docs/timing.rst +++ b/docs/timing.rst @@ -96,7 +96,7 @@ better than nested.) # Do something fun. foo_timer.stop() -When :py:meth:`statsd.client.Timer.stop` is called, a `timing stat +When :py:meth:`statsd.client.Timer.stop` is called, a :ref:`timing stat <timer-type>`_ will automatically be sent to StatsD. You can over ride this behavior with the ``send=False`` keyword argument to ``stop()``:: @@ -109,11 +109,11 @@ ready. .. _timer-direct-note: .. note:: - This use of timers is compatible with `Pipelines <pipeline-chapter>`_ - but be careful with the ``send()`` method. It *must* be called for - the stat to be included when the Pipeline finally sends data, but - ``send()`` will *not* immediately cause data to be sent in the - context of a Pipeline. For example:: + This use of timers is compatible with :ref:`Pipelines + <pipeline-chapter>`_ but be careful with the ``send()`` method. It + *must* be called for the stat to be included when the Pipeline + finally sends data, but ``send()`` will *not* immediately cause data + to be sent in the context of a Pipeline. For example:: with statsd.pipeline() as pipe: foo_timer = pipe.timer('foo').start() @@ -5,7 +5,7 @@ from setuptools import find_packages, setup setup( name='statsd', - version='2.1.2', + version='3.0', description='A simple statsd client.', long_description=open('README.rst').read(), author='James Socol', @@ -15,6 +15,7 @@ setup( packages=find_packages(), include_package_data=True, package_data={'': ['README.rst']}, + test_suite='nose.collector', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', @@ -28,6 +29,8 @@ setup( 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.2', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', 'Topic :: Software Development :: Libraries :: Python Modules', - ] + ], ) diff --git a/statsd/__init__.py b/statsd/__init__.py index 444eab7..cee708f 100644 --- a/statsd/__init__.py +++ b/statsd/__init__.py @@ -1,44 +1,8 @@ from __future__ import absolute_import -import os -import socket - -try: - from django.conf import settings - from django.core.exceptions import ImproperlyConfigured - try: - # This handles the case where Django >=1.5 is in the python path - # but this particular project is not a django project. In - # that case, settings aren't configured. - getattr(settings, 'STATSD_HOST', 'localhost') - except ImproperlyConfigured: - settings = None -except ImportError: - settings = None from .client import StatsClient -VERSION = (2, 1, 2) +VERSION = (3, 0) __version__ = '.'.join(map(str, VERSION)) -__all__ = ['StatsClient', 'statsd'] - -statsd = None - -if settings: - try: - host = getattr(settings, 'STATSD_HOST', 'localhost') - port = getattr(settings, 'STATSD_PORT', 8125) - prefix = getattr(settings, 'STATSD_PREFIX', None) - maxudpsize = getattr(settings, 'STATSD_MAXUDPSIZE', 512) - statsd = StatsClient(host, port, prefix, maxudpsize) - except (socket.error, socket.gaierror, ImportError): - pass -elif 'STATSD_HOST' in os.environ: - try: - host = os.environ['STATSD_HOST'] - port = int(os.environ['STATSD_PORT']) - prefix = os.environ.get('STATSD_PREFIX') - maxudpsize = int(os.environ.get('STATSD_MAXUDPSIZE', 512)) - statsd = StatsClient(host, port, prefix, maxudpsize) - except (socket.error, socket.gaierror, KeyError): - pass +__all__ = ['StatsClient'] diff --git a/statsd/defaults/__init__.py b/statsd/defaults/__init__.py new file mode 100644 index 0000000..2f2de3b --- /dev/null +++ b/statsd/defaults/__init__.py @@ -0,0 +1,4 @@ +HOST = 'localhost' +PORT = 8125 +PREFIX = None +MAXUDPSIZE = 512 diff --git a/statsd/defaults/django.py b/statsd/defaults/django.py new file mode 100644 index 0000000..c4c2951 --- /dev/null +++ b/statsd/defaults/django.py @@ -0,0 +1,15 @@ +from __future__ import absolute_import +from django.conf import settings + +from statsd import defaults +from statsd.client import StatsClient + + +statsd = None + +if statsd is None: + host = getattr(settings, 'STATSD_HOST', defaults.HOST) + port = getattr(settings, 'STATSD_PORT', defaults.PORT) + prefix = getattr(settings, 'STATSD_PREFIX', defaults.PREFIX) + maxudpsize = getattr(settings, 'STATSD_MAXUDPSIZE', defaults.MAXUDPSIZE) + statsd = StatsClient(host, port, prefix, maxudpsize) diff --git a/statsd/defaults/env.py b/statsd/defaults/env.py new file mode 100644 index 0000000..eb857f9 --- /dev/null +++ b/statsd/defaults/env.py @@ -0,0 +1,15 @@ +from __future__ import absolute_import +import os + +from statsd import defaults +from statsd.client import StatsClient + + +statsd = None + +if statsd is None: + host = os.getenv('STATSD_HOST', defaults.HOST) + port = int(os.getenv('STATSD_PORT', defaults.PORT)) + prefix = os.getenv('STATSD_PREFIX', defaults.PREFIX) + maxudpsize = int(os.getenv('STATSD_MAXUDPSIZE', defaults.MAXUDPSIZE)) + statsd = StatsClient(host, port, prefix, maxudpsize) diff --git a/statsd/tests.py b/statsd/tests.py index fc51af5..da52182 100644 --- a/statsd/tests.py +++ b/statsd/tests.py @@ -158,7 +158,7 @@ def test_gauge_absolute_negative_rate(mock_random): mock_random.return_value = -1 sc.gauge('foo', -1, rate=0.5, delta=False) _sock_check(sc, 1, 'foo:0|g\nfoo:-1|g') - + mock_random.return_value = 2 sc.gauge('foo', -2, rate=0.5, delta=False) _sock_check(sc, 1, 'foo:0|g\nfoo:-1|g') # Should not have changed. @@ -1,5 +1,5 @@ [tox] -envlist = py26,py27,pypy,py32,py33 +envlist = py26,py27,pypy,py32,py33,py34 [testenv] deps= |