summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-10-01 19:37:43 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-10-01 19:37:43 -0400
commitb19513c8f908ae03cdd63578789b075c3da7e8e8 (patch)
tree9325b2a6f1cb023c6fc244554eb0301e6c09c7b0
parent907a37e75e7011ba5cbca0300981800cb2884410 (diff)
downloadmako-b19513c8f908ae03cdd63578789b075c3da7e8e8.tar.gz
install extreme hoops for pkg_resources and I'm starting to wonder if
I really want to do it like this
-rw-r--r--mako/cache.py8
-rw-r--r--mako/util.py26
2 files changed, 25 insertions, 9 deletions
diff --git a/mako/cache.py b/mako/cache.py
index b5b7ac6..2e2b09e 100644
--- a/mako/cache.py
+++ b/mako/cache.py
@@ -11,7 +11,9 @@ def register_plugin(name, modulename, attrname):
"""Register the given :class:`.CacheImpl` under the given
name.
- This is an alternative to using a setuptools-installed entrypoint.
+ This is an alternative to using a setuptools-installed entrypoint,
+ and will work even if Mako isn't installed. ``pkg_resources`` is
+ required, however.
"""
import pkg_resources
@@ -22,7 +24,9 @@ def register_plugin(name, modulename, attrname):
else:
cache_map = entry_map['mako.cache']
cache_map[name] = \
- pkg_resources.EntryPoint.parse('%s = %s:%s' % (name, modulename, attrname), dist=dist)
+ pkg_resources.EntryPoint.parse(
+ '%s = %s:%s' %
+ (name, modulename, attrname), dist=dist)
try:
register_plugin("beaker", "mako.ext.beaker_cache", "BeakerCacheImpl")
diff --git a/mako/util.py b/mako/util.py
index 6bc100b..31fcf70 100644
--- a/mako/util.py
+++ b/mako/util.py
@@ -68,22 +68,34 @@ else:
def get_pkg_resources_distribution():
"""Return a pkg_resources.Distribution for Mako.
- Pulls all kinds of strings to ensure one is
- available even if Mako is not installed.
+ Creates a fake distribution if Mako is not installed,
+ so that tests/apps/etc. can use register_plugin.
"""
import pkg_resources
try:
- dist = pkg_resources.get_distribution("mako")
+ # would like to make this >= 0.5.1, but
+ # pkg_resources won't install us if another
+ # mako already present as no, no, you're now
+ # a "hidden distro" (not documented,
+ # just in their source code, no warning/exception,
+ # sure seems like silent failure to me...)
+ return pkg_resources.get_distribution("Mako")
except:
+ # make a "fake" Distribution, which we very much
+ # hope makes it so something global is returned
+ # when we say get_distribution() so we can hang
+ # our plugins in the same way as when we're
+ # installed.
import mako
dist = pkg_resources.Distribution(
- project_name="mako", location="mako", version=mako.__version__
+ pkg_resources.normalize_path(
+ os.path.dirname(os.path.dirname(mako.__file__))),
+ project_name="Mako",
+ version=mako.__version__,
)
- dist.activate()
pkg_resources.working_set.add(dist)
- dist = pkg_resources.get_distribution("mako")
- return dist
+ return pkg_resources.get_distribution("Mako")
def verify_directory(dir):
"""create and/or verify a filesystem directory."""