Skip to content

Commit

Permalink
Fix processing model descriptions on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoferigo committed May 17, 2024
1 parent 7d08aee commit 1d009f9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/rod/utils/gazebo.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,19 @@ def process_model_description_with_sdformat(
# Get the Gazebo Sim executable (raises exception if not found)
gazebo_executable = GazeboHelper.get_gazebo_executable()

with tempfile.NamedTemporaryFile(mode="w+") as fp:
fp.write(model_description_string)
fp.seek(0)
# Operate on a file stored in a temporary directory.
# This is necessary on windows because the file has to be closed before
# it can be processed by the sdformat executable.
# As soon as 3.12 will be the minimum supported version, we can use just
# NamedTemporaryFile with the new delete_on_close=False parameter.
with tempfile.TemporaryDirectory() as tmp:

with tempfile.NamedTemporaryFile(
mode="w+", suffix=".xml", dir=tmp, delete=False
) as fp:

fp.write(model_description_string)
fp.close()

cp = subprocess.run(
[str(gazebo_executable), "sdf", "-p", fp.name],
Expand Down

0 comments on commit 1d009f9

Please sign in to comment.