8000 doco and allow os.path.join() like arguments · Global19/robotics-toolbox-python@a00008f · GitHub
[go: up one dir, main page]

Skip to content

Commit a00008f

Browse files
committed
doco and allow os.path.join() like arguments
1 parent 604cb56 commit a00008f

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

roboticstoolbox/tools/data.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,41 +53,44 @@ def loaddata(filename, handler, **kwargs):
5353
path = path_to_datafile(filename)
5454
return handler(path, **kwargs)
5555

56-
def path_to_datafile(filename, local=False):
56+
def path_to_datafile(*filename, local=True):
5757
"""
5858
Get absolute path to datafile
5959
6060
:param filename: pathname of datafile
6161
:type filename: str
62+
:param local: search for file locally first, default True
63+
:type local: bool
6264
:raises FileNotFoundError: File does not exist
6365
:return: Absolute path
6466
:rtype: Path
6567
66-
If ``filename`` contains no path specification eg. ``map1.mat`` it will
67-
first attempt to locate the file within the ``roboticstoolbox/data``
68-
folder and if found, return that absolute path.
68+
The positional arguments are joined, like ``os.path.join``.
6969
70-
Otherwise, ``~`` is expanded, the path made absolute, resolving symlinks
71-
and the file's existence is tested.
70+
If ``local`` is True then ``~`` is expanded and if the file exists, the
71+
path is made absolute, and symlinks resolved.
72+
73+
Otherwise, the file is sought within the ``rtbdata`` package and if found,
74+
return that absolute path.
7275
7376
Example::
7477
75-
loadmat('map1.mat') # read ...roboticstoolbox/data/map1.mat
78+
loadmat('data/map1.mat') # read rtbdata/data/map1.mat
7679
loadmat('foo.dat') # read ./foo.dat
77-
loadmat('~/data/foo.dat') # read ~/data/foo.dat
80+
loadmat('~/foo.dat') # read $HOME/foo.dat
7881
"""
7982

80-
filename = Path(filename)
83+
filename = Path(*filename)
8184

8285
if local:
8386
# check if file is in user's local filesystem
8487

8588
p = filename.expanduser()
8689
p = p.resolve()
8790
if p.exists():
88-
return str(p)
91+
return p
8992

90-
# assume it is in rtbdata
93+
# otherwise, look for it in rtbdata
9194

9295
rtbdata = importlib.import_module("rtbdata")
9396
root = Path(rtbdata.__path__[0])

0 commit comments

Comments
 (0)
0