Skip to content

Commit

Permalink
Improve logic of URI resolution adding more environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed Feb 9, 2023
1 parent 2b623ab commit b3ef67b
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/rod/utils/resolve_uris.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import pathlib
from typing import List

from rod import Geometry, logging

Expand All @@ -8,7 +9,15 @@ def resolve_local_uri(uri: str) -> pathlib.Path:
# Remove the prefix of the URI
uri_no_prefix = uri.split(sep="//")[-1]

for path in os.environ["IGN_GAZEBO_RESOURCE_PATH"].split(":"):
paths = []
paths += paths_from_environment_variable("GZ_SIM_RESOURCE_PATH")
paths += paths_from_environment_variable("IGN_GAZEBO_RESOURCE_PATH")
paths += paths_from_environment_variable("GAZEBO_MODEL_PATH")

# Remove possible duplicates
paths = list(set(paths))

for path in paths:
tentative = pathlib.Path(path) / uri_no_prefix

if tentative.is_file():
Expand All @@ -24,3 +33,16 @@ def resolve_geometry_uris(geometry: Geometry) -> None:
return

geometry.mesh.uri = str(resolve_local_uri(uri=geometry.mesh.uri))


def paths_from_environment_variable(variable_name: str) -> List[str]:
if variable_name not in os.environ:
return []

# Collect all paths removing the empty ones (if '::' is part of the variable)
paths = [p for p in os.environ[variable_name].split(":") if p != ""]

# Remove duplicates that might occur
paths = list(set(paths))

return paths

0 comments on commit b3ef67b

Please sign in to comment.