import os

from invoke import ctask as task, Collection


@task(aliases=['c'])
def _clean(ctx):
    ctx.run("rm -rf {0}".format(ctx['sphinx.target']))


@task(aliases=['b'])
def _browse(ctx):
    index = os.path.join(ctx['sphinx.target'], 'index.html')
    ctx.run("open {0}".format(index))


@task(default=True)
def build(ctx, clean=False, browse=False):
    if clean:
        _clean(ctx)
    cmd = "sphinx-build {0} {1}".format(
        ctx['sphinx.source'], ctx['sphinx.target']
    )
    ctx.run(cmd, pty=True)
    if browse:
        _browse(ctx)

ns = Collection(clean=_clean, browse=_browse, build=build)
ns.configure({
    'sphinx.source': 'docs',
    # TODO: allow lazy eval so one attr can refer to another?
    'sphinx.target': os.path.join('docs', '_build'),
})

@@ -55,27 +55,87 @@
 n%0A%0A%0A
-@task(aliases=%5B'c'%5D
+# Underscored func name to avoid shadowing kwargs in build()%0A@task(name='clean'
 )%0Ade
@@ -210,27 +210,35 @@
 )%0A%0A%0A
-@task(aliases=%5B'b'%5D
+# Ditto%0A@task(name='browse'
 )%0Ade
@@ -633,22 +633,16 @@
 ion(
-clean=
 _clean, 
 brow
@@ -637,23 +637,16 @@
 _clean, 
-browse=
 _browse,
@@ -650,14 +650,8 @@
 se, 
-build=
 buil

Tweak docs module naming/organization: