Skip to content

Commit

Permalink
Remove six and cloudpickle from setup.py. (#7694)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertnishihara committed Mar 23, 2020
1 parent 1a0c922 commit ee8c9ff
Show file tree
Hide file tree
Showing 15 changed files with 20 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This file is used by CrossLanguageInvocationTest.java to test cross-language
# invocation.

import six

import ray


Expand Down Expand Up @@ -63,4 +61,4 @@ def __init__(self, value):

def increase(self, delta):
self.value += int(delta)
return str(self.value).encode("utf-8") if six.PY3 else str(self.value)
return str(self.value).encode("utf-8")
3 changes: 1 addition & 2 deletions python/ray/actor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import copy
import inspect
import logging
import six
import weakref

from abc import ABCMeta, abstractmethod
Expand Down Expand Up @@ -963,7 +962,7 @@ def exit_actor():
"""A namedtuple that represents a checkpoint."""


class Checkpointable(six.with_metaclass(ABCMeta, object)):
class Checkpointable(metaclass=ABCMeta):
"""An interface that indicates an actor can be checkpointed."""

@abstractmethod
Expand Down
5 changes: 0 additions & 5 deletions python/ray/tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import logging
import random
import six
import sys
import threading
import time
Expand Down Expand Up @@ -365,10 +364,6 @@ def test_illegal_api_calls(ray_start_regular):
ray.get(3)


# TODO(hchen): This test currently doesn't work in Python 2. This is likely
# because plasma client isn't thread-safe. This needs to be fixed from the
# Arrow side. See #4107 for relevant discussions.
@pytest.mark.skipif(six.PY2, reason="Doesn't work in Python 2.")
def test_multithreading(ray_start_2_cpus):
# This test requires at least 2 CPUs to finish since the worker does not
# release resources when joining the threads.
Expand Down
2 changes: 1 addition & 1 deletion python/ray/tune/examples/durable_trainable_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ray.tune import DurableTrainable
from ray.tune.sync_client import get_sync_client

import cloudpickle
from ray import cloudpickle

logger = logging.getLogger(__name__)

Expand Down
3 changes: 1 addition & 2 deletions python/ray/tune/experiment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import copy
import logging
import os
import six

from ray.tune.error import TuneError
from ray.tune.registry import register_trainable, get_trainable_cls
Expand Down Expand Up @@ -189,7 +188,7 @@ def register_if_needed(cls, run_object):
A string representing the trainable identifier.
"""

if isinstance(run_object, six.string_types):
if isinstance(run_object, str):
return run_object
elif isinstance(run_object, sample_from):
logger.warning("Not registering trainable. Resolving as variant.")
Expand Down
3 changes: 1 addition & 2 deletions python/ray/tune/tune.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import six

from ray.tune.error import TuneError
from ray.tune.experiment import convert_to_experiment_list, Experiment
Expand Down Expand Up @@ -41,7 +40,7 @@ def _make_scheduler(args):


def _check_default_resources_override(run_identifier):
if not isinstance(run_identifier, six.string_types):
if not isinstance(run_identifier, str):
# If obscure dtype, assume it is overriden.
return True
trainable_cls = get_trainable_cls(run_identifier)
Expand Down
27 changes: 4 additions & 23 deletions python/ray/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import numpy as np
import os
import six
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -223,32 +222,14 @@ def decode(byte_str, allow_none=False):
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
if isinstance(s, str):
return s
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
assert isinstance(s, bytes)
return s.decode(encoding, errors)


def binary_to_object_id(binary_object_id):
Expand Down
21 changes: 3 additions & 18 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,24 +171,9 @@ def find_version(*filepath):


requires = [
"numpy >= 1.16",
"filelock",
"jsonschema",
"click",
"colorama",
"packaging",
"pyyaml",
"redis>=3.3.2",
# 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",
"faulthandler;python_version<'3.3'",
"protobuf >= 3.8.0",
"cloudpickle",
"py-spy >= 0.2.0",
"aiohttp",
"google",
"grpcio"
"numpy >= 1.16", "filelock", "jsonschema", "click", "colorama",
"packaging", "pyyaml", "redis >= 3.3.2", "protobuf >= 3.8.0",
"py-spy >= 0.2.0", "aiohttp", "google", "grpcio"
]

setup(
Expand Down
3 changes: 1 addition & 2 deletions rllib/agents/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import math
import os
import pickle
import six
import time
import tempfile

Expand Down Expand Up @@ -1022,7 +1021,7 @@ def __setstate__(self, state):
self.optimizer.restore(state["optimizer"])

def _register_if_needed(self, env_object):
if isinstance(env_object, six.string_types):
if isinstance(env_object, str):
return env_object
elif isinstance(env_object, type):
name = env_object.__name__
Expand Down
2 changes: 1 addition & 1 deletion rllib/env/policy_server_input.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
import six.moves.queue as queue
import queue
import threading
import traceback

Expand Down
2 changes: 1 addition & 1 deletion rllib/evaluation/sampler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict, namedtuple
import logging
import numpy as np
import six.moves.queue as queue
import queue
import threading
import time

Expand Down
5 changes: 2 additions & 3 deletions rllib/offline/json_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import logging
import os
import random
import six
from six.moves.urllib.parse import urlparse
from urllib.parse import urlparse

try:
from smart_open import smart_open
Expand Down Expand Up @@ -39,7 +38,7 @@ def __init__(self, inputs, ioctx=None):
"""

self.ioctx = ioctx or IOContext()
if isinstance(inputs, six.string_types):
if isinstance(inputs, str):
inputs = os.path.abspath(os.path.expanduser(inputs))
if os.path.isdir(inputs):
inputs = os.path.join(inputs, "*.json")
Expand Down
3 changes: 1 addition & 2 deletions rllib/policy/sample_batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import six
import collections
import numpy as np

Expand Down Expand Up @@ -49,7 +48,7 @@ def __init__(self, *args, **kwargs):
self.data = dict(*args, **kwargs)
lengths = []
for k, v in self.data.copy().items():
assert isinstance(k, six.string_types), self
assert isinstance(k, str), self
lengths.append(len(v))
self.data[k] = np.array(v, copy=False)
if not lengths:
Expand Down
2 changes: 1 addition & 1 deletion streaming/python/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from abc import ABC, abstractmethod
import typing

import cloudpickle
from ray import cloudpickle
from ray.streaming.runtime import gateway_client


Expand Down
2 changes: 1 addition & 1 deletion streaming/python/partition.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import importlib
from abc import ABC, abstractmethod

import cloudpickle
from ray import cloudpickle
from ray.streaming.runtime import gateway_client


Expand Down

0 comments on commit ee8c9ff

Please sign in to comment.