@@ -53,41 +53,44 @@ def loaddata(filename, handler, **kwargs):
53
53
path = path_to_datafile (filename )
54
54
return handler (path , ** kwargs )
55
55
56
- def path_to_datafile (filename , local = False ):
56
+ def path_to_datafile (* filename , local = True ):
57
57
"""
58
58
Get absolute path to datafile
59
59
60
60
:param filename: pathname of datafile
61
61
:type filename: str
62
+ :param local: search for file locally first, default True
63
+ :type local: bool
62
64
:raises FileNotFoundError: File does not exist
63
65
:return: Absolute path
64
66
:rtype: Path
65
67
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``.
69
69
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.
72
75
73
76
Example::
74
77
75
- loadmat('map1.mat') # read ...roboticstoolbox /data/map1.mat
78
+ loadmat('data/ map1.mat') # read rtbdata /data/map1.mat
76
79
loadmat('foo.dat') # read ./foo.dat
77
- loadmat('~/data/ foo.dat') # read ~/data /foo.dat
80
+ loadmat('~/foo.dat') # read $HOME /foo.dat
78
81
"""
79
82
80
- filename = Path (filename )
83
+ filename = Path (* filename )
81
84
82
85
if local :
83
86
# check if file is in user's local filesystem
84
87
85
88
p = filename .expanduser ()
86
89
p = p .resolve ()
87
90
if p .exists ():
88
- return str ( p )
91
+ return p
89
92
90
- # assume it is in rtbdata
93
+ # otherwise, look for it in rtbdata
91
94
92
95
rtbdata = importlib .import_module ("rtbdata" )
93
96
root = Path (rtbdata .__path__ [0 ])
0 commit comments