From 428d75b9b630688c02a37f951cf83cf6d6b0aef5 Mon Sep 17 00:00:00 2001 From: rpkak <67059904+rpkak@users.noreply.github.com> Date: Fri, 14 May 2021 12:43:08 +0200 Subject: [PATCH] Support for Click 8.0.0 (#1465) * `'.'` to `['.']` as path default(s) view https://github.com/rq/rq/issues/1464#issuecomment-839649116, #1464 * DefaultSerializer class object to `rq.serializers.DefaultSerializer` in shared options in defaults.py #1464 * remove unused import * make rq python 3.5 compatible --- rq/cli/cli.py | 8 ++++---- rq/defaults.py | 1 + rq/utils.py | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/rq/cli/cli.py b/rq/cli/cli.py index 95e8f3f..1486329 100755 --- a/rq/cli/cli.py +++ b/rq/cli/cli.py @@ -21,11 +21,11 @@ from rq.defaults import (DEFAULT_CONNECTION_CLASS, DEFAULT_JOB_CLASS, DEFAULT_QUEUE_CLASS, DEFAULT_WORKER_CLASS, DEFAULT_RESULT_TTL, DEFAULT_WORKER_TTL, DEFAULT_JOB_MONITORING_INTERVAL, - DEFAULT_LOGGING_FORMAT, DEFAULT_LOGGING_DATE_FORMAT) + DEFAULT_LOGGING_FORMAT, DEFAULT_LOGGING_DATE_FORMAT, + DEFAULT_SERIALIZER_CLASS) from rq.exceptions import InvalidJobOperationError from rq.registry import FailedJobRegistry, clean_registries from rq.utils import import_attribute -from rq.serializers import DefaultSerializer from rq.suspension import (suspend as connection_suspend, resume as connection_resume, is_suspended) from rq.worker_registration import clean_worker_registry @@ -62,11 +62,11 @@ shared_options = [ default=DEFAULT_CONNECTION_CLASS, help='Redis client class to use'), click.option('--path', '-P', - default='.', + default=['.'], help='Specify the import path.', multiple=True), click.option('--serializer', '-S', - default=DefaultSerializer, + default=DEFAULT_SERIALIZER_CLASS, help='Path to serializer, defaults to rq.serializers.DefaultSerializer') ] diff --git a/rq/defaults.py b/rq/defaults.py index 701e356..227a1b6 100644 --- a/rq/defaults.py +++ b/rq/defaults.py @@ -1,6 +1,7 @@ DEFAULT_JOB_CLASS = 'rq.job.Job' DEFAULT_QUEUE_CLASS = 'rq.Queue' DEFAULT_WORKER_CLASS = 'rq.Worker' +DEFAULT_SERIALIZER_CLASS = 'rq.serializers.DefaultSerializer' DEFAULT_CONNECTION_CLASS = 'redis.Redis' DEFAULT_WORKER_TTL = 420 DEFAULT_JOB_MONITORING_INTERVAL = 30 diff --git a/rq/utils.py b/rq/utils.py index 284286b..6bbf7bf 100644 --- a/rq/utils.py +++ b/rq/utils.py @@ -137,11 +137,11 @@ def import_attribute(name): module_name = '.'.join(module_name_bits) module = importlib.import_module(module_name) break - except ModuleNotFoundError: + except ImportError: attribute_bits.insert(0, module_name_bits.pop()) if module is None: - raise ValueError(f'Invalid attribute name: {name}') + raise ValueError('Invalid attribute name: %s' % name) attribute_name = '.'.join(attribute_bits) if hasattr(module, attribute_name): @@ -153,7 +153,7 @@ def import_attribute(name): attribute_owner = getattr(module, attribute_owner_name) if not hasattr(attribute_owner, attribute_name): - raise ValueError(f'Invalid attribute name: {name}') + raise ValueError('Invalid attribute name: %s' % name) return getattr(attribute_owner, attribute_name)