@@ -239,12 +239,12 @@ def make_datasource(pkg_def, **kwargs):
239
239
240
240
`data_path` is the only allowed keyword argument.
241
241
242
- `pkg_def` is a dictionary with at least one key - 'name '. 'name ' is a
243
- string which may be contain hyphens e.g. ``nipy-templates`` .
242
+ `pkg_def` is a dictionary with at least one key - 'relpath '. 'relpath ' is a
243
+ relative path with unix forward slash separators .
244
244
245
245
The relative path to the data is found with::
246
246
247
- names = pkg_def['name'].split('- ')
247
+ names = pkg_def['name'].split('/ ')
248
248
rel_path = os.path.join(names)
249
249
250
250
We search for this relative path in the list of paths given by `data_path`.
@@ -255,11 +255,12 @@ def make_datasource(pkg_def, **kwargs):
255
255
Parameters
256
256
----------
257
257
pkg_def : dict
258
- dict containing at least the key 'name'. If the name contains hyphens
259
- these as taken as directory separators, so we find the relative path to
260
- the data with ``rel_pth = pkg_def['name'].replace('-', os.path.sep)``.
261
- `pkg_def` can also contain a key 'install hint' that we use in the
262
- returned error message from trying to use the resulting datasource
258
+ dict containing at least the key 'relpath'. 'relpath' is the data path of
259
+ the package relative to `data_path`. It is in unix path format (using
260
+ forward slashes as directory separators). `pkg_def` can also contain
261
+ optional keys 'name' (the name of the package), and / or a key 'install
262
+ hint' that we use in the returned error message from trying to use the
263
+ resulting datasource
263
264
data_path : sequence of strings or None, optional
264
265
sequence of paths in which to search for data. If None (the
265
266
default), then use ``get_data_path()``
@@ -274,21 +275,20 @@ def make_datasource(pkg_def, **kwargs):
274
275
data_path = kwargs .get ('data_path' )
275
276
if data_path is None :
276
277
data_path = get_data_path ()
277
- name = pkg_def ['name ' ]
278
- names = name .split ('- ' )
278
+ unix_relpath = pkg_def ['relpath ' ]
279
+ names = unix_relpath .split ('/ ' )
279
280
try :
280
281
pth = find_data_dir (data_path , * names )
281
282
except DataError , exception :
282
283
pth = [pjoin (this_data_path , * names )
283
284
for this_data_path in data_path ]
284
285
pkg_hint = pkg_def .get ('install hint' , DEFAULT_INSTALL_HINT )
285
- msg = '''%(exc)s;
286
- Is it possible you have not installed a data package?
287
- From the names, maybe you need data package "%(name)s"?
288
-
289
- %(pkg_hint)s''' % dict (exc = exception ,
290
- name = name ,
291
- pkg_hint = pkg_hint )
286
+ msg = ('%s; Is it possible you have not installed a data package?' %
287
+ exception )
288
+ if 'name' in pkg_def :
289
+ msg += '\n \n You may need the package "%s"' % pkg_def ['name' ]
290
+ if not pkg_hint is None :
291
+ msg += '\n \n %s' % pkg_hint
292
292
raise DataError (msg )
293
293
return VersionedDatasource (pth )
294
294
@@ -321,34 +321,37 @@ def datasource_or_bomber(pkg_def, **options):
321
321
Parameters
322
322
----------
323
323
pkg_def : dict
324
- dict containing at least key 'name '. Can optioanlly have key 'install
325
- hint' (for helpful error messages) and 'min version' giving the minimum
326
- necessary version string for the package.
324
+ dict containing at least key 'relpath '. Can optioanlly have keys 'name'
325
+ (package name), 'install hint' (for helpful error messages) and 'min
326
+ version' giving the minimum necessary version string for the package.
327
327
data_path : sequence of strings or None, optional
328
328
329
329
Returns
330
330
-------
331
331
ds : datasource or ``Bomber`` instance
332
332
'''
333
- name = pkg_def ['name ' ]
333
+ unix_relpath = pkg_def ['relpath ' ]
334
334
version = pkg_def .get ('min version' )
335
335
pkg_hint = pkg_def .get ('install hint' , DEFAULT_INSTALL_HINT )
336
- names = name .split ('- ' )
337
- rel_path = os .path .sep .join (names )
336
+ names = unix_relpath .split ('/ ' )
337
+ sys_relpath = os .path .sep .join (names )
338
338
try :
339
339
ds = make_datasource (pkg_def , ** options )
340
340
except DataError , exception :
341
- return Bomber (rel_path , exception )
341
+ return Bomber (sys_relpath , exception )
342
342
# check version
343
343
if (version is None or
344
344
LooseVersion (ds .version ) >= LooseVersion (version )):
345
345
return ds
346
- pkg_name = '-' .join (names )
346
+ if 'name' in pkg_def :
347
+ pkg_name = pkg_def ['name' ]
348
+ else :
349
+ pkg_name = 'data at ' + unix_relpath
347
350
msg = ('%(name)s is version %(pkg_version)s but we need '
348
351
'version >= %(req_version)s\n \n %(pkg_hint)s' %
349
- dict (name = name ,
352
+ dict (name = pkg_name ,
350
353
pkg_version = ds .version ,
351
354
req_version = version ,
352
355
pkg_hint = pkg_hint ))
353
- return Bomber (rel_path , DataError (msg ))
356
+ return Bomber (sys_relpath , DataError (msg ))
354
357
0 commit comments