Jelajahi Sumber

Removes celery.utils.functional, replaced by functools

Ask Solem 14 tahun lalu
induk
melakukan
e00ac648ce

+ 1 - 1
celery/app/__init__.py

@@ -11,6 +11,7 @@ Celery Application.
 import os
 import os
 import threading
 import threading
 
 
+from functools import wraps
 from inspect import getargspec
 from inspect import getargspec
 
 
 from kombu.utils import cached_property
 from kombu.utils import cached_property
@@ -18,7 +19,6 @@ from kombu.utils import cached_property
 from celery import registry
 from celery import registry
 from celery.app import base
 from celery.app import base
 from celery.utils import instantiate
 from celery.utils import instantiate
-from celery.utils.functional import wraps
 
 
 # Apps with the :attr:`~celery.app.base.BaseApp.set_as_current` attribute
 # Apps with the :attr:`~celery.app.base.BaseApp.set_as_current` attribute
 # sets this, so it will always contain the last instantiated app,
 # sets this, so it will always contain the last instantiated app,

+ 1 - 1
celery/app/base.py

@@ -12,6 +12,7 @@ import platform as _platform
 import sys
 import sys
 
 
 from copy import deepcopy
 from copy import deepcopy
+from functools import wraps
 from threading import Lock
 from threading import Lock
 
 
 from kombu.utils import cached_property
 from kombu.utils import cached_property
@@ -19,7 +20,6 @@ from kombu.utils import cached_property
 from celery.app.defaults import DEFAULTS
 from celery.app.defaults import DEFAULTS
 from celery.datastructures import ConfigurationView
 from celery.datastructures import ConfigurationView
 from celery.utils import instantiate, lpmerge
 from celery.utils import instantiate, lpmerge
-from celery.utils.functional import wraps
 
 
 import kombu
 import kombu
 if kombu.VERSION < (1, 1, 0):
 if kombu.VERSION < (1, 1, 0):

+ 2 - 2
celery/apps/worker.py

@@ -333,10 +333,10 @@ def install_worker_restart_handler(worker):
 
 
 
 
 def install_cry_handler(logger):
 def install_cry_handler(logger):
-    # 2.4 does not have sys._current_frames
+    # Jython/PyPy does not have sys._current_frames
     is_jython = sys.platform.startswith("java")
     is_jython = sys.platform.startswith("java")
     is_pypy = hasattr(sys, "pypy_version_info")
     is_pypy = hasattr(sys, "pypy_version_info")
-    if not (is_jython or is_pypy) and sys.version_info > (2, 5):
+    if not (is_jython or is_pypy):
 
 
         def cry_handler(signum, frame):
         def cry_handler(signum, frame):
             """Signal handler logging the stacktrace of all active threads."""
             """Signal handler logging the stacktrace of all active threads."""

+ 2 - 1
celery/bin/celerybeat.py

@@ -22,9 +22,10 @@
     `ERROR`, `CRITICAL`, or `FATAL`.
     `ERROR`, `CRITICAL`, or `FATAL`.
 
 
 """
 """
+from functools import partial
+
 from celery.bin.base import Command, Option, daemon_options
 from celery.bin.base import Command, Option, daemon_options
 from celery.platforms import create_daemon_context
 from celery.platforms import create_daemon_context
-from celery.utils.functional import partial
 
 
 
 
 class BeatCommand(Command):
 class BeatCommand(Command):

+ 2 - 1
celery/concurrency/base.py

@@ -3,9 +3,10 @@ import sys
 import time
 import time
 import traceback
 import traceback
 
 
+from functools import partial
+
 from celery import log
 from celery import log
 from celery.datastructures import ExceptionInfo
 from celery.datastructures import ExceptionInfo
-from celery.utils.functional import partial
 from celery.utils import timer2
 from celery.utils import timer2
 
 
 
 

+ 2 - 1
celery/execute/trace.py

@@ -41,7 +41,8 @@ class TraceInfo(object):
                 raise
                 raise
             return cls(states.FAILURE, retval=exc, exc_info=sys.exc_info())
             return cls(states.FAILURE, retval=exc, exc_info=sys.exc_info())
         except:  # pragma: no cover
         except:  # pragma: no cover
