blob: e5904f360dfa346697661deca6ddd01367b4d069 [file] [log] [blame]
Tarek Ziade1231a4e2011-05-19 13:07:25 +02001"""Data file path abstraction.
2
3Functions in this module use sysconfig to find the paths to the resource
4files registered in project's setup.cfg file. See the documentation for
5more information.
6"""
7# TODO write that documentation
8
9from packaging.database import get_distribution
10
11__all__ = ['get_file_path', 'get_file']
12
13
14def get_file_path(distribution_name, relative_path):
15 """Return the path to a resource file."""
16 dist = get_distribution(distribution_name)
17 if dist != None:
18 return dist.get_resource_path(relative_path)
19 raise LookupError('no distribution named %r found' % distribution_name)
20
21
22def get_file(distribution_name, relative_path, *args, **kwargs):
23 """Open and return a resource file."""
24 return open(get_file_path(distribution_name, relative_path),
25 *args, **kwargs)