fix python2 compatibility

This commit is contained in:
fxia22 2020-12-22 12:17:44 -08:00
parent 66263f48b1
commit 9eb883fa8f
16 changed files with 48 additions and 41 deletions

View File

@ -1074,7 +1074,7 @@ class MeshRenderer(object):
or_buffer_idx_end = len(duplicate_vao_ids)
# Store indices in the duplicate vao ids array, and hence the optimized rendering buffers, that this Instance will use
instance.or_buffer_indices = list(
np.arange(or_buffer_idx_start, or_buffer_idx_end)).copy()
np.arange(or_buffer_idx_start, or_buffer_idx_end))
class_id_array.extend(
[float(instance.class_id) / 255.0] * len(ids))
pbr_data_array.extend(
@ -1094,7 +1094,7 @@ class MeshRenderer(object):
temp_or_buffer_indices.extend(
list(np.arange(or_buffer_idx_start, or_buffer_idx_end)))
id_sum += len(ids)
instance.or_buffer_indices = temp_or_buffer_indices.copy()
instance.or_buffer_indices = list(temp_or_buffer_indices)
class_id_array.extend(
[float(instance.class_id) / 255.0] * id_sum)
pbr_data_array.extend(

View File

@ -160,8 +160,10 @@ class Viewer:
link_state = p.getLinkState(object_id, link_id)
link_pos, link_orn = link_state[:2]
child_frame_trans_pos, child_frame_trans_orn = p.invertTransform(link_pos, link_orn)
child_frame_pos, child_frame_orn = \
p.multiplyTransforms(*p.invertTransform(link_pos, link_orn),
p.multiplyTransforms(child_frame_trans_pos,
child_frame_trans_orn,
hit_pos,
[0, 0, 0, 1])
self.constraint_marker.set_position(hit_pos)

View File

@ -1,12 +1,12 @@
from abc import abstractmethod, ABC
from abc import abstractmethod, ABCMeta
class BaseRewardFunction(ABC):
class BaseRewardFunction():
"""
Base RewardFunction class
Reward-specific reset and get_reward methods are implemented in subclasses
"""
__metaclass__ = ABCMeta
def __init__(self, config):
self.config = config

View File

@ -13,7 +13,7 @@ class EmptyScene(Scene):
"""
def __init__(self):
super().__init__()
super(EmptyScene, self).__init__()
def load(self):
"""

View File

@ -41,7 +41,7 @@ class StaticIndoorScene(IndoorScene):
:param waypoint_resolution: resolution of adjacent way points
:param pybullet_load_texture: whether to load texture into pybullet. This is for debugging purpose only and does not affect robot's observations
"""
super().__init__(
super(StaticIndoorScene, self).__init__(
scene_id,
trav_map_resolution,
trav_map_erosion,

View File

@ -66,7 +66,7 @@ class InteractiveIndoorScene(StaticIndoorScene):
:param scene_source: source of scene data; among IG, CUBICASA, THREEDFRONT
"""
super().__init__(
super(InteractiveIndoorScene, self).__init__(
scene_id,
trav_map_resolution,
trav_map_erosion,

View File

@ -41,7 +41,7 @@ class IndoorScene(Scene):
:param waypoint_resolution: resolution of adjacent way points
:param pybullet_load_texture: whether to load texture into pybullet. This is for debugging purpose only and does not affect robot's observations
"""
super().__init__()
super(IndoorScene, self).__init__()
logging.info("IndoorScene model: {}".format(scene_id))
self.scene_id = scene_id
self.trav_map_default_resolution = 0.01 # each pixel represents 0.01m

View File

@ -13,7 +13,7 @@ class StadiumScene(Scene):
"""
def __init__(self):
super().__init__()
super(StadiumScene, self).__init__()
def load(self):
"""

View File

@ -1,12 +1,12 @@
from abc import abstractmethod, ABC
from abc import abstractmethod, ABCMeta
class BaseSensor(ABC):
class BaseSensor():
"""
Base Sensor class.
Sensor-specific get_obs method is implemented in subclasses
"""
__metaclass__ = ABCMeta
def __init__(self, env):
self.config = env.config

View File

@ -1,12 +1,12 @@
from abc import abstractmethod, ABC
from abc import abstractmethod, ABCMeta
class BaseSensorNoise(ABC):
class BaseSensorNoise():
"""
Base SensorNoise class.
Sensor noise-specific add_noise method is implemented in subclasses
"""
__metaclass__ = ABCMeta
def __init__(self, env):
self.config = env.config

View File

@ -311,7 +311,7 @@ class Simulator:
visual_object = None
if type == p.GEOM_MESH:
filename = filename.decode('utf-8')
if (filename, (*dimensions)) not in self.visual_objects.keys():
if (filename, tuple(dimensions)) not in self.visual_objects.keys():
self.renderer.load_object(filename,
transform_orn=rel_orn,
transform_pos=rel_pos,
@ -319,9 +319,9 @@ class Simulator:
scale=np.array(dimensions),
texture_scale=texture_scale,
load_texture=load_texture)
self.visual_objects[(filename, (*dimensions))
self.visual_objects[(filename, tuple(dimensions))
] = len(self.renderer.visual_objects) - 1
visual_object = self.visual_objects[(filename, (*dimensions))]
visual_object = self.visual_objects[(filename, tuple(dimensions))]
elif type == p.GEOM_SPHERE:
filename = os.path.join(
gibson2.assets_path, 'models/mjcf_primitives/sphere8.obj')
@ -404,7 +404,7 @@ class Simulator:
id, link_id, type, dimensions, filename, rel_pos, rel_orn, color = shape[:8]
if type == p.GEOM_MESH:
filename = filename.decode('utf-8')
if (filename, (*dimensions)) not in self.visual_objects.keys():
if (filename, tuple(dimensions)) not in self.visual_objects.keys():
overwrite_material = None
if visual_mesh_to_material is not None and filename in visual_mesh_to_material:
overwrite_material = visual_mesh_to_material[filename]
@ -415,10 +415,10 @@ class Simulator:
input_kd=color[:3],
scale=np.array(dimensions),
overwrite_material=overwrite_material)
self.visual_objects[(filename, (*dimensions))
self.visual_objects[(filename, tuple(dimensions))
] = len(self.renderer.visual_objects) - 1
visual_objects.append(
self.visual_objects[(filename, (*dimensions))])
self.visual_objects[(filename, tuple(dimensions))])
link_ids.append(link_id)
elif type == p.GEOM_SPHERE:
filename = os.path.join(
@ -496,16 +496,16 @@ class Simulator:
id, link_id, type, dimensions, filename, rel_pos, rel_orn, color = shape[:8]
if type == p.GEOM_MESH:
filename = filename.decode('utf-8')
if (filename, (*dimensions)) not in self.visual_objects.keys():
if (filename, tuple(dimensions)) not in self.visual_objects.keys():
self.renderer.load_object(filename,
transform_orn=rel_orn,
transform_pos=rel_pos,
input_kd=color[:3],
scale=np.array(dimensions))
self.visual_objects[(filename, (*dimensions))
self.visual_objects[(filename, tuple(dimensions))
] = len(self.renderer.visual_objects) - 1
visual_objects.append(
self.visual_objects[(filename, (*dimensions))])
self.visual_objects[(filename, tuple(dimensions))])
link_ids.append(link_id)
elif type == p.GEOM_SPHERE:
filename = os.path.join(

View File

@ -1,13 +1,13 @@
from abc import abstractmethod, ABC
from abc import abstractmethod, ABCMeta
class BaseTask(ABC):
class BaseTask():
"""
Base Task class.
Task-specific reset_scene, reset_agent, get_task_obs, step methods are implemented in subclasses
Subclasses are expected to populate self.reward_functions and self.termination_conditions
"""
__metaclass__ = ABCMeta
def __init__(self, env):
self.config = env.config
self.reward_functions = []

View File

@ -1,4 +1,3 @@
from abc import abstractmethod, ABC
from gibson2.termination_conditions.termination_condition_base import BaseTerminationCondition

View File

@ -1,11 +1,12 @@
from abc import abstractmethod, ABC
from abc import abstractmethod, ABCMeta
class BaseTerminationCondition(ABC):
class BaseTerminationCondition():
"""
Base TerminationCondition class
Condition-specific get_termination method is implemented in subclasses
"""
__metaclass__ = ABCMeta
def __init__(self, config):
self.config = config

View File

@ -36,11 +36,11 @@ class MotionPlanningWrapper(object):
"""
def __init__(self,
env: iGibsonEnv = None,
base_mp_algo: str = 'birrt',
arm_mp_algo: str = 'birrt',
optimize_iter: int = 0,
fine_motion_plan: bool = True):
env=None,
base_mp_algo='birrt',
arm_mp_algo='birrt',
optimize_iter=0,
fine_motion_plan=True):
"""
Get planning related parameters.
"""

View File

@ -13,7 +13,7 @@ import subprocess
import platform
import codecs
import platform
import sys
use_clang = False
@ -105,8 +105,13 @@ class PostInstallCommand(install):
check_call("bash realenv/envs/build.sh".split())
install.run(self)
'''
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
if sys.version_info.major == 3:
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
else:
# for python2
with open("README.md", "r") as fh:
long_description = fh.read()
setup(
name='gibson2',
@ -137,7 +142,7 @@ setup(
'future',
'trimesh',
'sphinx_markdown_tables',
'sphinx==2.2.1',
'sphinx>=1.8.0',
'recommonmark',
'sphinx_rtd_theme'
],