Skip to content

Commit

Permalink
chore: fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Bogdanp committed Apr 22, 2018
1 parent 313e637 commit ddccad3
Show file tree
Hide file tree
Showing 53 changed files with 126 additions and 111 deletions.
6 changes: 2 additions & 4 deletions dramatiq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@
from .composition import group, pipeline
from .encoder import Encoder, JSONEncoder, PickleEncoder
from .errors import (
DramatiqError,
BrokerError, ActorNotFound, QueueNotFound, QueueJoinTimeout,
ConnectionError, ConnectionClosed, ConnectionFailed,
RateLimitExceeded,
ActorNotFound, BrokerError, ConnectionClosed, ConnectionError, ConnectionFailed, DramatiqError, QueueJoinTimeout,
QueueNotFound, RateLimitExceeded
)
from .generic import GenericActor
from .logging import get_logger
Expand Down
4 changes: 2 additions & 2 deletions dramatiq/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import signal
import sys
import time

from collections import defaultdict
from dramatiq import __version__, Broker, ConnectionError, Worker, get_broker, get_logger
from threading import Thread

from dramatiq import Broker, ConnectionError, Worker, __version__, get_broker, get_logger

try:
from .watcher import setup_file_watcher

Expand Down
4 changes: 2 additions & 2 deletions dramatiq/brokers/rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import errno
import logging
import pika
import socket
import time
import warnings

from itertools import chain
from threading import local

import pika

from ..broker import Broker, Consumer, MessageProxy
from ..common import current_millis, dq_name, xq_name
from ..errors import ConnectionClosed, QueueJoinTimeout
Expand Down
4 changes: 2 additions & 2 deletions dramatiq/brokers/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import glob
import redis
import time

from os import path
from threading import Thread
from uuid import uuid4

import redis

from ..broker import Broker, Consumer, MessageProxy
from ..common import compute_backoff, current_millis, dq_name, xq_name
from ..errors import ConnectionClosed, QueueJoinTimeout
Expand Down
3 changes: 1 addition & 2 deletions dramatiq/brokers/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
# 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 time

from itertools import chain
from queue import Queue, Empty
from queue import Empty, Queue

