Enable the most modern Python syntax.

main
Vincent Driessen 11 years ago
parent 4746602c57
commit 38ec259b6e

@ -1,3 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
def slow_fib(n): def slow_fib(n):
if n <= 1: if n <= 1:
return 1 return 1

@ -1,6 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import os import os
import time import time
from rq import Queue, Connection
from rq import Connection, Queue
from fib import slow_fib from fib import slow_fib

@ -1,5 +1,8 @@
from rq import Queue, Worker, Connection # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from rq import Connection, Queue, Worker
if __name__ == '__main__': if __name__ == '__main__':
# Tell rq what Redis connection to use # Tell rq what Redis connection to use

@ -1,12 +1,13 @@
from .connections import get_current_connection # -*- coding: utf-8 -*-
from .connections import use_connection, push_connection, pop_connection from __future__ import (absolute_import, division, print_function,
from .connections import Connection unicode_literals)
from .queue import Queue, get_failed_queue
from .job import cancel_job, requeue_job
from .job import get_current_job
from .worker import Worker
from .version import VERSION
from .connections import (Connection, get_current_connection, pop_connection,
push_connection, use_connection)
from .job import cancel_job, get_current_job, requeue_job
from .queue import get_failed_queue, Queue
from .version import VERSION
from .worker import Worker
__all__ = [ __all__ = [
'use_connection', 'get_current_connection', 'use_connection', 'get_current_connection',

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import sys import sys
@ -35,7 +39,7 @@ else:
root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__ root = max(roots) # prefer __lt__ to __le__ to __gt__ to __ge__
for opname, opfunc in convert[root]: for opname, opfunc in convert[root]:
if opname not in roots: if opname not in roots:
opfunc.__name__ = opname opfunc.__name__ = str(opname)
opfunc.__doc__ = getattr(int, opname).__doc__ opfunc.__doc__ = getattr(int, opname).__doc__
setattr(cls, opname, opfunc) setattr(cls, opname, opfunc)
return cls return cls

@ -1,6 +1,11 @@
from redis import Redis, StrictRedis # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from functools import partial from functools import partial
from redis import Redis, StrictRedis
def fix_return_type(func): def fix_return_type(func):
# deliberately no functools.wraps() call here, since the function being # deliberately no functools.wraps() call here, since the function being

@ -1,7 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from contextlib import contextmanager from contextlib import contextmanager
from redis import StrictRedis from redis import StrictRedis
from .local import LocalStack, release_local
from .compat.connections import patch_connection from .compat.connections import patch_connection
from .local import LocalStack, release_local
class NoRedisConnectionException(Exception): class NoRedisConnectionException(Exception):

@ -1,3 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import logging import logging
from rq import get_current_connection from rq import get_current_connection
from rq import Worker from rq import Worker

@ -1,3 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
def register_sentry(client, worker): def register_sentry(client, worker):
"""Given a Raven client and an RQ worker, registers exception handlers """Given a Raven client and an RQ worker, registers exception handlers
with the worker so exceptions are logged to Sentry. with the worker so exceptions are logged to Sentry.

@ -1,8 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from functools import wraps from functools import wraps
from .queue import Queue
from rq.compat import string_types
from .connections import resolve_connection from .connections import resolve_connection
from .queue import Queue
from .worker import DEFAULT_RESULT_TTL from .worker import DEFAULT_RESULT_TTL
from rq.compat import string_types
class job(object): class job(object):

@ -1,8 +1,12 @@
# -*- coding: utf-8 -*-
""" """
Some dummy tasks that are well-suited for generating load for testing purposes. Some dummy tasks that are well-suited for generating load for testing purposes.
""" """
import time from __future__ import (absolute_import, division, print_function,
unicode_literals)
import random import random
import time
def do_nothing(): def do_nothing():

@ -1,3 +1,8 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
class NoSuchJobError(Exception): class NoSuchJobError(Exception):
pass pass

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import inspect import inspect
from uuid import uuid4 from uuid import uuid4
try: try:
@ -13,7 +17,12 @@ from rq.compat import text_type, decode_redis_hash, as_text, string_types
def enum(name, *sequential, **named): def enum(name, *sequential, **named):
values = dict(zip(sequential, range(len(sequential))), **named) values = dict(zip(sequential, range(len(sequential))), **named)
return type(name, (), values)
# NOTE: Yes, we *really* want to cast using str() here.
# On Python 2 type() requires a byte string (which is str() on Python 2).
# On Python 3 it does not matter, so we'll use str(), which acts as
# a no-op.
return type(str(name), (), values)
Status = enum('Status', Status = enum('Status',
QUEUED='queued', FINISHED='finished', FAILED='failed', QUEUED='queued', FINISHED='finished', FAILED='failed',

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import logging import logging
# Make sure that dictConfig is available # Make sure that dictConfig is available

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import uuid import uuid
from .connections import resolve_connection from .connections import resolve_connection

@ -1,10 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import importlib import importlib
import os import os
from functools import partial from functools import partial
from warnings import warn from warnings import warn
import redis import redis
from rq import use_connection from rq import use_connection
from rq.utils import first from rq.utils import first

@ -1,7 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import optparse import optparse
from rq import use_connection, Queue
from rq import dummy from rq import dummy, Queue, use_connection
def parse_args(): def parse_args():

@ -1,12 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import argparse import argparse
import os import os
import sys import sys
import time import time
from redis.exceptions import ConnectionError from redis.exceptions import ConnectionError
from rq import get_failed_queue, Queue, Worker from rq import get_failed_queue, Queue, Worker
from rq.scripts import (add_standard_arguments, read_config_file, from rq.scripts import (add_standard_arguments, read_config_file,
setup_default_arguments, setup_redis) setup_default_arguments, setup_redis)

@ -1,15 +1,20 @@
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import argparse import argparse
import logging import logging
import logging.config import logging.config
import os import os
import sys import sys
from rq import Queue
from rq.logutils import setup_loghandlers
from redis.exceptions import ConnectionError from redis.exceptions import ConnectionError
from rq import Queue
from rq.contrib.legacy import cleanup_ghosts from rq.contrib.legacy import cleanup_ghosts
from rq.scripts import add_standard_arguments, read_config_file, setup_default_arguments, setup_redis from rq.logutils import setup_loghandlers
from rq.scripts import (add_standard_arguments, read_config_file,
setup_default_arguments, setup_redis)
from rq.utils import import_attribute from rq.utils import import_attribute
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import signal import signal

@ -5,6 +5,9 @@ Miscellaneous helper functions.
The formatter for ANSI colored console output is heavily based on Pygments The formatter for ANSI colored console output is heavily based on Pygments
terminal colorizing code, originally by Georg Brandl. terminal colorizing code, originally by Georg Brandl.
""" """
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import importlib import importlib
import datetime import datetime
import logging import logging

@ -1 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
VERSION = '0.4.2' VERSION = '0.4.2'

@ -1,26 +1,33 @@
import sys # -*- coding: utf-8 -*-
import os from __future__ import (absolute_import, division, print_function,
unicode_literals)
import errno import errno
import logging
import os
import random import random
import time
try:
from procname import setprocname
except ImportError:
def setprocname(*args, **kwargs): # noqa
pass
import socket
import signal import signal
import socket
import sys
import time
import traceback import traceback
import logging
from .queue import Queue, get_failed_queue from rq.compat import as_text, text_type
from .connections import get_current_connection from .connections import get_current_connection
from .exceptions import DequeueTimeout, NoQueueError
from .job import Job, Status from .job import Job, Status
from .utils import make_colorizer, utcnow, utcformat
from .logutils import setup_loghandlers from .logutils import setup_loghandlers
from .exceptions import NoQueueError, DequeueTimeout from .queue import get_failed_queue, Queue
from .timeouts import UnixSignalDeathPenalty from .timeouts import UnixSignalDeathPenalty
from .utils import make_colorizer, utcformat, utcnow
from .version import VERSION from .version import VERSION
from rq.compat import text_type, as_text
try:
from procname import setprocname
except ImportError:
def setprocname(*args, **kwargs): # noqa
pass
green = make_colorizer('darkgreen') green = make_colorizer('darkgreen')
yellow = make_colorizer('darkyellow') yellow = make_colorizer('darkyellow')

@ -1,13 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import logging import logging
from redis import StrictRedis
from rq import pop_connection, push_connection
from rq.compat import is_python_version from rq.compat import is_python_version
if is_python_version((2, 7), (3, 2)): if is_python_version((2, 7), (3, 2)):
import unittest import unittest
else: else:
import unittest2 as unittest # noqa import unittest2 as unittest # noqa
from redis import StrictRedis
from rq import push_connection, pop_connection
def find_empty_redis_database(): def find_empty_redis_database():
"""Tries to connect to a random Redis database (starting from 4), and """Tries to connect to a random Redis database (starting from 4), and

@ -1 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
REDIS_HOST = "testhost.example.com" REDIS_HOST = "testhost.example.com"

@ -1,11 +1,15 @@
# -*- coding: utf-8 -*-
""" """
This file contains all jobs that are used in tests. Each of these test This file contains all jobs that are used in tests. Each of these test
fixtures has a slighty different characteristics. fixtures has a slighty different characteristics.
""" """
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import time import time
from rq import Connection
from rq import Connection, get_current_job
from rq.decorators import job from rq.decorators import job
from rq import get_current_job
def say_hello(name=None): def say_hello(name=None):

@ -1,3 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from datetime import timedelta from datetime import timedelta

@ -1,7 +1,11 @@
from tests import RQTestCase, find_empty_redis_database # -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from rq import Connection, Queue
from tests import find_empty_redis_database, RQTestCase
from tests.fixtures import do_nothing from tests.fixtures import do_nothing
from rq import Queue
from rq import Connection
def new_connection(): def new_connection():

@ -1,10 +1,15 @@
from tests import RQTestCase # -*- coding: utf-8 -*-
from tests.fixtures import decorated_job from __future__ import (absolute_import, division, print_function,
unicode_literals)
from rq.decorators import job from rq.decorators import job
from rq.job import Job from rq.job import Job
from rq.worker import DEFAULT_RESULT_TTL from rq.worker import DEFAULT_RESULT_TTL
from tests import RQTestCase
from tests.fixtures import decorated_job
class TestDecorator(RQTestCase): class TestDecorator(RQTestCase):
def setUp(self): def setUp(self):

@ -1,16 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from datetime import datetime from datetime import datetime
from rq.compat import as_text, PY2
from rq.exceptions import NoSuchJobError, UnpickleError
from rq.job import get_current_job, Job
from rq.queue import Queue
from rq.utils import utcformat
from tests import RQTestCase from tests import RQTestCase
from tests.fixtures import Number, some_calculation, say_hello, access_self from tests.fixtures import access_self, Number, say_hello, some_calculation
from tests.helpers import strip_microseconds from tests.helpers import strip_microseconds
try: try:
from cPickle import loads, dumps from cPickle import loads, dumps
except ImportError: except ImportError:
from pickle import loads, dumps from pickle import loads, dumps
from rq.compat import as_text
from rq.job import Job, get_current_job
from rq.exceptions import NoSuchJobError, UnpickleError
from rq.queue import Queue
from rq.utils import utcformat
class TestJob(RQTestCase): class TestJob(RQTestCase):
@ -240,15 +247,18 @@ class TestJob(RQTestCase):
def test_description_is_persisted(self): def test_description_is_persisted(self):
"""Ensure that job's custom description is set properly""" """Ensure that job's custom description is set properly"""
job = Job.create(func=say_hello, args=('Lionel',), description=u'Say hello!') job = Job.create(func=say_hello, args=('Lionel',), description='Say hello!')
job.save() job.save()
Job.fetch(job.id, connection=self.testconn) Job.fetch(job.id, connection=self.testconn)
self.assertEqual(job.description, u'Say hello!') self.assertEqual(job.description, 'Say hello!')
# Ensure job description is constructed from function call string # Ensure job description is constructed from function call string
job = Job.create(func=say_hello, args=('Lionel',)) job = Job.create(func=say_hello, args=('Lionel',))
job.save() job.save()
Job.fetch(job.id, connection=self.testconn) Job.fetch(job.id, connection=self.testconn)
if PY2:
self.assertEqual(job.description, "tests.fixtures.say_hello(u'Lionel')")
else:
self.assertEqual(job.description, "tests.fixtures.say_hello('Lionel')") self.assertEqual(job.description, "tests.fixtures.say_hello('Lionel')")
def test_job_access_within_job_function(self): def test_job_access_within_job_function(self):

@ -1,9 +1,15 @@
from tests import RQTestCase # -*- coding: utf-8 -*-
from tests.fixtures import Number, div_by_zero, echo, say_hello, some_calculation from __future__ import (absolute_import, division, print_function,
from rq import Queue, get_failed_queue unicode_literals)
from rq import get_failed_queue, Queue
from rq.exceptions import InvalidJobOperationError
from rq.job import Job, Status from rq.job import Job, Status
from rq.worker import Worker from rq.worker import Worker
from rq.exceptions import InvalidJobOperationError
from tests import RQTestCase
from tests.fixtures import (div_by_zero, echo, Number, say_hello,
some_calculation)
class TestQueue(RQTestCase): class TestQueue(RQTestCase):

@ -1,9 +1,14 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from rq.compat import is_python_version from rq.compat import is_python_version
from rq.scripts import read_config_file
if is_python_version((2, 7), (3, 2)): if is_python_version((2, 7), (3, 2)):
from unittest import TestCase from unittest import TestCase
else: else:
from unittest2 import TestCase # noqa from unittest2 import TestCase # noqa
from rq.scripts import read_config_file
class TestScripts(TestCase): class TestScripts(TestCase):

@ -1,7 +1,12 @@
from tests import RQTestCase # -*- coding: utf-8 -*-
from rq import Queue, Worker, get_failed_queue from __future__ import (absolute_import, division, print_function,
unicode_literals)
from rq import get_failed_queue, Queue, Worker
from rq.contrib.sentry import register_sentry from rq.contrib.sentry import register_sentry
from tests import RQTestCase
class FakeSentry(object): class FakeSentry(object):
def captureException(self, *args, **kwds): def captureException(self, *args, **kwds):

@ -1,12 +1,18 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function,
unicode_literals)
import os import os
from tests import RQTestCase, slow
from tests.fixtures import say_hello, div_by_zero, create_file, \ from rq import get_failed_queue, Queue, Worker
create_file_after_timeout
from tests.helpers import strip_microseconds
from rq import Queue, Worker, get_failed_queue
from rq.compat import as_text from rq.compat import as_text
from rq.job import Job, Status from rq.job import Job, Status
from tests import RQTestCase, slow
from tests.fixtures import (create_file, create_file_after_timeout, div_by_zero,
say_hello)
from tests.helpers import strip_microseconds
class TestWorker(RQTestCase): class TestWorker(RQTestCase):
def test_create_worker(self): def test_create_worker(self):

Loading…
Cancel
Save