فهرست منبع

Moves .utils.isatty to .platforms.isatty

Ask Solem 9 سال پیش
والد
کامیت
de6cf95522
6فایلهای تغییر یافته به همراه22 افزوده شده و 29 حذف شده
  1. 1 1
      celery/app/log.py
  2. 2 2
      celery/apps/worker.py
  3. 8 1
      celery/platforms.py
  4. 10 0
      celery/tests/utils/test_platforms.py
  5. 0 10
      celery/tests/utils/test_utils.py
  6. 1 15
      celery/utils/__init__.py

+ 1 - 1
celery/app/log.py

@@ -23,7 +23,7 @@ from kombu.utils.encoding import set_default_encoding_file
 from celery import signals
 from celery._state import get_current_task
 from celery.five import class_property, string_t
-from celery.utils import isatty
+from celery.platforms import isatty
 from celery.utils.log import (
     get_logger, mlevel,
     ColorFormatter, LoggingProxy, get_multiprocessing_logger,

+ 2 - 2
celery/apps/worker.py

@@ -28,8 +28,8 @@ from celery.app import trace
 from celery.exceptions import WorkerShutdown, WorkerTerminate
 from celery.five import string, string_t
 from celery.loaders.app import AppLoader
-from celery.platforms import EX_FAILURE, EX_OK, check_privileges
-from celery.utils import cry, isatty
+from celery.platforms import EX_FAILURE, EX_OK, check_privileges, isatty
+from celery.utils import cry
 from celery.utils.imports import qualname
 from celery.utils.log import get_logger, in_sighandler, set_in_sighandler
 from celery.utils.text import pluralize

+ 8 - 1
celery/platforms.py

@@ -48,7 +48,7 @@ __all__ = ['EX_OK', 'EX_FAILURE', 'EX_UNAVAILABLE', 'EX_USAGE', 'SYSTEM',
            'parse_gid', 'setgroups', 'initgroups', 'setgid', 'setuid',
            'maybe_drop_privileges', 'signals', 'set_process_title',
            'set_mp_process_title', 'get_errno_name', 'ignore_errno',
-           'fd_by_path']
+           'fd_by_path', 'isatty']
 
 # exitcodes
 EX_OK = getattr(os, 'EX_OK', 0)
@@ -93,6 +93,13 @@ User information: uid={uid} euid={euid} gid={gid} egid={egid}
 """
 
 
+def isatty(fh):
+    try:
+        return fh.isatty()
+    except AttributeError:
+        pass
+
+
 def pyimplementation():
     """Return string identifying the current Python implementation."""
     if hasattr(_platform, 'python_implementation'):

+ 10 - 0
celery/tests/utils/test_platforms.py

@@ -31,6 +31,7 @@ from celery.platforms import (
     _setgroups_hack,
     close_open_fds,
     fd_by_path,
+    isatty,
 )
 
 try:
@@ -41,6 +42,15 @@ except ImportError:  # pragma: no cover
 from celery.tests.case import Case, Mock, call, mock, patch, skip
 
 
+class test_isatty(Case):
+
+    def test_tty(self):
+        fh = Mock(name='fh')
+        self.assertIs(isatty(fh), fh.isatty())
+        fh.isatty.side_effect = AttributeError()
+        self.assertFalse(isatty(fh))
+
+
 class test_find_option_with_arg(Case):
 
     def test_long_opt(self):

+ 0 - 10
celery/tests/utils/test_utils.py

@@ -8,7 +8,6 @@ from kombu import Queue
 
 from celery.utils import (
     chunks,
-    isatty,
     is_iterable,
     cached_property,
     jsonify,
@@ -16,15 +15,6 @@ from celery.utils import (
 from celery.tests.case import Case, Mock
 
 
-class test_isatty(Case):
-
-    def test_tty(self):
-        fh = Mock(name='fh')
-        self.assertIs(isatty(fh), fh.isatty())
-        fh.isatty.side_effect = AttributeError()
-        self.assertFalse(isatty(fh))
-
-
 class test_jsonify(Case):
 
     def test_simple(self):

+ 1 - 15
celery/utils/__init__.py

@@ -9,7 +9,6 @@
 from __future__ import absolute_import, print_function, unicode_literals
 
 import numbers
-import os
 import sys
 import traceback
 import datetime
@@ -24,18 +23,12 @@ from .functional import memoize  # noqa
 from .nodenames import worker_direct, nodename, nodesplit
 
 __all__ = ['worker_direct', 'lpmerge',
-           'is_iterable', 'isatty', 'cry', 'maybe_reraise', 'strtobool',
+           'is_iterable', 'cry', 'maybe_reraise', 'strtobool',
            'jsonify', 'gen_task_name', 'nodename', 'nodesplit',
            'cached_property']
 
 PY3 = sys.version_info[0] == 3
 
-#: Billiard sets this when execv is enabled.
-#: We use it to find out the name of the original ``__main__``
-#: module, so that we can properly rewrite the name of the
-#: task to be that of ``App.main``.
-MP_MAIN_FILE = os.environ.get('MP_MAIN_FILE')
-
 
 def lpmerge(L, R):
     """In place left precedent dictionary merge.
@@ -54,13 +47,6 @@ def is_iterable(obj):
     return True
 
 
-def isatty(fh):
-    try:
-        return fh.isatty()
-    except AttributeError:
-        pass
-
-
 def cry(out=None, sepchr='=', seplen=49):  # pragma: no cover
     """Return stack-trace of all active threads,
     taken from https://gist.github.com/737056."""