Ask Solem 13 år sedan
förälder
incheckning
a86bd1c64b

+ 2 - 2
celery/app/__init__.py

@@ -247,12 +247,12 @@ def _app_or_default_trace(app=None):  # pragma: no cover
     from multiprocessing import current_process
     if app is None:
         if getattr(_tls, "current_app", None):
-            print("-- RETURNING TO CURRENT APP --")
+            print("-- RETURNING TO CURRENT APP --")  # noqa+
             print_stack()
             return _tls.current_app
         if current_process()._name == "MainProcess":
             raise Exception("DEFAULT APP")
-        print("-- RETURNING TO DEFAULT APP --")
+        print("-- RETURNING TO DEFAULT APP --")      # noqa+
         print_stack()
         return default_app
     return app

+ 2 - 0
celery/app/amqp.py

@@ -9,6 +9,8 @@ AMQ related functionality.
 :license: BSD, see LICENSE for more details.
 
 """
+from __future__ import absolute_import
+
 from datetime import datetime, timedelta
 
 from kombu import BrokerConnection, Exchange

+ 2 - 0
celery/app/defaults.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import sys
 
 from collections import deque

+ 1 - 0
celery/bin/celeryctl.py

@@ -1,3 +1,4 @@
+from __future__ import absolute_import
 from __future__ import with_statement
 
 import sys

+ 2 - 0
celery/concurrency/processes/_win.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import os
 
 __all__ = ["get_processtree_pids", "kill_processtree"]

+ 1 - 0
celery/concurrency/processes/pool.py

@@ -5,6 +5,7 @@
 #
 # Copyright (c) 2007-2008, R Oudkerk --- see COPYING.txt
 #
+from __future__ import absolute_import
 
 __all__ = ['Pool']
 

+ 2 - 0
celery/contrib/abortable.py

@@ -78,6 +78,8 @@ have it block until the task is finished.
    database backends.
 
 """
+from __future__ import absolute_import
+
 from celery.task.base import Task
 from celery.result import AsyncResult
 

+ 2 - 0
celery/contrib/batches.py

@@ -39,6 +39,8 @@ Registering the click is done as follows:
 :license: BSD, see LICENSE for more details.
 
 """
+from __future__ import absolute_import
+
 from itertools import count
 from Queue import Queue
 

+ 1 - 0
celery/contrib/rdb.py

@@ -36,6 +36,7 @@ Inspired by http://snippets.dzone.com/posts/show/7248
 :license: BSD, see LICENSE for more details.
 
 """
+from __future__ import absolute_import
 
 import errno
 import os

+ 2 - 0
celery/db/a805d4bd.py

@@ -19,6 +19,8 @@ Hence the random module name "a805d5bd" is taken to decrease the chances of
 a collision.
 
 """
+from __future__ import absolute_import
+
 from sqlalchemy.types import PickleType as _PickleType
 
 

+ 2 - 0
celery/db/dfd042c7.py

@@ -5,6 +5,8 @@ SQLAlchemy 0.5.8 version of a805d4bd, see the docstring of that module
 for an explanation of this workaround.
 
 """
+from __future__ import absolute_import
+
 from sqlalchemy.types import PickleType as _PickleType
 from sqlalchemy import util
 

+ 2 - 0
celery/db/session.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 from collections import defaultdict
 
 from sqlalchemy import create_engine

+ 3 - 0
celery/exceptions.py

@@ -1,3 +1,6 @@
+from __future__ import absolute_import
+
+
 UNREGISTERED_FMT = """\
 Task of kind %s is not registered, please make sure it's imported.\
 """

+ 3 - 0
celery/local.py

@@ -1,3 +1,6 @@
+from __future__ import absolute_import
+
+
 def try_import(module):
     from importlib import import_module
     try:

+ 2 - 0
celery/messaging.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 from . import current_app
 from .local import Proxy
 

+ 1 - 0
celery/states.py

