diff --git a/mako/cache.py b/mako/cache.py index b5b7ac627394e668e428be47fe2b9f11d32724cd..2e2b09e4d9bef2a1f4fc7e566ddf7502415640dc 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 6bc100b4f806129bf50301d7d9b56fdb5c0c2683..31fcf70e6df3fa275116fda069a062f6f09d87d1 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."""