Skip to content

Commit

Permalink
Resolve path only if accessible, otherwise return unchanged
Browse files Browse the repository at this point in the history
Fixes cctbx#771
  • Loading branch information
dagewa committed Nov 22, 2024
1 parent ea6fd5f commit ad079dc
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/dxtbx/serialize/filename.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ def resolve_path(path, directory=None):
directory (Optional[str]): The local path to resolve relative links
Returns:
str: The absolute path to the file to read
str: The absolute path to the file to read if accessible, otherwise
return the original path as provided
"""
if not path:
return ""
path = os.path.expanduser(os.path.expandvars(path))
if directory and not os.path.isabs(path):
path = os.path.join(directory, path)
return os.path.abspath(path)
trial_path = os.path.expanduser(os.path.expandvars(path))
if directory and not os.path.isabs(trial_path):
trial_path = os.path.join(directory, trial_path)
if os.path.exists(trial_path):
return os.path.abspath(trial_path)
else:
return path

0 comments on commit ad079dc

Please sign in to comment.