Skip to content

Commit 02986a8

Browse files
committed
PyMJCF nested include tags relative to base model
1 parent d6f9cb4 commit 02986a8

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

dm_control/mjcf/parser.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def from_file(file_handle, escape_separators=False,
8080

8181

8282
def from_path(path, escape_separators=False, resolve_references=True,
83-
assets=None):
83+
assets=None, model_dir=None):
8484
"""Parses an XML file into an MJCF object model.
8585
8686
Args:
@@ -94,11 +94,14 @@ def from_path(path, escape_separators=False, resolve_references=True,
9494
assets: (optional) A dictionary of pre-loaded assets, of the form
9595
`{filename: bytestring}`. If present, PyMJCF will search for assets in
9696
this dictionary before attempting to load them from the filesystem.
97+
model_dir: (optional) Path to the directory containing the model XML file.
98+
This is used to prefix the paths of all asset files.
9799
98100
Returns:
99101
An `mjcf.RootElement`.
100102
"""
101-
model_dir, _ = os.path.split(path)
103+
if model_dir is None:
104+
model_dir, _ = os.path.split(path)
102105
contents = resources.GetResource(path)
103106
xml_root = etree.fromstring(contents)
104107
return _parse(xml_root, escape_separators,
@@ -153,7 +156,7 @@ def _parse(xml_root, escape_separators=False,
153156
path_or_xml_string,
154157
escape_separators=escape_separators,
155158
resolve_references=resolve_references,
156-
assets=assets)
159+
assets=assets, model_dir=model_dir)
157160
to_include.append(included_mjcf)
158161
# We must remove <include/> tags before parsing the main XML file, since
159162
# these are a schema violation.

0 commit comments

Comments
 (0)