remove six and __future__ imports (#1840)

* remove six

* remove __future__ imports

* remove six from setup.py, python 2.7 from README.rst
This commit is contained in:
pzhokhov
2020-04-10 17:10:34 -05:00
committed by GitHub
parent a8a3d36353
commit 67212547ac
17 changed files with 24 additions and 46 deletions

View File

@@ -48,7 +48,7 @@ should know:
Supported systems
-----------------
We currently support Linux and OS X running Python 2.7 or 3.5 -- 3.7.
We currently support Linux and OS X running Python 3.5 -- 3.8
Windows support is experimental - algorithmic, toy_text, classic_control and atari *should* work on Windows (see next section for installation instructions); nevertheless, proceed at your own risk.
Installation

View File

@@ -1,9 +1,7 @@
from __future__ import print_function
import gym
from gym import wrappers, logger
import numpy as np
from six.moves import cPickle as pickle
import pickle
import json, sys, os
from os import path
from _policies import BinaryActionLinearPolicy # Different file so it can be unpickled

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function
import sys, gym, time
#

View File

@@ -36,7 +36,7 @@ from gym.utils import colorize, seeding
import sys
from contextlib import closing
import numpy as np
from six import StringIO
from io import StringIO
class AlgorithmicEnv(Env):

View File

@@ -2,7 +2,6 @@
Task is to return every nth character from the input tape.
http://arxiv.org/abs/1511.07275
"""
from __future__ import division
from gym.envs.algorithmic import algorithmic_env

View File

@@ -1,4 +1,3 @@
from __future__ import division
from gym.envs.algorithmic import algorithmic_env

View File

@@ -1,9 +1,7 @@
"""
2D rendering framework
"""
from __future__ import division
import os
import six
import sys
if "Apple" in sys.version:
@@ -46,7 +44,7 @@ def get_display(spec):
"""
if spec is None:
return None
elif isinstance(spec, six.string_types):
elif isinstance(spec, str):
return pyglet.canvas.Display(spec)
else:
raise error.Error('Invalid display specification: {}. (Must be a string like :0 or None.)'.format(spec))

View File

@@ -51,7 +51,6 @@ def test_random_rollout():
def test_env_render_result_is_immutable():
from six import string_types
environs = [
envs.make('Taxi-v3'),
envs.make('FrozenLake-v0'),
@@ -61,5 +60,5 @@ def test_env_render_result_is_immutable():
for env in environs:
env.reset()
output = env.render(mode='ansi')
assert isinstance(output, string_types)
assert isinstance(output, str)
env.close()

View File

@@ -4,7 +4,6 @@ Hashed str representation of objects
"""
from __future__ import unicode_literals
import json
import hashlib
import os

View File

@@ -2,7 +2,7 @@ import sys
from contextlib import closing
import numpy as np
from six import StringIO, b
from io import StringIO
from gym import utils
from gym.envs.toy_text import discrete

View File

@@ -1,6 +1,6 @@
import sys
from contextlib import closing
from six import StringIO
from io import StringIO
from gym import utils
from gym.envs.toy_text import discrete
import numpy as np

View File

@@ -21,15 +21,10 @@ def colorize(string, color, bold=False, highlight = False):
blue, magenta, cyan, white, crimson
"""
# Import six here so that `utils` has no import-time dependencies.
# We want this since we use `utils` during our import-time sanity checks
# that verify that our dependencies (including six) are actually present.
import six
attr = []
num = color2num[color]
if highlight: num += 10
attr.append(six.u(str(num)))
if bold: attr.append(six.u('1'))
attrs = six.u(';').join(attr)
return six.u('\x1b[%sm%s\x1b[0m') % (attrs, string)
attr.append(str(num))
if bold: attr.append('1')
attrs = ';'.join(attr)
return '\x1b[%sm%s\x1b[0m' % (attrs, string)

View File

@@ -2,14 +2,13 @@ import hashlib
import numpy as np
import os
import random as _random
from six import integer_types
import struct
import sys
from gym import error
def np_random(seed=None):
if seed is not None and not (isinstance(seed, integer_types) and 0 <= seed):
if seed is not None and not (isinstance(seed, int) and 0 <= seed):
raise error.Error('Seed must be a non-negative integer or omitted, not {}'.format(seed))
seed = create_seed(seed)
@@ -58,7 +57,7 @@ def create_seed(a=None, max_bytes=8):
a = a.encode('utf8')
a += hashlib.sha512(a).digest()
a = _bigint_from_bytes(a[:max_bytes])
elif isinstance(a, integer_types):
elif isinstance(a, int):
a = a % 2**(8 * max_bytes)
else:
raise error.Error('Invalid type for seed: {} ({})'.format(type(a), a))

View File

@@ -1,7 +1,7 @@
import gym
from gym import Wrapper
from gym import error, version, logger
import os, json, numpy as np, six
import os, json, numpy as np
from gym.wrappers.monitoring import stats_recorder, video_recorder
from gym.utils import atomic_write, closer
from gym.utils.json_utils import json_encode_np
@@ -66,10 +66,7 @@ class Monitor(Wrapper):
if not os.path.exists(directory):
logger.info('Creating monitor directory %s', directory)
if six.PY3:
os.makedirs(directory, exist_ok=True)
else:
os.makedirs(directory)
os.makedirs(directory, exist_ok=True)
if video_callable is None:
video_callable = capped_cubic_video_schedule

View File

@@ -5,8 +5,7 @@ import tempfile
import os.path
import distutils.spawn, distutils.version
import numpy as np
from six import StringIO
import six
from io import StringIO
from gym import error, logger
def touch(path):
@@ -182,9 +181,8 @@ class TextEncoder(object):
self.frames = []
def capture_frame(self, frame):
from six import string_types
string = None
if isinstance(frame, string_types):
if isinstance(frame, str):
string = frame
elif isinstance(frame, StringIO):
string = frame.getvalue()
@@ -193,10 +191,10 @@ class TextEncoder(object):
frame_bytes = string.encode('utf-8')
if frame_bytes[-1:] != six.b('\n'):
if frame_bytes[-1:] != b'\n':
raise error.InvalidFrame('Frame must end with a newline: """{}"""'.format(string))
if six.b('\r') in frame_bytes:
if b'\r' in frame_bytes:
raise error.InvalidFrame('Frame contains carriage returns (only newlines are allowed: """{}"""'.format(string))
self.frames.append(frame_bytes)
@@ -208,14 +206,14 @@ class TextEncoder(object):
# Turn frames into events: clear screen beforehand
# https://rosettacode.org/wiki/Terminal_control/Clear_the_screen#Python
# https://rosettacode.org/wiki/Terminal_control/Cursor_positioning#Python
clear_code = six.b("%c[2J\033[1;1H" % (27))
clear_code = b"%c[2J\033[1;1H" % (27)
# Decode the bytes as UTF-8 since JSON may only contain UTF-8
events = [ (frame_duration, (clear_code+frame.replace(six.b('\n'),six.b('\r\n'))).decode('utf-8')) for frame in self.frames ]
events = [ (frame_duration, (clear_code+frame.replace(b'\n', b'\r\n')).decode('utf-8')) for frame in self.frames ]
# Calculate frame size from the largest frames.
# Add some padding since we'll get cut off otherwise.
height = max([frame.count(six.b('\n')) for frame in self.frames]) + 1
width = max([max([len(line) for line in frame.split(six.b('\n'))]) for frame in self.frames]) + 2
height = max([frame.count(b'\n') for frame in self.frames]) + 1
width = max([max([len(line) for line in frame.split(b'\n')]) for frame in self.frames]) + 2
data = {
"version": 1,

View File

@@ -1,4 +1,3 @@
from __future__ import unicode_literals
from gym import envs, spaces, logger
import json
import os

View File

@@ -28,7 +28,7 @@ setup(name='gym',
if package.startswith('gym')],
zip_safe=False,
install_requires=[
'scipy', 'numpy>=1.10.4', 'six', 'pyglet>=1.4.0,<=1.5.0', 'cloudpickle>=1.2.0,<1.4.0',
'scipy', 'numpy>=1.10.4', 'pyglet>=1.4.0,<=1.5.0', 'cloudpickle>=1.2.0,<1.4.0',
'enum34~=1.1.6;python_version<"3.4"',
],
extras_require=extras,