Skip to content

Commit

Permalink
Correctly resolve root_dir
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Jan 14, 2025
1 parent 5ae92bb commit 662dfdc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions xacro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@
filestack = None
macrostack = None

# Allow the user to override the root directory that relative
# paths will be resolved to
root_dir = os.curdir


def init_stacks(file):
global filestack
global macrostack
Expand Down Expand Up @@ -1015,10 +1018,10 @@ def parse(inp, filename=None):
:return:xml.dom.minidom.Document
:raise: xml.parsers.expat.ExpatError
"""
global root_dir
f = None
if inp is None:
try:
global root_dir
inp = f = open(os.path.join(root_dir, filename))
except IOError as e:
# do not report currently processed file as "in file ..."
Expand Down Expand Up @@ -1103,10 +1106,6 @@ def process_file(input_file_name, **kwargs):
# initialize file stack for error-reporting
init_stacks(input_file_name)

global root_dir
if 'root_dir' in kwargs:
root_dir = kwargs['root_dir']

# parse the document into a xml.dom tree
doc = parse(None, input_file_name)
# perform macro replacement
Expand All @@ -1129,6 +1128,10 @@ def process_file(input_file_name, **kwargs):


def _process(input_file_name, opts):
if 'root_dir' in opts and opts['root_dir']:
global root_dir
root_dir = opts['root_dir']

try:
# open and process file
doc = process_file(input_file_name, **opts)
Expand Down
2 changes: 1 addition & 1 deletion xacro/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def process_args(argv, require_input=True):
help="print file dependencies")
parser.add_option("--inorder", "-i", action="store_true", dest="in_order",
help="processing in read order (default, can be omitted)")
parser.add_option("--root-dir", dest="root_dir", metavar="DIR",
parser.add_option("--root-dir", dest="root_dir", metavar="DIR", default=None,
help="set the root directory to resolve relative paths to")

# verbosity options
Expand Down

0 comments on commit 662dfdc

Please sign in to comment.