@@ -59,6 +59,7 @@ Misc.
 -----
 
 """
+from __future__ import absolute_import
 
 #: State precedence.
 #: None represents the precedence of an unknown state.

+ 2 - 0
celery/tests/__init__.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import logging
 import os
 import sys

+ 2 - 0
celery/tests/config.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import os
 
 BROKER_TRANSPORT = "memory"

+ 2 - 0
celery/tests/functional/case.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import atexit
 import logging
 import os

+ 2 - 0
celery/tests/functional/tasks.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import time
 
 from celery.task import task

+ 1 - 0
celery/tests/test_bin/__init__.py

@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+from __future__ import with_statement
 
 import os
 

+ 1 - 0
celery/tests/test_bin/test_celerybeat.py

@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+from __future__ import with_statement
 
 import logging
 import sys

+ 1 - 0
celery/tests/test_concurrency/test_concurrency_processes.py

@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+from __future__ import with_statement
 
 import signal
 import sys

+ 1 - 0
celery/tests/test_events/__init__.py

@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+from __future__ import with_statement
 
 import socket
 

+ 1 - 0
celery/tests/test_events/test_events_snapshot.py

@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+from __future__ import with_statement
 
 from celery.app import app_or_default
 from celery.events import Events

+ 1 - 0
celery/tests/test_task/__init__.py

@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+from __future__ import with_statement
 
 from datetime import datetime, timedelta
 from functools import wraps

+ 1 - 0
celery/tests/test_task/test_execute_trace.py

@@ -1,4 +1,5 @@
 from __future__ import absolute_import
+from __future__ import with_statement
 
 import operator
 

+ 2 - 0
celery/utils/compat.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 ############## py3k #########################################################
 import sys
 

+ 2 - 0
celery/utils/dispatch/__init__.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 from .signal import Signal
 
 __all__ = ["Signal"]

+ 1 - 0
celery/utils/dispatch/saferef.py

@@ -4,6 +4,7 @@
 Provides a way to safely weakref any function, including bound methods (which
 aren't handled by the core weakref module).
 """
+from __future__ import absolute_import
 
 import weakref
 import traceback

+ 1 - 0
celery/utils/dispatch/signal.py

@@ -1,4 +1,5 @@
 """Signal class."""
+from __future__ import absolute_import
 
 import weakref
 try:

+ 2 - 1
celery/utils/functional.py

@@ -1,4 +1,5 @@
-from __future__ import absolute_import, with_statement
+from __future__ import absolute_import
+from __future__ import with_statement
 
 from functools import wraps
 from threading import Lock

+ 4 - 1
celery/utils/mail.py

@@ -1,12 +1,15 @@
+from __future__ import absolute_import
+
 import sys
 import smtplib
-from celery.utils import get_symbol_by_name
 
 try:
     from email.mime.text import MIMEText
 except ImportError:
     from email.MIMEText import MIMEText  # noqa
 
+from celery.utils import get_symbol_by_name
+
 supports_timeout = sys.version_info >= (2, 6)
 
 

+ 2 - 0
celery/utils/patch.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import logging
 
 _process_aware = False

+ 2 - 0
celery/utils/serialization.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import inspect
 import sys
 import types

+ 2 - 0
celery/utils/timeutils.py

@@ -1,3 +1,5 @@
+from __future__ import absolute_import
+
 import math
 
 from datetime import datetime, timedelta

+ 128 - 0
contrib/release/flakeplus.py

