Skip to content

Commit 0cc45fe

Browse files
khasanovbinoxiouz
authored andcommitted
Fix tests, deprecate io_loop passing (#79)
* fix: Fix tests, remove unnecessary instructions, fixate tornado version. `--egg` param removed in pip 10.0 pypa/pip#1749 * feat: Deprecate io_loop args for new tornado support. http://www.tornadoweb.org/en/stable/releases/v5.0.0.html
1 parent 55d6dd0 commit 0cc45fe

File tree

12 files changed

+58
-29
lines changed

12 files changed

+58
-29
lines changed

.travis.yml

-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ services:
1212
- docker
1313

1414
before_install:
15-
- sudo apt-get -qq update
16-
- sudo apt-get install zookeeper zookeeperd -y
17-
- sudo pip install cocaine cocaine-tools
18-
- docker pull noxiouz/cocaine
1915
- docker run -d --net=host noxiouz/cocaine && docker ps
2016

2117
install:

cocaine/detail/baseservice.py

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import itertools
2323
import socket
2424
import time
25+
import warnings
2526
import weakref
2627

2728
import six
@@ -76,6 +77,8 @@ def set_keep_alive(sock, idle=10, interval=5, fails=5):
7677

7778
class BaseService(object):
7879
def __init__(self, name, endpoints, io_loop=None):
80+
if io_loop:
81+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
7982
# If it's not the main thread
8083
# and a current IOloop doesn't exist here,
8184
# IOLoop.instance becomes self._io_loop

cocaine/detail/channel.py

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import datetime
2222
import logging
23+
import warnings
2324

2425
import six
2526

@@ -123,6 +124,8 @@ def __init__(self, rx_tree, session_id, header_table=None, io_loop=None, service
123124
if header_table is None:
124125
header_table = CocaineHeaders()
125126

127+
if io_loop:
128+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
126129
# If it's not the main thread
127130
# and a current IOloop doesn't exist here,
128131
# IOLoop.instance becomes self._io_loop

cocaine/detail/iotimer.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
# You should have received a copy of the GNU Lesser General Public License
1919
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
#
21+
import warnings
2122

22-
from tornado.ioloop import PeriodicCallback
23+
from tornado.ioloop import IOLoop, PeriodicCallback
2324

2425

2526
class Timer(PeriodicCallback):
26-
def __init__(self, callback, callback_time, io_loop):
27+
def __init__(self, callback, callback_time, io_loop=None):
28+
if io_loop:
29+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
30+
io_loop = io_loop or IOLoop.current()
2731
super(Timer, self).__init__(callback, callback_time * 1000, io_loop)

cocaine/detail/locator.py

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# You should have received a copy of the GNU Lesser General Public License
1818
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1919
#
20+
import warnings
2021

2122
from .api import API
2223
from .baseservice import BaseService
@@ -27,6 +28,8 @@
2728

2829
class Locator(BaseService):
2930
def __init__(self, endpoints=LOCATOR_DEFAULT_ENDPOINTS, io_loop=None):
31+
if io_loop:
32+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
3033
super(Locator, self).__init__(name="locator",
3134
endpoints=endpoints, io_loop=io_loop)
3235
self.api = API.Locator

cocaine/detail/logger.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import json
2525
import logging
2626
import threading
27+
import warnings
2728

2829
import six
2930
from six.moves import cStringIO as BytesIO
@@ -87,6 +88,8 @@ def __new__(cls, *args, **kwargs):
8788

8889
@thread_once
8990
def __init__(self, endpoints=LOCATOR_DEFAULT_ENDPOINTS, io_loop=None):
91+
if io_loop:
92+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
9093
self.io_loop = io_loop or IOLoop.current()
9194
self.endpoints = endpoints
9295
self._lock = Lock()
@@ -268,7 +271,8 @@ def __del__(self):
268271

269272
@coroutine
270273
def resolve_logging(endpoints, name="logging", io_loop=None):
271-
io_loop = io_loop or IOLoop.current()
274+
if io_loop:
275+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
272276

273277
for host, port in endpoints:
274278
buff = msgpack_unpacker()
@@ -303,7 +307,7 @@ def emit(self, record):
303307
lvl = record.levelno
304308
extra = getattr(record, "extra", {})
305309
if lvl >= logging.ERROR:
306-
# to avoid message formating
310+
# to avoid message formatting
307311
if self._logger.enable_for(ERROR_LEVEL):
308312
self._logger.error(self.format(record), extra=extra)
309313
elif lvl >= logging.WARNING:

cocaine/detail/service.py

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
# You should have received a copy of the GNU Lesser General Public License
1919
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2020
#
21+
import warnings
2122

2223
from .baseservice import BaseService
2324
from .defaults import Defaults
@@ -34,6 +35,8 @@
3435
class Service(BaseService):
3536
def __init__(self, name, endpoints=LOCATOR_DEFAULT_ENDPOINT,
3637
seed=None, version=0, locator=None, io_loop=None, timeout=0):
38+
if io_loop:
39+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
3740
super(Service, self).__init__(name=name, endpoints=LOCATOR_DEFAULT_ENDPOINT, io_loop=io_loop)
3841
self.locator_endpoints = endpoints
3942
self.locator = locator

cocaine/futures/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#
2121

2222
import threading
23+
import warnings
2324

2425
from tornado.concurrent import Future
2526
from tornado.ioloop import IOLoop
@@ -31,6 +32,8 @@
3132
class ConcurrentWorker(object):
3233
def __init__(self, func, io_loop=None, args=(), kwargs=None):
3334
self._func = func
35+
if io_loop:
36+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
3437
self._io_loop = io_loop or IOLoop.current()
3538
self._args = args
3639
self._kwargs = kwargs or {}
@@ -53,5 +56,5 @@ def execute(self):
5356

5457
def threaded(func):
5558
def wrapper(*args, **kwargs):
56-
return ConcurrentWorker(func, io_loop=None, args=args, kwargs=kwargs).execute()
59+
return ConcurrentWorker(func, args=args, kwargs=kwargs).execute()
5760
return wrapper

cocaine/worker/worker.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#
2121
import logging
2222
import socket
23+
import warnings
2324

2425
import six
2526

@@ -71,7 +72,10 @@ def token(self):
7172

7273

7374
class TicketVendingMachineTokenManager(TokenManager):
74-
def __init__(self, name, ticket, interval, loop):
75+
def __init__(self, name, ticket, interval, loop=None):
76+
if loop:
77+
warnings.warn('loop argument is deprecated.', DeprecationWarning)
78+
loop = loop or IOLoop.current()
7579
self._name = name
7680
self._ticket = ticket
7781
self._service = Service('tvm')
@@ -100,7 +104,10 @@ def _refresh(self):
100104
yield now
101105

102106

103-
def make_token_manager(name, token, loop):
107+
def make_token_manager(name, token, loop=None):
108+
if loop:
109+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
110+
loop = loop or IOLoop.current()
104111
if token.ty == 'TVM':
105112
return TicketVendingMachineTokenManager(name, token.body, 10.0, loop)
106113
else:
@@ -111,14 +118,15 @@ class BasicWorker(object):
111118
def __init__(self, disown_timeout=DEFAULT_DISOWN_TIMEOUT,
112119
heartbeat_timeout=DEFAULT_HEARTBEAT_TIMEOUT,
113120
io_loop=None, app=None, uuid=None, endpoint=None):
114-
115121
if heartbeat_timeout < disown_timeout:
116122
raise ValueError("heartbeat timeout must be greater than disown")
117123

118124
self.appname = app or Defaults.app
119125
self.uuid = uuid or Defaults.uuid
120126
self.endpoint = endpoint or Defaults.endpoint
121127

128+
if io_loop:
129+
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
122130
self.io_loop = io_loop or IOLoop.current()
123131
self._token_manager = make_token_manager(
124132
self.appname,

requirements.txt

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
msgpack-python
2-
six <= 1.10
3-
tornado>=4.2
1+
2+
msgpack
3+
six >= 1.9,<= 1.10
4+
tornado >=4.2,<5
5+
6+
7+
8+
9+

tests/runtime.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@
4242
class RuntimeMock(tcpserver.TCPServer):
4343
_msgpack_string_encoding = None if sys.version_info[0] == 2 else 'utf8'
4444

45-
def __init__(self, unixsocket, io_loop=None):
46-
super(RuntimeMock, self).__init__(io_loop=io_loop or ioloop.IOLoop.current())
47-
self.io_loop = io_loop or ioloop.IOLoop.current()
45+
def __init__(self, unixsocket):
46+
super(RuntimeMock, self).__init__()
4847
self.actions = list()
4948
self.counter = 1
5049
self.endpoint = unixsocket

tox.ini

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
[tox]
22
envlist = flake8,
3-
py27,
4-
py34,
5-
py35,
6-
py36
7-
pypy
3+
py27,
4+
py34,
5+
py35,
6+
py36,
7+
pypy
88
skip_missing_interpreters = True
99

1010

@@ -21,16 +21,13 @@ exclude = .tox,.git,build/,examples/,tests/,*.egg/,docs/
2121

2222

2323
[testenv]
24-
# Install eggs
25-
install_command = pip install --egg {opts} {packages}
2624
deps = -rtests/requirements.txt
2725
commands = python setup.py nosetests --cover-min-percentage=0
2826

2927

3028
[testenv:flake8]
31-
install_command = pip install {opts} {packages}
3229
deps = flake8
33-
flake8-import-order
34-
flake8-blind-except
35-
pep8-naming
30+
flake8-import-order
31+
flake8-blind-except
32+
pep8-naming
3633
commands = flake8 {toxinidir}

0 commit comments

Comments
 (0)