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

PyMJCF nested include tags relative to base model #417

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
9 changes: 6 additions & 3 deletions dm_control/mjcf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def from_file(file_handle, escape_separators=False,


def from_path(path, escape_separators=False, resolve_references=True,
assets=None):
assets=None, model_dir=None):
"""Parses an XML file into an MJCF object model.

Args:
Expand All @@ -94,11 +94,14 @@ def from_path(path, escape_separators=False, resolve_references=True,
assets: (optional) A dictionary of pre-loaded assets, of the form
`{filename: bytestring}`. If present, PyMJCF will search for assets in
this dictionary before attempting to load them from the filesystem.
model_dir: (optional) Path to the directory containing the model XML file.
This is used to prefix the paths of all asset files.

Returns:
An `mjcf.RootElement`.
"""
model_dir, _ = os.path.split(path)
if model_dir is None:
model_dir, _ = os.path.split(path)
contents = resources.GetResource(path)
xml_root = etree.fromstring(contents)
return _parse(xml_root, escape_separators,
Expand Down Expand Up @@ -153,7 +156,7 @@ def _parse(xml_root, escape_separators=False,
path_or_xml_string,
escape_separators=escape_separators,
resolve_references=resolve_references,
assets=assets)
assets=assets, model_dir=model_dir)
to_include.append(included_mjcf)
# We must remove <include/> tags before parsing the main XML file, since
# these are a schema violation.
Expand Down