Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Commit

Permalink
Optional dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
shazow committed Oct 25, 2011
1 parent 87c6f94 commit dd12c6c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
@@ -1 +1 @@
include README.rst CHANGES.rst LICENSE.txt
include README.rst CHANGES.rst LICENSE.txt optional.txt
26 changes: 24 additions & 2 deletions composer/filters.py
Expand Up @@ -6,6 +6,21 @@

import os

try:
import markdown2
except ImportError:
markdown2 = False

try:
import mako.lookup
import mako.template
except ImportError:
mako = False


__all__ = ['Filter', 'Markdown', 'Mako', 'MakoContainer']


class Filter(object):
def __init__(self, index):
self.index = index
Expand All @@ -23,9 +38,10 @@ def __call__(self, content, route=None):

class Markdown(Filter):
def __init__(self, index, **markdown_kw):
super(Markdown, self).__init__(index)
if not markdown2:
raise ImportError("Markdown filter requires the 'markdown2' package to be installed.")

import markdown2
super(Markdown, self).__init__(index)
self.markdowner = markdown2.Markdown(**markdown_kw).convert

def __call__(self, content, route=None):
Expand All @@ -34,6 +50,9 @@ def __call__(self, content, route=None):

class Mako(Filter):
def __init__(self, index, **template_kw):
if not mako:
raise ImportError("Mako filter requires the 'Mako' package to be installed.")

super(Mako, self).__init__(index)

from mako.lookup import TemplateLookup
Expand All @@ -58,6 +77,9 @@ class MakoContainer(Mako):
pipes the ``content`` into the ``body`` context variable.
"""
def __init__(self, index, template, **lookup_kw):
if not mako:
raise ImportError("MakoContainer filter requires the 'Mako' package to be installed.")

super(MakoContainer, self).__init__(index, **lookup_kw)

template = os.path.relpath(self.index.absolute_path(template), '.')
Expand Down
9 changes: 9 additions & 0 deletions optional.txt
@@ -0,0 +1,9 @@
# Composer includes optional filters which have the following dependencies:
#
# Dependency: Filters:

markdown2 # composer.filters.Markdown
Mako # composer.filters.Mako, composer.filters.MakoContainer

# You'll need to install the dependencies manually if you plan on using these
# filters, else an ImportError exception will be raised during instantiation.
14 changes: 14 additions & 0 deletions setup.py
Expand Up @@ -47,3 +47,17 @@
composer = composer.command:main
"""
)


print """
---
%s
---
You can install all the optional dependencies with: ::
pip install -r optional.txt
""" % open('optional.txt').read().strip()

0 comments on commit dd12c6c

Please sign in to comment.