From 41b81af11b82132e8e37819929da47f8971dd54e Mon Sep 17 00:00:00 2001 From: Yuhong Guo Date: Thu, 28 Feb 2019 05:05:25 +0800 Subject: [PATCH] Downgrade six to 1.0.0 (#4180) --- python/ray/function_manager.py | 14 +++++++------- python/ray/utils.py | 32 ++++++++++++++++++++++++++++++++ python/setup.py | 4 +++- 3 files changed, 42 insertions(+), 8 deletions(-) diff --git a/python/ray/function_manager.py b/python/ray/function_manager.py index 814fe4cd9..bc63a994f 100644 --- a/python/ray/function_manager.py +++ b/python/ray/function_manager.py @@ -7,7 +7,6 @@ import importlib import inspect import json import logging -import six import sys import time import traceback @@ -27,6 +26,7 @@ from ray.utils import ( is_class_method, check_oversized_pickle, decode, + ensure_str, format_error_message, push_error_to_driver, ) @@ -89,9 +89,9 @@ class FunctionDescriptor(object): return FunctionDescriptor.for_driver_task() elif (len(function_descriptor_list) == 3 or len(function_descriptor_list) == 4): - module_name = six.ensure_str(function_descriptor_list[0]) - class_name = six.ensure_str(function_descriptor_list[1]) - function_name = six.ensure_str(function_descriptor_list[2]) + module_name = ensure_str(function_descriptor_list[0]) + class_name = ensure_str(function_descriptor_list[1]) + function_name = ensure_str(function_descriptor_list[2]) if len(function_descriptor_list) == 4: return cls(module_name, function_name, class_name, function_descriptor_list[3]) @@ -709,10 +709,10 @@ class FunctionActorManager(object): "actor_method_names" ]) - class_name = six.ensure_str(class_name) - module_name = six.ensure_str(module) + class_name = ensure_str(class_name) + module_name = ensure_str(module) driver_id = ray.DriverID(driver_id_str) - actor_method_names = json.loads(six.ensure_str(actor_method_names)) + actor_method_names = json.loads(ensure_str(actor_method_names)) actor_class = None try: diff --git a/python/ray/utils.py b/python/ray/utils.py index d80e10f79..106c472a0 100644 --- a/python/ray/utils.py +++ b/python/ray/utils.py @@ -10,6 +10,7 @@ import inspect import logging import numpy as np import os +import six import subprocess import sys import threading @@ -180,6 +181,37 @@ def decode(byte_str, allow_none=False): return byte_str +def ensure_str(s, encoding="utf-8", errors="strict"): + """Coerce *s* to `str`. + + To keep six with lower version, see Issue 4169, we copy this function + from six == 1.12.0. + + TODO(yuhguo): remove this function when six >= 1.12.0. + + For Python 2: + - `unicode` -> encoded to `str` + - `str` -> `str` + + For Python 3: + - `str` -> `str` + - `bytes` -> decoded to `str` + """ + if six.PY3: + text_type = str + binary_type = bytes + else: + text_type = unicode # noqa: F821 + binary_type = str + if not isinstance(s, (text_type, binary_type)): + raise TypeError("not expecting type '%s'" % type(s)) + if six.PY2 and isinstance(s, text_type): + s = s.encode(encoding, errors) + elif six.PY3 and isinstance(s, binary_type): + s = s.decode(encoding, errors) + return s + + def binary_to_object_id(binary_object_id): return ray.ObjectID(binary_object_id) diff --git a/python/setup.py b/python/setup.py index 4b9a650b4..6cb9f2d2b 100644 --- a/python/setup.py +++ b/python/setup.py @@ -152,7 +152,9 @@ requires = [ "pytest", "pyyaml", "redis", - "six >= 1.12.0", + # NOTE: Don't upgrade the version of six! Doing so causes installation + # problems. See https://github.com/ray-project/ray/issues/4169. + "six >= 1.0.0", # The typing module is required by modin. "typing", "flatbuffers",