-            # For Python2.4 where raising strings are still allowed.
+            # For Python2.5 where raising strings are still allowed
+            # (but deprecated)
             if propagate:
             if propagate:
                 raise
                 raise
             return cls(states.FAILURE, retval=None, exc_info=sys.exc_info())
             return cls(states.FAILURE, retval=None, exc_info=sys.exc_info())

+ 4 - 3
celery/tests/test_app/test_routes.py

@@ -1,10 +1,10 @@
-from celery.tests.utils import unittest
+from functools import wraps
 
 
 from celery import routes
 from celery import routes
 from celery import current_app
 from celery import current_app
-from celery.utils import maybe_promise
-from celery.utils.functional import wraps
 from celery.exceptions import QueueNotFound
 from celery.exceptions import QueueNotFound
+from celery.utils import maybe_promise
+from celery.tests.utils import unittest
 
 
 
 
 def E(queues):
 def E(queues):
@@ -16,6 +16,7 @@ def E(queues):
 def with_queues(**queues):
 def with_queues(**queues):
 
 
     def patch_fun(fun):
     def patch_fun(fun):
+
         @wraps(fun)
         @wraps(fun)
         def __inner(*args, **kwargs):
         def __inner(*args, **kwargs):
             app = current_app
             app = current_app

+ 2 - 4
celery/tests/test_bin/test_celeryd.py

@@ -3,6 +3,7 @@ import os
 import sys
 import sys
 import warnings
 import warnings
 
 
+from functools import wraps
 try:
 try:
     from multiprocessing import current_process
     from multiprocessing import current_process
 except ImportError:
 except ImportError:
@@ -21,12 +22,9 @@ from celery.bin.celeryd import WorkerCommand, windows_main, \
                                main as celeryd_main
                                main as celeryd_main
 from celery.exceptions import ImproperlyConfigured
 from celery.exceptions import ImproperlyConfigured
 from celery.utils import patch
 from celery.utils import patch
-from celery.utils.functional import wraps
 
 
 from celery.tests.compat import catch_warnings
 from celery.tests.compat import catch_warnings
-from celery.tests.utils import execute_context
-from celery.tests.utils import AppCase
-from celery.tests.utils import StringIO
+from celery.tests.utils import AppCase, execute_context, StringIO
 
 
 
 
 patch.ensure_process_aware_logger()
 patch.ensure_process_aware_logger()

+ 2 - 3
celery/tests/test_slow/test_buckets.py

@@ -2,18 +2,17 @@ from __future__ import generators
 
 
 import sys
 import sys
 import time
 import time
-from celery.tests.utils import unittest
 
 
+from functools import partial
 from itertools import chain, izip
 from itertools import chain, izip
 
 
 from celery.registry import TaskRegistry
 from celery.registry import TaskRegistry
 from celery.task.base import Task
 from celery.task.base import Task
 from celery.utils import timeutils
 from celery.utils import timeutils
 from celery.utils import gen_unique_id
 from celery.utils import gen_unique_id
-from celery.utils.functional import partial
 from celery.worker import buckets
 from celery.worker import buckets
 
 
-from celery.tests.utils import skip_if_environ
+from celery.tests.utils import skip_if_environ, unittest
 
 
 skip_if_disabled = partial(skip_if_environ("SKIP_RLIMITS"))
 skip_if_disabled = partial(skip_if_environ("SKIP_RLIMITS"))
 
 

+ 2 - 4
celery/tests/test_task/test_task.py

@@ -1,6 +1,5 @@
-from celery.tests.utils import unittest
-from celery.tests.utils import StringIO
 from datetime import datetime, timedelta
 from datetime import datetime, timedelta
+from functools import wraps
 
 
 from pyparsing import ParseException
 from pyparsing import ParseException
 
 
@@ -13,10 +12,9 @@ from celery.result import EagerResult
 from celery.schedules import crontab, crontab_parser
 from celery.schedules import crontab, crontab_parser
 from celery.utils import timeutils
 from celery.utils import timeutils
 from celery.utils import gen_unique_id
 from celery.utils import gen_unique_id
-from celery.utils.functional import wraps
 from celery.utils.timeutils import parse_iso8601
 from celery.utils.timeutils import parse_iso8601
 
 
