aboutsummaryrefslogtreecommitdiffstats
path: root/mako/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'mako/util.py')
-rw-r--r--mako/util.py26
1 files changed, 19 insertions, 7 deletions
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."""