[Checkins] SVN: hurry.resource/trunk/src/hurry/resource/ Allow the user to explicitly specify the package in which the library
Martijn Faassen
faassen at startifact.com
Sat Jul 24 09:38:49 EDT 2010
Log message for revision 115006:
Allow the user to explicitly specify the package in which the library
source resides.
Changed:
U hurry.resource/trunk/src/hurry/resource/README.txt
U hurry.resource/trunk/src/hurry/resource/core.py
-=-
Modified: hurry.resource/trunk/src/hurry/resource/README.txt
===================================================================
--- hurry.resource/trunk/src/hurry/resource/README.txt 2010-07-24 13:28:57 UTC (rev 115005)
+++ hurry.resource/trunk/src/hurry/resource/README.txt 2010-07-24 13:38:49 UTC (rev 115006)
@@ -31,18 +31,27 @@
A resource library
==================
-We define a library ``foo``. It takes two arguments, the name of the library
-as it should be published under in a URL and uniquely identify it, and a path
-to the root of the resources that this library publishes::
+We define a library ``foo``. It takes two arguments, the name of the
+library as it should be published under in a URL and uniquely identify
+it, and a path to the root of the resources (rootpath) that this
+library publishes::
>>> from hurry.resource import Library
>>> foo = Library('foo', 'dummy')
-The full path to the directory with the resources is reconstructed::
+The full path to the directory with the resources is reconstructed from
+the package that the Library is defined in::
>>> foo.path #doctest: +ELLIPSIS
'.../hurry.resource/src/hurry/resource/dummy'
+You can also give a package that contains the rootpath explicitly::
+
+ >>> import hurry.resource
+ >>> bar = Library('foo', 'dummy', package=hurry.resource)
+ >>> bar.path #doctest: +ELLIPSIS
+ '.../hurry.resource/src/hurry/resource/dummy'
+
Entry points
============
Modified: hurry.resource/trunk/src/hurry/resource/core.py
===================================================================
--- hurry.resource/trunk/src/hurry/resource/core.py 2010-07-24 13:28:57 UTC (rev 115005)
+++ hurry.resource/trunk/src/hurry/resource/core.py 2010-07-24 13:38:49 UTC (rev 115006)
@@ -18,10 +18,14 @@
class Library(object):
implements(interfaces.ILibrary)
- def __init__(self, name, rootpath):
+ def __init__(self, name, rootpath, package=None):
self.name = name
self.rootpath = rootpath
- self.path = pkg_resources.resource_filename(__name__, rootpath)
+ if package is not None:
+ name = package.__name__
+ else:
+ name = __name__
+ self.path = pkg_resources.resource_filename(name, rootpath)
def libraries():
return pkg_resources.iter_entry_points('hurry.resource.libraries')
More information about the checkins
mailing list