-from celery.tests.utils import with_eager_tasks
+from celery.tests.utils import with_eager_tasks, unittest, StringIO
 
 
 
 
 def return_True(*args, **kwargs):
 def return_True(*args, **kwargs):

+ 2 - 2
celery/tests/test_task/test_task_control.py

@@ -1,4 +1,4 @@
-from celery.tests.utils import unittest
+from functools import wraps
 
 
 from kombu.pidbox import Mailbox
 from kombu.pidbox import Mailbox
 
 
@@ -6,7 +6,7 @@ from celery.app import app_or_default
 from celery.task import control
 from celery.task import control
 from celery.task import PingTask
 from celery.task import PingTask
 from celery.utils import gen_unique_id
 from celery.utils import gen_unique_id
-from celery.utils.functional import wraps
+from celery.tests.utils import unittest
 
 
 
 
 class MockMailbox(Mailbox):
 class MockMailbox(Mailbox):

+ 3 - 3
celery/tests/test_task/test_task_http.py

@@ -2,7 +2,8 @@
 from __future__ import generators
 from __future__ import generators
 
 
 import logging
 import logging
-from celery.tests.utils import unittest
+
+from functools import wraps
 try:
 try:
     from urllib import addinfourl
     from urllib import addinfourl
 except ImportError:  # py3k
 except ImportError:  # py3k
@@ -11,8 +12,7 @@ except ImportError:  # py3k
 from anyjson import serialize
 from anyjson import serialize
 
 
 from celery.task import http
 from celery.task import http
-from celery.utils.functional import wraps
-
+from celery.tests.utils import unittest
 from celery.tests.utils import execute_context, contextmanager, StringIO
 from celery.tests.utils import execute_context, contextmanager, StringIO
 
 
 
 

+ 2 - 1
celery/tests/utils.py

@@ -16,6 +16,8 @@ try:
 except ImportError:  # py3k
 except ImportError:  # py3k
     import builtins  # noqa
     import builtins  # noqa
 
 
+from functools import wraps
+
 from celery.utils.compat import StringIO, LoggerAdapter
 from celery.utils.compat import StringIO, LoggerAdapter
 try:
 try:
     from contextlib import contextmanager
     from contextlib import contextmanager
@@ -29,7 +31,6 @@ from nose import SkipTest
 
 
 from celery.app import app_or_default
 from celery.app import app_or_default
 from celery.utils import noop
 from celery.utils import noop
-from celery.utils.functional import wraps
 
 
 
 
 class Mock(mock.Mock):
 class Mock(mock.Mock):

+ 1 - 1
celery/utils/__init__.py

@@ -9,6 +9,7 @@ import threading
 import traceback
 import traceback
 import warnings
 import warnings
 
 
+from functools import partial, wraps
 from inspect import getargspec
 from inspect import getargspec
 from itertools import islice
 from itertools import islice
 from pprint import pprint
 from pprint import pprint
@@ -17,7 +18,6 @@ from kombu.utils import cached_property, gen_unique_id  # noqa
 from kombu.utils import rpartition
 from kombu.utils import rpartition
 
 
 from celery.utils.compat import StringIO
 from celery.utils.compat import StringIO
-from celery.utils.functional import partial, wraps
 
 
 
 
 LOG_LEVELS = dict(logging._levelNames)
 LOG_LEVELS = dict(logging._levelNames)

+ 0 - 136
celery/utils/functional.py

