mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-08-23 15:04:20 +00:00
remove reraise logic (#1342)
* remove reraise logic - replace with re-raising import errors in the only place it is used * remove reraise * remove reset call from MountainCar constructor * further remove reraise * remove reraise import in classic_control/rendering.py
This commit is contained in:
@@ -4,7 +4,6 @@ import sys
|
||||
import warnings
|
||||
|
||||
from gym import error
|
||||
from gym.utils import reraise
|
||||
from gym.version import VERSION as __version__
|
||||
|
||||
from gym.core import Env, GoalEnv, Wrapper, ObservationWrapper, ActionWrapper, RewardWrapper
|
||||
|
@@ -35,7 +35,6 @@ class MountainCarEnv(gym.Env):
|
||||
self.observation_space = spaces.Box(self.low, self.high, dtype=np.float32)
|
||||
|
||||
self.seed()
|
||||
self.reset()
|
||||
|
||||
def seed(self, seed=None):
|
||||
self.np_random, seed = seeding.np_random(seed)
|
||||
|
@@ -11,18 +11,27 @@ if "Apple" in sys.version:
|
||||
os.environ['DYLD_FALLBACK_LIBRARY_PATH'] += ':/usr/lib'
|
||||
# (JDS 2016/04/15): avoid bug on Anaconda 2.3.0 / Yosemite
|
||||
|
||||
from gym.utils import reraise
|
||||
from gym import error
|
||||
|
||||
try:
|
||||
import pyglet
|
||||
except ImportError as e:
|
||||
reraise(suffix="HINT: you can install pyglet directly via 'pip install pyglet'. But if you really just want to install all Gym dependencies and not have to think about it, 'pip install -e .[all]' or 'pip install gym[all]' will do it.")
|
||||
raise ImportError('''
|
||||
Cannot import pyglet.
|
||||
HINT: you can install pyglet directly via 'pip install pyglet'.
|
||||
But if you really just want to install all Gym dependencies and not have to think about it,
|
||||
'pip install -e .[all]' or 'pip install gym[all]' will do it.
|
||||
''')
|
||||
|
||||
try:
|
||||
from pyglet.gl import *
|
||||
except ImportError as e:
|
||||
reraise(prefix="Error occured while running `from pyglet.gl import *`",suffix="HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'. If you're running on a server, you may need a virtual frame buffer; something like this should work: 'xvfb-run -s \"-screen 0 1400x900x24\" python <your_script.py>'")
|
||||
raise ImportError('''
|
||||
Error occured while running `from pyglet.gl import *`
|
||||
HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'.
|
||||
If you're running on a server, you may need a virtual frame buffer; something like this should work:
|
||||
'xvfb-run -s \"-screen 0 1400x900x24\" python <your_script.py>'
|
||||
''')
|
||||
|
||||
import math
|
||||
import numpy as np
|
||||
|
@@ -7,4 +7,3 @@ not intended as API functions, and will not remain stable over time.
|
||||
# that verify that our dependencies are actually present.
|
||||
from .colorize import colorize
|
||||
from .ezpickle import EzPickle
|
||||
from .reraise import reraise
|
||||
|
@@ -1,41 +0,0 @@
|
||||
import sys
|
||||
|
||||
# We keep the actual reraising in different modules, since the
|
||||
# reraising code uses syntax mutually exclusive to Python 2/3.
|
||||
if sys.version_info[0] < 3:
|
||||
from .reraise_impl_py2 import reraise_impl #pylint: disable=E0401
|
||||
else:
|
||||
from .reraise_impl_py3 import reraise_impl
|
||||
|
||||
def reraise(prefix=None, suffix=None):
|
||||
old_exc_type, old_exc_value, traceback = sys.exc_info()
|
||||
if old_exc_value is None:
|
||||
old_exc_value = old_exc_type()
|
||||
|
||||
e = ReraisedException(old_exc_value, prefix, suffix)
|
||||
|
||||
reraise_impl(e, traceback)
|
||||
|
||||
# http://stackoverflow.com/a/13653312
|
||||
def full_class_name(o):
|
||||
module = o.__class__.__module__
|
||||
if module is None or module == str.__class__.__module__:
|
||||
return o.__class__.__name__
|
||||
return module + '.' + o.__class__.__name__
|
||||
|
||||
class ReraisedException(Exception):
|
||||
def __init__(self, old_exc, prefix, suffix):
|
||||
self.old_exc = old_exc
|
||||
self.prefix = prefix
|
||||
self.suffix = suffix
|
||||
|
||||
def __str__(self):
|
||||
klass = self.old_exc.__class__
|
||||
|
||||
orig = "%s: %s" % (full_class_name(self.old_exc), klass.__str__(self.old_exc))
|
||||
prefixpart = suffixpart = ''
|
||||
if self.prefix is not None:
|
||||
prefixpart = self.prefix + "\n"
|
||||
if self.suffix is not None:
|
||||
suffixpart = "\n\n" + self.suffix
|
||||
return "%sThe original exception was:\n\n%s%s" % (prefixpart, orig, suffixpart)
|
@@ -1,2 +0,0 @@
|
||||
def reraise_impl(e, traceback):
|
||||
raise e.__class__, e, traceback
|
@@ -1,4 +0,0 @@
|
||||
# http://stackoverflow.com/a/33822606 -- `from None` disables Python 3'
|
||||
# semi-smart exception chaining, which we don't want in this case.
|
||||
def reraise_impl(e, traceback):
|
||||
raise e.with_traceback(traceback) from None
|
Reference in New Issue
Block a user