Skip to content

Commit

Permalink
Merge pull request #3 from drocco007/feature/contingent
Browse files Browse the repository at this point in the history
Use Builder to manage build process for the blog example
  • Loading branch information
brandon-rhodes committed Aug 26, 2014
2 parents 6f176cf + 9fd2054 commit d50498f
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions contingent/example1/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@

import os
import re
import sys
from IPython.nbconvert import HTMLExporter
from IPython.nbformat import current as nbformat
from docutils.core import publish_doctree, publish_parts
from docutils import nodes
from glob import glob
from jinja2 import DictLoader

# Hmm. No distribution is in play here (so can't ``from contingent import …``)
# and relative imports don't work because the parent package hasn't been
# imported…
sys.path.insert(0, '..')
from builderlib import Builder

dl = DictLoader({'full.tpl': """\
{%- extends 'display_priority.tpl' -%}
{% block input scoped %}<pre>{{ cell.input }}</pre>
Expand Down Expand Up @@ -83,14 +90,28 @@ def main():
if not os.path.exists(outdir):
os.mkdir(outdir)

def call(f, *args):
def compute(target, get):
"Compute a dependency by direct invocation of the target function."
f, args = target
# The functions above expect a provider callable with a parameter
# signature of (fn, *args). Builder.get accepts a single target tuple;
# ``call`` (defined below) mediates between the two by packaging its
# arguments into a target tuple as required by Builder.
return f(call, *args)

builder = Builder(compute)

def call(f, *args):
"Compute a target using a Builder."
target = f, args
return builder.get(target)

paths = (glob(os.path.join(indir, '*.rst')) +
glob(os.path.join(indir, '*.ipynb')))
paths = tuple(paths)
for path in call(sorted_posts, paths):
print '-' * 72
print call(render, paths, path)
print('-' * 72)
print(call(render, paths, path))

if __name__ == '__main__':
main()

0 comments on commit d50498f

Please sign in to comment.