@@ -0,0 +1,128 @@
+#!/usr/bin/env python
+from __future__ import absolute_import
+from __future__ import with_statement
+
+import os
+import pprint
+import re
+import sys
+
+from collections import defaultdict
+from itertools import starmap
+from unipath import Path
+
+RE_COMMENT = r'^\s*\#'
+RE_NOQA = r'.+?\#\s+noqa+'
+RE_MULTILINE_COMMENT_O = r'^\s*(?:\'\'\'|""").+?(?:\'\'\'|""")'
+RE_MULTILINE_COMMENT_S = r'^\s*(?:\'\'\'|""")'
+RE_MULTILINE_COMMENT_E = r'(?:^|.+?)(?:\'\'\'|""")'
+RE_WITH = r'(?:^|\s+)with\s+'
+RE_WITH_IMPORT = r'''from\s+ __future__\s+ import\s+ with_statement'''
+RE_PRINT = r'''(?:^|\s+)print\((?:"|')\W+?[A-Z0-9:]{2,}'''
+RE_ABS_IMPORT = r'''from\s+ __future__\s+ import\s+ absolute_import'''
+
+acc = defaultdict(lambda: {"abs": False, "print": False})
+
+
+def compile(regex):
+    return re.compile(regex, re.VERBOSE)
+
+
+class FlakePP(object):
+    re_comment = compile(RE_COMMENT)
+    re_ml_comment_o = compile(RE_MULTILINE_COMMENT_O)
+    re_ml_comment_s = compile(RE_MULTILINE_COMMENT_S)
+    re_ml_comment_e = compile(RE_MULTILINE_COMMENT_E)
+    re_abs_import = compile(RE_ABS_IMPORT)
+    re_print = compile(RE_PRINT)
+    re_with_import = compile(RE_WITH_IMPORT)
+    re_with = compile(RE_WITH)
+    re_noqa = compile(RE_NOQA)
+    map = {"abs": False, "print": False,
+            "with": False, "with-used": False}
+
+    def __init__(self, verbose=False):
+        self.verbose = verbose
+        self.steps = (("abs", self.re_abs_import),
+                      ("with", self.re_with_import),
+                      ("with-used", self.re_with),
+                      ("print", self.re_print))
+
+    def analyze_fh(self, fh):
+        steps = self.steps
+        filename = fh.name
+        acc = dict(self.map)
+        index = 0
+        errors = [0]
+
+        def error(fmt, **kwargs):
+            errors[0] += 1
+            self.announce(fmt, **dict(kwargs, filename=filename))
+
+        for index, line in enumerate(self.strip_comments(fh)):
+            for key, pattern in self.steps:
+                if pattern.match(line):
+                    acc[key] = True
+        if index:
+            if not acc["abs"]:
+                error("%(filename)s: missing abs import")
+            if acc["with-used"] and not acc["with"]:
+                error("%(filename)s: missing with import")
+            if acc["print"]:
+                error("%(filename)s: left over print statement")
+
+        return filename, errors[0], acc
+
+    def analyze_file(self, filename):
+        with open(filename) as fh:
+            return self.analyze_fh(fh)
+
+    def analyze_tree(self, dir):
+        for dirpath, _, filenames in os.walk(dir):
+            for path in (Path(dirpath, f) for f in filenames):
+                if path.endswith(".py"):
+                    yield self.analyze_file(path)
+
+    def analyze(self, *paths):
+        for path in map(Path, paths):
+            if path.isdir():
+                for res in self.analyze_tree(path):
+                    yield res
+            else:
+                yield self.analyze_file(path)
+
+    def strip_comments(self, fh):
+        re_comment = self.re_comment
+        re_ml_comment_o = self.re_ml_comment_o
+        re_ml_comment_s = self.re_ml_comment_s
+        re_ml_comment_e = self.re_ml_comment_e
+        re_noqa = self.re_noqa
+        in_ml = False
+
+        for line in fh.readlines():
+            if in_ml:
+                if re_ml_comment_e.match(line):
+                    in_ml = False
+            else:
+                if re_noqa.match(line) or re_ml_comment_o.match(line):
+                    pass
+                elif re_ml_comment_s.match(line):
+                    in_ml = True
+                elif re_comment.match(line):
+                    pass
+                else:
+                    yield line
+
+    def announce(self, fmt, **kwargs):
+        sys.stderr.write((fmt + "\n") % kwargs)
+
+
+def main(argv=sys.argv, exitcode=0):
+    for _, errors, _ in FlakePP(verbose=True).analyze(*argv[1:]):
+        if errors:
+            exitcode = 1
+    return exitcode
+
+
+if __name__ == "__main__":
+    sys.exit(main())

+ 11 - 0
pavement.py

@@ -90,6 +90,17 @@ def flake8(options):
     }{exit $FOUND_FLAKE;
         '""" % (complexity, ), ignore_error=noerror)
 
+
+@task
+@cmdopts([
+    ("noerror", "E", "Ignore errors"),
+])
+def flakeplus(options):
+    noerror = getattr(options, "noerror", False)
+    sh("python contrib/release/flakeplus.py celery",
+       ignore_error=noerror)
+
+
 @task
 def clean_readme(options):
     path("README").unlink()