From fc803f5d0d3119ba6816c989518f319472e843b9 Mon Sep 17 00:00:00 2001 From: Vincent Driessen Date: Sat, 6 Sep 2014 08:04:09 +0200 Subject: [PATCH] Fix various flake8 complaints. --- rq/queue.py | 4 ++-- rq/scripts/rq_cli.py | 12 ++++-------- rq/scripts/rqinfo.py | 14 +++++++------- rq/scripts/rqworker.py | 2 -- tests/test_scripts.py | 12 ++++-------- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/rq/queue.py b/rq/queue.py index 22aa160..86f0406 100644 --- a/rq/queue.py +++ b/rq/queue.py @@ -138,10 +138,10 @@ class Queue(object): def remove(self, job_or_id, pipeline=None): """Removes Job from queue, accepts either a Job instance or ID.""" job_id = job_or_id.id if isinstance(job_or_id, self.job_class) else job_or_id - + if pipeline is not None: pipeline.lrem(self.key, 0, job_id) - + return self.connection._lrem(self.key, 0, job_id) def compact(self): diff --git a/rq/scripts/rq_cli.py b/rq/scripts/rq_cli.py index d88ed0d..3e5403c 100755 --- a/rq/scripts/rq_cli.py +++ b/rq/scripts/rq_cli.py @@ -15,8 +15,7 @@ from .rqinfo import info @click.group() -@click.option('--url', '-u', envvar='URL', - help='URL describing Redis connection details.') +@click.option('--url', '-u', envvar='URL', help='URL describing Redis connection details.') @click.pass_context def main(ctx, url): """RQ CLI""" @@ -29,8 +28,7 @@ def main(ctx, url): @main.command() -@click.option('--yes', '-y', is_flag=True, - help='Empty failed queue by default') +@click.option('--yes', '-y', is_flag=True, help='Empty failed queue by default') @click.argument('queues', nargs=-1) @click.pass_context def empty(ctx, yes, queues): @@ -51,8 +49,7 @@ def empty(ctx, yes, queues): conn = ctx.obj['connection'] queues = [Queue(queue, connection=conn) for queue in queues] if not queues: - if yes or click.confirm('Do you want to empty failed queue?', - abort=True): + if yes or click.confirm('Do you want to empty failed queue?', abort=True): queues = (get_failed_queue(connection=conn),) for queue in queues: num_jobs = queue.empty() @@ -61,8 +58,7 @@ def empty(ctx, yes, queues): @main.command() -@click.option('--all', '-a', 'is_all', is_flag=True, - help='Requeue all failed jobs') +@click.option('--all', '-a', 'is_all', is_flag=True, help='Requeue all failed jobs') @click.argument('job_ids', nargs=-1) @click.pass_context def requeue(ctx, is_all, job_ids): diff --git a/rq/scripts/rqinfo.py b/rq/scripts/rqinfo.py index 736a148..16c0a32 100755 --- a/rq/scripts/rqinfo.py +++ b/rq/scripts/rqinfo.py @@ -3,18 +3,17 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) +import argparse import sys import time -import click -import argparse from functools import partial +import click from redis.exceptions import ConnectionError -from rq import get_failed_queue, Queue, Worker, Connection +from rq import Connection, get_failed_queue, Queue, Worker from rq.scripts import (add_standard_arguments, read_config_file, setup_default_arguments, setup_redis) - red = partial(click.style, fg='red') green = partial(click.style, fg='green') yellow = partial(click.style, fg='yellow') @@ -184,7 +183,7 @@ def info(ctx, path, interval, raw, only_queues, only_workers, by_queue, queues): sys.exit(0) -### The following code is for backward compatibility, will be removed in future +# TODO: The following code is for backward compatibility, should be removed in future def parse_args(): parser = argparse.ArgumentParser(description='RQ command-line monitor.') add_standard_arguments(parser) @@ -198,12 +197,13 @@ def parse_args(): parser.add_argument('queues', nargs='*', help='The queues to poll') return parser.parse_args() + def main(): # warn users this command is deprecated, use `rq info` import warnings warnings.simplefilter('always', DeprecationWarning) - warnings.warn("This command will be remove in future, " - "use `rq info` instead", DeprecationWarning) + warnings.warn("This command will be removed in future, " + "use `rq info` instead", DeprecationWarning) args = parse_args() diff --git a/rq/scripts/rqworker.py b/rq/scripts/rqworker.py index b6371fd..c238c8a 100644 --- a/rq/scripts/rqworker.py +++ b/rq/scripts/rqworker.py @@ -4,8 +4,6 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) import argparse -import logging -import logging.config import os import sys diff --git a/tests/test_scripts.py b/tests/test_scripts.py index 826eef2..8c5e0fc 100644 --- a/tests/test_scripts.py +++ b/tests/test_scripts.py @@ -39,25 +39,21 @@ class TestRQCli(RQTestCase): def test_empty(self): """rq -u empty -y""" runner = CliRunner() - result = runner.invoke(rq_cli.main, - ['-u', self.redis_url, 'empty', "-y"]) + result = runner.invoke(rq_cli.main, ['-u', self.redis_url, 'empty', "-y"]) self.assertEqual(result.exit_code, 0) self.assertEqual(result.output, '1 jobs removed from failed queue\n') def test_requeue(self): """rq -u requeue""" runner = CliRunner() - result = runner.invoke(rq_cli.main, - ['-u', self.redis_url, 'requeue', '-a']) + result = runner.invoke(rq_cli.main, ['-u', self.redis_url, 'requeue', '-a']) self.assertEqual(result.exit_code, 0) self.assertIn('Requeueing 1 jobs from FailedQueue', result.output) - self.assertIn('Unable to requeue 0 jobs from FailedQueue', - result.output) + self.assertIn('Unable to requeue 0 jobs from FailedQueue', result.output) def test_info(self): """rq -u info -i 0""" runner = CliRunner() - result = runner.invoke(rq_cli.main, - ['-u', self.redis_url, 'info', '-i 0']) + result = runner.invoke(rq_cli.main, ['-u', self.redis_url, 'info', '-i 0']) self.assertEqual(result.exit_code, 0) self.assertIn('1 queues, 1 jobs total', result.output)