Skip to content

Commit

Permalink
Fix tests, deprecate io_loop passing (#79)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
khasanovbi authored and noxiouz committed May 31, 2018
1 parent 55d6dd0 commit 0cc45fe
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 29 deletions.
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ services:
- docker

before_install:
- sudo apt-get -qq update
- sudo apt-get install zookeeper zookeeperd -y
- sudo pip install cocaine cocaine-tools
- docker pull noxiouz/cocaine
- docker run -d --net=host noxiouz/cocaine && docker ps

install:
Expand Down
3 changes: 3 additions & 0 deletions cocaine/detail/baseservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import itertools
import socket
import time
import warnings
import weakref

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

class BaseService(object):
def __init__(self, name, endpoints, io_loop=None):
if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
# If it's not the main thread
# and a current IOloop doesn't exist here,
# IOLoop.instance becomes self._io_loop
Expand Down
3 changes: 3 additions & 0 deletions cocaine/detail/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import datetime
import logging
import warnings

import six

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

if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
# If it's not the main thread
# and a current IOloop doesn't exist here,
# IOLoop.instance becomes self._io_loop
Expand Down
8 changes: 6 additions & 2 deletions cocaine/detail/iotimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import warnings

from tornado.ioloop import PeriodicCallback
from tornado.ioloop import IOLoop, PeriodicCallback


class Timer(PeriodicCallback):
def __init__(self, callback, callback_time, io_loop):
def __init__(self, callback, callback_time, io_loop=None):
if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
io_loop = io_loop or IOLoop.current()
super(Timer, self).__init__(callback, callback_time * 1000, io_loop)
3 changes: 3 additions & 0 deletions cocaine/detail/locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import warnings

from .api import API
from .baseservice import BaseService
Expand All @@ -27,6 +28,8 @@

class Locator(BaseService):
def __init__(self, endpoints=LOCATOR_DEFAULT_ENDPOINTS, io_loop=None):
if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
super(Locator, self).__init__(name="locator",
endpoints=endpoints, io_loop=io_loop)
self.api = API.Locator
8 changes: 6 additions & 2 deletions cocaine/detail/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import json
import logging
import threading
import warnings

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

@thread_once
def __init__(self, endpoints=LOCATOR_DEFAULT_ENDPOINTS, io_loop=None):
if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
self.io_loop = io_loop or IOLoop.current()
self.endpoints = endpoints
self._lock = Lock()
Expand Down Expand Up @@ -268,7 +271,8 @@ def __del__(self):

@coroutine
def resolve_logging(endpoints, name="logging", io_loop=None):
io_loop = io_loop or IOLoop.current()
if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)

for host, port in endpoints:
buff = msgpack_unpacker()
Expand Down Expand Up @@ -303,7 +307,7 @@ def emit(self, record):
lvl = record.levelno
extra = getattr(record, "extra", {})
if lvl >= logging.ERROR:
# to avoid message formating
# to avoid message formatting
if self._logger.enable_for(ERROR_LEVEL):
self._logger.error(self.format(record), extra=extra)
elif lvl >= logging.WARNING:
Expand Down
3 changes: 3 additions & 0 deletions cocaine/detail/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import warnings

from .baseservice import BaseService
from .defaults import Defaults
Expand All @@ -34,6 +35,8 @@
class Service(BaseService):
def __init__(self, name, endpoints=LOCATOR_DEFAULT_ENDPOINT,
seed=None, version=0, locator=None, io_loop=None, timeout=0):
if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
super(Service, self).__init__(name=name, endpoints=LOCATOR_DEFAULT_ENDPOINT, io_loop=io_loop)
self.locator_endpoints = endpoints
self.locator = locator
Expand Down
5 changes: 4 additions & 1 deletion cocaine/futures/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#

import threading
import warnings

from tornado.concurrent import Future
from tornado.ioloop import IOLoop
Expand All @@ -31,6 +32,8 @@
class ConcurrentWorker(object):
def __init__(self, func, io_loop=None, args=(), kwargs=None):
self._func = func
if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
self._io_loop = io_loop or IOLoop.current()
self._args = args
self._kwargs = kwargs or {}
Expand All @@ -53,5 +56,5 @@ def execute(self):

def threaded(func):
def wrapper(*args, **kwargs):
return ConcurrentWorker(func, io_loop=None, args=args, kwargs=kwargs).execute()
return ConcurrentWorker(func, args=args, kwargs=kwargs).execute()
return wrapper
14 changes: 11 additions & 3 deletions cocaine/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#
import logging
import socket
import warnings

import six

Expand Down Expand Up @@ -71,7 +72,10 @@ def token(self):


class TicketVendingMachineTokenManager(TokenManager):
def __init__(self, name, ticket, interval, loop):
def __init__(self, name, ticket, interval, loop=None):
if loop:
warnings.warn('loop argument is deprecated.', DeprecationWarning)
loop = loop or IOLoop.current()
self._name = name
self._ticket = ticket
self._service = Service('tvm')
Expand Down Expand Up @@ -100,7 +104,10 @@ def _refresh(self):
yield now


def make_token_manager(name, token, loop):
def make_token_manager(name, token, loop=None):
if loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
loop = loop or IOLoop.current()
if token.ty == 'TVM':
return TicketVendingMachineTokenManager(name, token.body, 10.0, loop)
else:
Expand All @@ -111,14 +118,15 @@ class BasicWorker(object):
def __init__(self, disown_timeout=DEFAULT_DISOWN_TIMEOUT,
heartbeat_timeout=DEFAULT_HEARTBEAT_TIMEOUT,
io_loop=None, app=None, uuid=None, endpoint=None):

if heartbeat_timeout < disown_timeout:
raise ValueError("heartbeat timeout must be greater than disown")

self.appname = app or Defaults.app
self.uuid = uuid or Defaults.uuid
self.endpoint = endpoint or Defaults.endpoint

if io_loop:
warnings.warn('io_loop argument is deprecated.', DeprecationWarning)
self.io_loop = io_loop or IOLoop.current()
self._token_manager = make_token_manager(
self.appname,
Expand Down
12 changes: 9 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
msgpack-python
six <= 1.10
tornado>=4.2

msgpack
six >= 1.9,<= 1.10
tornado >=4.2,<5





5 changes: 2 additions & 3 deletions tests/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@
class RuntimeMock(tcpserver.TCPServer):
_msgpack_string_encoding = None if sys.version_info[0] == 2 else 'utf8'

def __init__(self, unixsocket, io_loop=None):
super(RuntimeMock, self).__init__(io_loop=io_loop or ioloop.IOLoop.current())
self.io_loop = io_loop or ioloop.IOLoop.current()
def __init__(self, unixsocket):
super(RuntimeMock, self).__init__()
self.actions = list()
self.counter = 1
self.endpoint = unixsocket
Expand Down
19 changes: 8 additions & 11 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[tox]
envlist = flake8,
py27,
py34,
py35,
py36
pypy
py27,
py34,
py35,
py36,
pypy
skip_missing_interpreters = True


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


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


[testenv:flake8]
install_command = pip install {opts} {packages}
deps = flake8
flake8-import-order
flake8-blind-except
pep8-naming
flake8-import-order
flake8-blind-except
pep8-naming
commands = flake8 {toxinidir}

0 comments on commit 0cc45fe

Please sign in to comment.