Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop unsupported pythons #1

Merged
merged 2 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
language: python
python:
- "2.7"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- "pypy"
- "3.9"
- "3.10"
- "pypy3"
dist: focal
install:
- pip install -q "flake8"
- pip install -r requirements.txt
script:
- nosetests --with-coverage --cover-package=statsd
- pytest statsd/tests.py
- flake8 statsd/
17 changes: 8 additions & 9 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Python StatsD documentation build configuration file, created by
# sphinx-quickstart on Mon Apr 9 15:47:23 2012.
Expand Down Expand Up @@ -40,8 +39,8 @@
master_doc = 'index'

# General information about the project.
project = u'Python StatsD'
copyright = u'2015, James Socol'
project = 'Python StatsD'
copyright = '2015, James Socol'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
Expand Down Expand Up @@ -183,8 +182,8 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'PythonStatsD.tex', u'Python StatsD Documentation',
u'James Socol', 'manual'),
('index', 'PythonStatsD.tex', 'Python StatsD Documentation',
'James Socol', 'manual'),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -213,8 +212,8 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'pythonstatsd', u'Python StatsD Documentation',
[u'James Socol'], 1)
('index', 'pythonstatsd', 'Python StatsD Documentation',
['James Socol'], 1)
]

# If true, show URL addresses after external links.
Expand All @@ -227,8 +226,8 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'PythonStatsD', u'Python StatsD Documentation',
u'James Socol', 'PythonStatsD', 'One line description of project.',
('index', 'PythonStatsD', 'Python StatsD Documentation',
'James Socol', 'PythonStatsD', 'One line description of project.',
'Miscellaneous'),
]

Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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, 3.4, and
PyPy, if they're available.
Tox will run the tests in Pythons 3.7, 3.8, 3.9, 3.10 and
PyPy3, if they're available.


Writing Tests
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
mock==1.0.1
nose==1.2.1
flake8==1.7.0
flake8>=4.0
pytest>=6.2.5
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
include_package_data=True,
package_data={'': ['README.rst']},
test_suite='nose.collector',
python_requires='>=3.7',
classifiers=[
'Development Status :: 5 - Production/Stable',
'Environment :: Web Environment',
'Intended Audience :: Developers',
'License :: OSI Approved :: MIT License',
'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',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development :: Libraries :: Python Modules',
],
)
2 changes: 0 additions & 2 deletions statsd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from .client import StatsClient
from .client import TCPStatsClient
from .client import UnixSocketStatsClient
Expand Down
2 changes: 0 additions & 2 deletions statsd/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
from __future__ import absolute_import, division, unicode_literals

from .stream import TCPStatsClient, UnixSocketStatsClient # noqa
from .udp import StatsClient # noqa
12 changes: 5 additions & 7 deletions statsd/client/base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
from __future__ import absolute_import, division, unicode_literals

import random
from collections import deque
from datetime import timedelta

from .timer import Timer


class StatsClientBase(object):
class StatsClientBase:
"""A Base class for various statsd clients."""

def close(self):
Expand Down Expand Up @@ -53,7 +51,7 @@ def gauge(self, stat, value, rate=1, delta=False):
pipe._send_stat(stat, '%s|g' % value, 1)
else:
prefix = '+' if delta and value >= 0 else ''
self._send_stat(stat, '%s%s|g' % (prefix, value), rate)
self._send_stat(stat, f'{prefix}{value}|g', rate)

def set(self, stat, value, rate=1):
"""Set a set value."""
Expand All @@ -66,12 +64,12 @@ def _prepare(self, stat, value, rate):
if rate < 1:
if random.random() > rate:
return
value = '%s|@%s' % (value, rate)
value = f'{value}|@{rate}'

if self._prefix:
stat = '%s.%s' % (self._prefix, stat)
stat = f'{self._prefix}.{stat}'

return '%s:%s' % (stat, value)
return f'{stat}:{value}'

def _after(self, data):
if data:
Expand Down
2 changes: 0 additions & 2 deletions statsd/client/stream.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

import socket

from .base import StatsClientBase, PipelineBase
Expand Down
4 changes: 1 addition & 3 deletions statsd/client/timer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

import functools

# Use timer that's not susceptible to time of day adjustments.
Expand All @@ -18,7 +16,7 @@ def safe_wraps(wrapper, *args, **kwargs):
return functools.wraps(wrapper, *args, **kwargs)


class Timer(object):
class Timer:
"""A context manager/decorator for statsd.timing()."""

def __init__(self, client, stat, rate=1):
Expand Down
6 changes: 2 additions & 4 deletions statsd/client/udp.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import, division, unicode_literals

import socket

from .base import StatsClientBase, PipelineBase
Expand All @@ -8,7 +6,7 @@
class Pipeline(PipelineBase):

def __init__(self, client):
super(Pipeline, self).__init__(client)
super().__init__(client)
self._maxudpsize = client._maxudpsize

def _send(self):
Expand Down Expand Up @@ -42,7 +40,7 @@ def _send(self, data):
"""Send data to statsd."""
try:
self._sock.sendto(data.encode('ascii'), self._addr)
except (socket.error, RuntimeError):
except (OSError, RuntimeError):
# No time for love, Dr. Jones!
pass

Expand Down
1 change: 0 additions & 1 deletion statsd/defaults/django.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from django.conf import settings

from statsd import defaults
Expand Down
1 change: 0 additions & 1 deletion statsd/defaults/env.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import os

