def copy_to_version(ctx, source, outputdir=None, kind="pkg", force=False): """Copy source with version number to `outputdir`. The version type is specified by the ``kind`` parameter and can be either "pkg" (package version), "svn" (current subversion revision number), or "hash" (the md5 hash of the file's contents). Returns: (str) output file name """ # where to place the versioned file.. # print "LOCALS:", locals() source = Path(source) outputdir = Path(outputdir) if outputdir else source.dirname() outputdir.makedirs() dst_fname = source.basename() if '{version}' not in str(dst_fname): dst_fname = versioned_name(dst_fname) dst = outputdir / dst_fname.format(version=get_version(ctx, source, kind)) if force or not os.path.exists(dst): copy(ctx, source, dst, force=force) elif open(source).read() != open(dst).read(): print """ Filename already exists, add --force or call upversion: {} """.format(dst) return dst
def test_copy(ctx): files = """ foo.txt: hello world """ with create_files(files) as directory: ctx = ctx.init() copy(ctx, 'foo.txt', 'foo.txt') copy(ctx, 'foo.txt', 'bar.txt') assert open('bar.txt').read() == 'hello world'
def make_api_docs(ctx, force=False): """Run sphinx-apidoc to write autodoc documentation to `docs/api/*` """ ctx.run("rm -rf {pkg.docsdir}/api".format(pkg=ctx.pkg)) ctx.run("sphinx-apidoc -o {pkg.docsdir}/api {pkg.sourcedir}".format(pkg=ctx.pkg)) concat.copy(ctx, ctx.pkg.docsdir/'api'/'*', ctx.pkg.docsdir) ctx.run("rm -rf {pkg.docsdir}/api".format(pkg=ctx.pkg)) if ".. include:: modules.rst" not in open(ctx.pkg.docsdir / 'index.rst').read(): print textwrap.dedent("""\ WARNING: you need to include the following in docs/index.rst .. include:: modules.rst """)