@@ -1,136 +0,0 @@
-"""Functional utilities for Python 2.4 compatibility."""
-# License for code in this file that was taken from Python 2.5.
-
-# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
-# --------------------------------------------
-#
-# 1. This LICENSE AGREEMENT is between the Python Software Foundation
-# ("PSF"), and the Individual or Organization ("Licensee") accessing and
-# otherwise using this software ("Python") in source or binary form and
-# its associated documentation.
-#
-# 2. Subject to the terms and conditions of this License Agreement, PSF
-# hereby grants Licensee a nonexclusive, royalty-free, world-wide
-# license to reproduce, analyze, test, perform and/or display publicly,
-# prepare derivative works, distribute, and otherwise use Python
-# alone or in any derivative version, provided, however, that PSF's
-# License Agreement and PSF's notice of copyright, i.e., "Copyright (c)
-# 2001, 2002, 2003, 2004, 2005, 2006, 2007 Python Software Foundation;
-# All Rights Reserved" are retained in Python alone or in any derivative
-# version prepared by Licensee.
-#
-# 3. In the event Licensee prepares a derivative work that is based on
-# or incorporates Python or any part thereof, and wants to make
-# the derivative work available to others as provided herein, then
-# Licensee hereby agrees to include in any such work a brief summary of
-# the changes made to Python.
-#
-# 4. PSF is making Python available to Licensee on an "AS IS"
-# basis.  PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
-# IMPLIED.  BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
-# DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
-# FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
-# INFRINGE ANY THIRD PARTY RIGHTS.
-#
-# 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
-# FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
-# A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
-# OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
-#
-# 6. This License Agreement will automatically terminate upon a material
-# breach of its terms and conditions.
-#
-# 7. Nothing in this License Agreement shall be deemed to create any
-# relationship of agency, partnership, or joint venture between PSF and
-# Licensee.  This License Agreement does not grant permission to use PSF
-# trademarks or trade name in a trademark sense to endorse or promote
-# products or services of Licensee, or any third party.
-#
-# 8. By copying, installing or otherwise using Python, Licensee
-# agrees to be bound by the terms and conditions of this License
-# Agreement.
-
-### Begin from Python 2.5 functools.py ########################################
-
-# Summary of changes made to the Python 2.5 code below:
-#   * Wrapped the `setattr` call in `update_wrapper` with a try-except
-#     block to make it compatible with Python 2.3, which doesn't allow
-#     assigning to `__name__`.
-
-# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Python Software
-# Foundation. All Rights Reserved.
-
-###############################################################################
-
-# update_wrapper() and wraps() are tools to help write
-# wrapper functions that can handle naive introspection
-
-
-def _compat_partial(fun, *args, **kwargs):
-    """New function with partial application of the given arguments
-    and keywords."""
-
-    def _curried(*addargs, **addkwargs):
-        return fun(*(args + addargs), **dict(kwargs, **addkwargs))
-    return _curried
-
-
-try:
-    from functools import partial
-except ImportError:
-    partial = _compat_partial  # noqa
-
-WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
-WRAPPER_UPDATES = ('__dict__',)
-
-
-def _compat_update_wrapper(wrapper, wrapped, assigned=WRAPPER_ASSIGNMENTS,
-        updated=WRAPPER_UPDATES):
-    """Update a wrapper function to look like the wrapped function
-
-       wrapper is the function to be updated
-       wrapped is the original function
-       assigned is a tuple naming the attributes assigned directly
-       from the wrapped function to the wrapper function (defaults to
-       functools.WRAPPER_ASSIGNMENTS)
-       updated is a tuple naming the attributes off the wrapper that
-       are updated with the corresponding attribute from the wrapped
-       function (defaults to functools.WRAPPER_UPDATES)
-
-    """
-    for attr in assigned:
-        try:
-            setattr(wrapper, attr, getattr(wrapped, attr))
-        except TypeError:   # Python 2.3 doesn't allow assigning to __name__.
-            pass
-    for attr in updated:
-        getattr(wrapper, attr).update(getattr(wrapped, attr))
-    # Return the wrapper so this can be used as a decorator via partial()
-    return wrapper
-
-try:
-    from functools import update_wrapper
-except ImportError:
-    update_wrapper = _compat_update_wrapper  # noqa
-
-
-def _compat_wraps(wrapped, assigned=WRAPPER_ASSIGNMENTS,
-        updated=WRAPPER_UPDATES):
-    """Decorator factory to apply update_wrapper() to a wrapper function
-
-    Returns a decorator that invokes update_wrapper() with the decorated
-    function as the wrapper argument and the arguments to wraps() as the
-    remaining arguments. Default arguments are as for update_wrapper().
-    This is a convenience function to simplify applying partial() to
-    update_wrapper().
-
-    """
-    return partial(update_wrapper, wrapped=wrapped,
-                   assigned=assigned, updated=updated)
-
-try:
-    from functools import wraps
-except ImportError:
-    wraps = _compat_wraps  # noqa
-
-### End from Python 2.5 functools.py ##########################################