[Checkins] SVN: hurry.resource/trunk/src/hurry/resource/ It turned out that the previous method for getting the base resource

Martijn Faassen faassen at startifact.com
Sat Jul 24 11:55:45 EDT 2010


Log message for revision 115023:
  It turned out that the previous method for getting the base resource
  directory path didn't work properly. Instead use a hack to do this 
  more reliably.
  

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 15:54:30 UTC (rev 115022)
+++ hurry.resource/trunk/src/hurry/resource/README.txt	2010-07-24 15:55:45 UTC (rev 115023)
@@ -45,13 +45,6 @@
   >>> 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 15:54:30 UTC (rev 115022)
+++ hurry.resource/trunk/src/hurry/resource/core.py	2010-07-24 15:55:45 UTC (rev 115023)
@@ -1,4 +1,4 @@
-import os
+import os, sys
 from types import TupleType
 import pkg_resources
 
@@ -18,17 +18,19 @@
 class Library(object):
     implements(interfaces.ILibrary)
     
-    def __init__(self, name, rootpath, package=None):
+    def __init__(self, name, rootpath):
         self.name = name
         self.rootpath = rootpath
-        if package is not None:
-            name = package.__name__
-        else:
-            name = __name__
-        self.path = pkg_resources.resource_filename(name, rootpath)
+        self.path = os.path.join(caller_dir(), rootpath)
 
+# total hack to be able to get the dir the resources will be in
+def caller_dir():
+    return os.path.dirname(sys._getframe(2).f_globals['__file__'])
+
 def libraries():
-    return pkg_resources.iter_entry_points('hurry.resource.libraries')
+    for entry_point in pkg_resources.iter_entry_points(
+        'hurry.resource.libraries'):
+        yield entry_point.load()
 
 class InclusionBase(object):
     implements(interfaces.IInclusion)



More information about the checkins mailing list