from ..broker import Broker, Consumer, MessageProxy
from ..common import current_millis, dq_name, iter_queue, join_queue
Expand Down
3 changes: 2 additions & 1 deletion dramatiq/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def compute_backoff(attempts, *, factor=5, jitter=True, max_backoff=2000, max_ex


def current_millis():
"Returns the current UNIX time in milliseconds."
"""Returns the current UNIX time in milliseconds.
"""
return int(time() * 1000)


Expand Down
1 change: 0 additions & 1 deletion dramatiq/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import pickle
import typing


#: Represents the contents of a Message object as a dict.
MessageData = typing.Dict[str, typing.Any]

Expand Down
2 changes: 0 additions & 2 deletions dramatiq/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@

import time
import uuid

from collections import namedtuple

from .broker import get_broker
from .composition import pipeline
from .encoder import Encoder, JSONEncoder
from .results import Results


#: The global encoder instance.
global_encoder = JSONEncoder()

Expand Down
1 change: 0 additions & 1 deletion dramatiq/middleware/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import fcntl
import glob
import os

from contextlib import contextmanager
from http.server import BaseHTTPRequestHandler, HTTPServer
from threading import Thread
Expand Down
2 changes: 1 addition & 1 deletion dramatiq/middleware/shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from ..logging import get_logger
from .middleware import Middleware
from .threading import Interrupt, current_platform, supported_platforms, raise_thread_exception
from .threading import Interrupt, current_platform, raise_thread_exception, supported_platforms


class Shutdown(Interrupt):
Expand Down
2 changes: 1 addition & 1 deletion dramatiq/middleware/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from ..logging import get_logger

__all__ = ['Interrupt', 'raise_thread_exception']
__all__ = ["Interrupt", "raise_thread_exception"]


logger = get_logger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion dramatiq/middleware/time_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from ..logging import get_logger
from .middleware import Middleware
from .threading import Interrupt, current_platform, supported_platforms, raise_thread_exception
from .threading import Interrupt, current_platform, raise_thread_exception, supported_platforms


class TimeLimitExceeded(Interrupt):
Expand Down
3 changes: 1 addition & 2 deletions dramatiq/rate_limits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .backend import RateLimiterBackend
from .rate_limiter import RateLimiter, RateLimitExceeded

from .bucket import BucketRateLimiter
from .concurrent import ConcurrentRateLimiter
from .rate_limiter import RateLimiter, RateLimitExceeded
from .window import WindowRateLimiter

__all__ = [
Expand Down
1 change: 0 additions & 1 deletion dramatiq/rate_limits/backends/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import time

from threading import Lock

from ..backend import RateLimiterBackend
Expand Down
2 changes: 1 addition & 1 deletion dramatiq/results/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

from .backend import Missing, ResultBackend
from .errors import ResultError, ResultTimeout, ResultMissing
from .errors import ResultError, ResultMissing, ResultTimeout
from .middleware import Results

__all__ = ["Missing", "ResultBackend", "ResultError", "ResultTimeout", "ResultMissing", "Results"]
2 changes: 1 addition & 1 deletion dramatiq/results/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from ..common import compute_backoff, q_name
from ..encoder import Encoder, JSONEncoder
from .errors import ResultTimeout, ResultMissing
from .errors import ResultMissing, ResultTimeout

#: The default timeout for blocking get operations in milliseconds.
DEFAULT_TIMEOUT = 10000
Expand Down
2 changes: 1 addition & 1 deletion dramatiq/results/backends/memcached.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

from pylibmc import Client, ClientPool

from ..backend import ResultBackend, Missing
from ..backend import Missing, ResultBackend


class MemcachedBackend(ResultBackend):
Expand Down
2 changes: 1 addition & 1 deletion dramatiq/results/backends/stub.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import time

from ..backend import ResultBackend, Missing
from ..backend import Missing, ResultBackend


class StubBackend(ResultBackend):
Expand Down
1 change: 0 additions & 1 deletion dramatiq/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import os
import time

from collections import defaultdict
from itertools import chain
from queue import Empty, PriorityQueue, Queue
Expand Down
3 changes: 2 additions & 1 deletion examples/basic/example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import argparse
import dramatiq
import os
import random
import sys

import dramatiq

if os.getenv("REDIS") == "1":
from dramatiq.brokers.redis import RedisBroker
broker = RedisBroker()
Expand Down
3 changes: 2 additions & 1 deletion examples/basic/profile_example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import dramatiq
import logging
import random
import sys
import time

import dramatiq
import yappi

logger = logging.getLogger("example")
Expand Down
5 changes: 3 additions & 2 deletions examples/composition/example.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import argparse
import dramatiq
import requests
import sys

import requests

import dramatiq
from dramatiq import group
from dramatiq.brokers.rabbitmq import RabbitmqBroker
from dramatiq.encoder import PickleEncoder
Expand Down
9 changes: 5 additions & 4 deletions examples/crawler/example.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import argparse
import dramatiq
import hashlib
import logging
import os
import pylibmc
import re
import requests
import sys

from contextlib import closing
from threading import local

import pylibmc
import requests

import dramatiq

logger = logging.getLogger("example")
memcache_client = pylibmc.Client(["localhost"], binary=True)
memcache_pool = pylibmc.ThreadMappedPool(memcache_client)
Expand Down
2 changes: 1 addition & 1 deletion examples/crawler/profile_example.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dramatiq
import sys
import time

import dramatiq
from pympler import tracker

from .example import crawl # noqa
Expand Down
3 changes: 2 additions & 1 deletion examples/long_running/example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import dramatiq
import os
import random
import sys
import time

import dramatiq

if os.getenv("REDIS") == "1":
from dramatiq.brokers.redis import RedisBroker
broker = RedisBroker()
Expand Down
34 changes: 17 additions & 17 deletions examples/persistent/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,45 @@

def get_state(n):
try:
with open(os.path.join('states', str(n)), 'r') as state:
with open(os.path.join("states", str(n)), "r") as state:
data = json.load(state)
i, x2, x1 = data['i'], data['x2'], data['x1']
fib.logger.debug('Resuming fib(%d) from iteration %d ...', n, i)
i, x2, x1 = data["i"], data["x2"], data["x1"]
fib.logger.debug("Resuming fib(%d) from iteration %d ...", n, i)
return i, x2, x1
except Exception:
fib.logger.debug('Could not read state file, using defaults ...')
fib.logger.debug("Could not read state file, using defaults ...")
return 1, 1, 0


def save_state(n, i, x2, x1):
if not os.path.exists('states'):
os.mkdir('states')
with open(os.path.join('states', str(n)), 'w') as state:
json.dump({'i': i, 'x2': x2, 'x1': x1}, state)
fib.logger.debug('Saved fib(%d) state for iteration %d ...', n, i)
os.makedirs("states", exist_ok=True)
with open(os.path.join("states", str(n)), "w") as state:
json.dump({"i": i, "x2": x2, "x1": x1}, state)
fib.logger.debug("Saved fib(%d) state for iteration %d ...", n, i)


def del_state(n):
file = os.path.join('states', str(n))
if os.path.exists(file):
os.remove(file)
fib.logger.debug('Deleted state for fib(%d) ...', n)
try:
os.remove(os.path.join("states", str(n)))
fib.logger.debug("Deleted state for fib(%d) ...", n)
except OSError:
pass


@dramatiq.actor(time_limit=float('inf'), notify_shutdown=True, max_retries=0)
@dramatiq.actor(time_limit=float("inf"), notify_shutdown=True, max_retries=0)
def fib(n):
i, x2, x1 = get_state(n)

try:
for i in range(i, n + 1):
state = {'i': i, 'x2': x2, 'x1': x1}
state = {"i": i, "x2": x2, "x1": x1}

x2, x1 = x1, (x2 + x1)
fib.logger.info('fib(%d): %d', i, x1)
fib.logger.info("fib(%d): %d", i, x1)
time.sleep(.1)

del_state(n)
fib.logger.info('Done!')
fib.logger.info("Done!")
except Shutdown:
save_state(n, **state)

Expand Down
4 changes: 2 additions & 2 deletions examples/results/example.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import argparse
import dramatiq
import random
import sys
import time

import dramatiq
from dramatiq.brokers.rabbitmq import RabbitmqBroker
from dramatiq.encoder import PickleEncoder
from dramatiq.results.backends import RedisBackend
from dramatiq.results import Results
from dramatiq.results.backends import RedisBackend

result_backend = RedisBackend(encoder=PickleEncoder())
broker = RabbitmqBroker()
Expand Down
5 changes: 3 additions & 2 deletions examples/scheduling/example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import dramatiq
import sys
from datetime import datetime

from apscheduler.schedulers.blocking import BlockingScheduler
from apscheduler.triggers.cron import CronTrigger
from datetime import datetime

import dramatiq


@dramatiq.actor
Expand Down
3 changes: 2 additions & 1 deletion examples/time_limit/example.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import dramatiq
import logging
import os
import sys
import time

import dramatiq

if os.getenv("REDIS") == "1":
from dramatiq.brokers.redis import RedisBroker
broker = RedisBroker()
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ inline-quotes = "
multiline-quotes = """

[isort]
known_first_party=dramatiq
multi_line_output=5
not_skip = __init__.py
line_length = 120
known_first_party = dramatiq
multi_line_output = 5
order_by_type = true
Loading

0 comments on commit ddccad3

Please sign in to comment.