from statsd import defaults
Expand Down
44 changes: 19 additions & 25 deletions statsd/tests.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
from __future__ import with_statement
import functools
import random
import re
import socket
from datetime import timedelta
from unittest import SkipTest

import mock
from nose.tools import eq_
from unittest import mock

from statsd import StatsClient
from statsd import TCPStatsClient
Expand Down Expand Up @@ -66,25 +63,22 @@ def _unix_socket_client(prefix=None, socket_path=None):

def _timer_check(sock, count, proto, start, end):
send = send_method[proto](sock)
eq_(send.call_count, count)
assert send.call_count == count
value = send.call_args[0][0].decode('ascii')
exp = re.compile(r'^%s:\d+|%s$' % (start, end))
exp = re.compile(fr'^{start}:\d+|{end}$')
assert exp.match(value)


def _sock_check(sock, count, proto, val=None, addr=None):
send = send_method[proto](sock)
eq_(send.call_count, count)
assert send.call_count == count
if not addr:
addr = ADDR
if val is not None:
eq_(
send.call_args,
make_val[proto](val, addr),
)
assert send.call_args == make_val[proto](val, addr)


class assert_raises(object):
class assert_raises:
"""A context manager that asserts a given exception was raised.

>>> with assert_raises(TypeError):
Expand Down Expand Up @@ -131,7 +125,7 @@ def __enter__(self):

def __exit__(self, typ, value, tb):
assert typ, 'No exception raised.'
assert typ in self.exc_cls, '%s not in %s' % (
assert typ in self.exc_cls, '{} not in {}'.format(
typ.__name__, [e.__name__ for e in self.exc_cls])
self.exc_type = typ
self.exception = value
Expand Down Expand Up @@ -443,7 +437,7 @@ def _test_prepare(cl, proto):

def _check(o, s, v, r):
with mock.patch.object(random, 'random', lambda: -1):
eq_(o, cl._prepare(s, v, r))
assert o == cl._prepare(s, v, r)

for o, (s, v, r) in tests:
_check(o, s, v, r)
Expand Down Expand Up @@ -519,13 +513,13 @@ def bar(a, b):

# make sure it works with more than one decorator, called multiple
# times, and that parameters are handled correctly
eq_([4, 2], foo(4, 2))
assert [4, 2] == foo(4, 2)
_timer_check(cl._sock, 1, proto, 'foo', 'ms')

eq_([2, 4], bar(4, 2))
assert [2, 4] == bar(4, 2)
_timer_check(cl._sock, 2, proto, 'bar', 'ms')

eq_([6, 5], bar(5, 6))
assert [6, 5] == bar(5, 6)
_timer_check(cl._sock, 3, proto, 'bar', 'ms')


Expand All @@ -543,7 +537,7 @@ def test_timer_decorator_tcp():

def _test_timer_capture(cl, proto):
with cl.timer('woo') as result:
eq_(result.ms, None)
assert result.ms is None
assert isinstance(result.ms, float)


Expand Down Expand Up @@ -587,7 +581,7 @@ def test_timer_decorator_partial_function():
foo = functools.partial(lambda x: x * x, 2)
func = cl.timer('foo')(foo)

eq_(4, func())
assert 4 == func()

_timer_check(cl._sock, 1, 'tcp', 'foo', 'ms|@0.1')

Expand All @@ -601,10 +595,10 @@ def foo(a, b):
def bar(a, b=2, c=3):
return [c, b, a]

eq_([2, 4], foo(4, 2))
assert [2, 4] == foo(4, 2)
_timer_check(cl._sock, 1, proto, 'foo', 'ms|@0.1')

eq_([3, 2, 5], bar(5))
assert [3, 2, 5] == bar(5)
_timer_check(cl._sock, 2, proto, 'bar', 'ms|@0.2')


Expand Down Expand Up @@ -906,8 +900,8 @@ def test_pipeline_timer_object_tcp():
def _test_pipeline_empty(cl):
with cl.pipeline() as pipe:
pipe.incr('foo')
eq_(1, len(pipe._stats))
eq_(0, len(pipe._stats))
assert 1 == len(pipe._stats)
assert 0 == len(pipe._stats)


def test_pipeline_empty_udp():
Expand Down Expand Up @@ -1006,7 +1000,7 @@ def test_pipeline_packet_size():
# 32 * 16 = 512, so this will need 2 packets.
pipe.incr('sixteen_char_str')
pipe.send()
eq_(2, sc._sock.sendto.call_count)
assert 2 == sc._sock.sendto.call_count
assert len(sc._sock.sendto.call_args_list[0][0][0]) <= 512
assert len(sc._sock.sendto.call_args_list[1][0][0]) <= 512

Expand All @@ -1017,7 +1011,7 @@ def test_tcp_raises_exception_to_user(mock_socket):
addr = ('127.0.0.1', 1234)
cl = _tcp_client(addr=addr[0], port=addr[1])
cl.incr('foo')
eq_(1, cl._sock.sendall.call_count)
assert 1 == cl._sock.sendall.call_count
cl._sock.sendall.side_effect = socket.error
with assert_raises(socket.error):
cl.incr('foo')
Expand Down
7 changes: 3 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ envlist = py27,pypy,py34,py35,py36,py37

[testenv]
deps=
mock==1.0.1
nose==1.2.1
coverage==3.5.2
coverage>=6.0
pytest>=6.2.5

commands=
nosetests statsd --with-coverage --cover-package=statsd []
pytest statsd/tests.py