Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure environment variables with a helper method #17

Merged
merged 2 commits into from
Jun 9, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions gym_ignition_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
from typing import List
from pathlib import Path


def get_models_path() -> str:
Expand Down Expand Up @@ -80,3 +81,37 @@ def get_model_string(robot_name: str) -> str:
string = f.read()

return string


def setup_environment() -> None:
"""
Configure the environment variables.
"""

models_path = Path(get_models_path())

if not models_path.exists():
raise NotADirectoryError(f"Failed to find path '{models_path}'")

# Setup the environment to find the models
if "SDF_PATH" in os.environ:
os.environ["SDF_PATH"] += f":{models_path}"
else:
os.environ["SDF_PATH"] = f"{models_path}"

# Models with mesh files
# Workaround for https://github.com/osrf/sdformat/issues/227
models_with_mesh = ["panda", "iCubGazeboV2_5", "iCubGazeboSimpleCollisionsV2_5"]

# Setup the environment to find the mesh files
for model in models_with_mesh:

model_path = Path(get_models_path()) / model

if not model_path.exists():
raise NotADirectoryError(f"Failed to find path '{model_path}'")

if "IGN_FILE_PATH" in os.environ:
os.environ["IGN_FILE_PATH"] += f':{model_path}'
else:
os.environ["IGN_FILE_PATH"] = f'{model_path}'