def build(ctx, less=False, docs=False, js=False, force=False): """Build everything and collectstatic. """ specified = any([less, docs, js]) buildall = not specified if buildall or less: less_fname = ctx.pkg.source_less / ctx.pkg.name + '.less' if less_fname.exists(): lessc.LessRule( ctx, src='{pkg.source_less}/{pkg.name}.less', dst='{pkg.django_static}/{pkg.name}/css/{pkg.name}-{version}.min.css', force=force ) elif less: warnings.warn( "WARNING: build --less specified, but no file at: " + less_fname ) if buildall or docs: if WARN_ABOUT_SETTINGS: warnings.warn( "autodoc might need a dummy settings file in the root of " "your package. Since it runs in a separate process you cannot" "use settings.configure()" ) doctools.build(ctx, force=force) if buildall or js: build_js(ctx, force) if HAVE_SETTINGS and (force or changed(ctx.pkg.django_static)): collectstatic(ctx, DJANGO_SETTINGS_MODULE, force=force)
def build(ctx, less=False, docs=False, js=False, force=False): """Build everything and collectstatic. """ specified = any([less, docs, js]) buildall = not specified if buildall or less: less_fname = ctx.pkg.source_less / ctx.pkg.name + '.less' if less_fname.exists(): lessc.LessRule( ctx, src='{pkg.source_less}/{pkg.name}.less', dst= '{pkg.django_static}/{pkg.name}/css/{pkg.name}-{version}.min.css', force=force) elif less: warnings.warn("WARNING: build --less specified, but no file at: " + less_fname) if buildall or docs: if WARN_ABOUT_SETTINGS: warnings.warn( "autodoc might need a dummy settings file in the root of " "your package. Since it runs in a separate process you cannot" "use settings.configure()") doctools.build(ctx, force=force) if buildall or js: build_js(ctx, force) if HAVE_SETTINGS and (force or changed(ctx.pkg.django_static)): collectstatic(ctx, DJANGO_SETTINGS_MODULE, force=force)
def build(ctx, clean=False, browse=False, warn=False, builder='html', force=False, opts=""): """ Build the project's Sphinx docs. """ if not force and not changed(ctx.pkg.docsdir): print """ No changes detected in {}, add --force to build docs anyway. """.format(ctx.pkg.docsdir) return # should perhaps check if code has changed too? (autodoc) if clean: _clean(ctx) make_api_docs(ctx, force=force) if opts is None: # pragma: nocover opts = "" opts += " -b %s" % builder if warn: opts += " -n -W" if force: opts += " -a -E" cmd = "sphinx-build {opts} {ctx.pkg.docsdir} {ctx.pkg.root}/build/docs".format(opts=opts, ctx=ctx) dj_settings = ctx.pkg.get('django_settings_module', "") if dj_settings: os.environ['DJANGO_SETTINGS_MODULE'] = dj_settings ctx.run(cmd) if browse: # pragma: nocover _browse(ctx)
def build(ctx, less=False, docs=False, js=False, force=False): """Build everything and collectstatic. """ specified = any([less, docs, js]) buildall = not specified if buildall or less: less_fname = ctx.pkg.source_less / ctx.pkg.name + '.less' if less_fname.exists(): lessc.LessRule( ctx, src='{pkg.source_less}/{pkg.name}.less', dst='{pkg.django_static}/{pkg.name}/css/{pkg.name}-{version}.min.css', force=force ) elif less: warnings.warn( "WARNING: build --less specified, but no file at: " + less_fname ) if buildall or docs: # output = 'svg' output = 'png' if WARN_ABOUT_SETTINGS: warnings.warn( "autodoc might need a dummy settings file in the root of " "your package. Since it runs in a separate process you cannot" "use settings.configure()" ) # input: ctx.pkg.source / 'models/legal_transitions.py' # output: ctx.pkg.docs / 'diagrams/transitions.dot' ctx.run('python {transitions2dot} {output}'.format( transitions2dot=ctx.pkg.docs / 'transitions2dot.py', output=ctx.pkg.docs / 'diagrams/transitions.dot' )) for fname in ctx.pkg.docs.glob('diagrams/*.puml'): ctx.run('java -jar %s %s -t%s -o %s' % ( PLANTUML_JAR, fname, output, ctx.pkg.docs / '_static' )) for fname in ctx.pkg.docs.glob('diagrams/*.dot'): ctx.run('dot -T%s -o %s %s' % ( output, ctx.pkg.docs / '_static' / fname.basename().switchext('.' + output), fname )) doctools.build(ctx, force=force) if buildall or js: build_js(ctx, force) if HAVE_SETTINGS and (force or changed(ctx.pkg.django_static)): collectstatic(ctx, DJANGO_SETTINGS_MODULE, force=force)
def test_multifiles(): files = """ a: - b: | hello - c: | world """ with create_files(files) as directory: assert changed.changed('a') assert not Directory('a').changed()
def collectstatic(ctx, settings=None, venv=None, clobber=False, force=False): "Run collectstatic with settings from package.json ('django_settings_module')" if not hasattr(ctx, "pkg"): ctx.pkg = Package() if not (force or ctx.pkg.staticdir.changed()): print "Skipping collectstic: no changes to static dir." return if not clobber: # check that we don't overwrite versioned resources changed_versioned_resources = False static = Path(os.environ["SRV"]) / "data" / "static" for fname in ctx.pkg.staticdir.glob("**/*\d+.min.*"): pubname = static / fname.relpath(ctx.pkg.staticdir) if pubname.exists(): # print 'checking:', pubname if pubname.open("rb").read() != fname.open("rb").read(): changed_versioned_resources = True print print "ERROR: versioned file has changes:" print " contents of: ", fname print " is different from:", pubname print if changed_versioned_resources: print "Exiting due to changes in versioned resources. " "You should probably revert the changes and create " "a new version." sys.exit(1) try: settings = settings or ctx.pkg.django_settings_module except AttributeError: settings = DEFAULT_SETTINGS_MODULE print "using settings:", settings, "venv:", venv manage(ctx, "collectstatic --noinput", settings=settings, venv=venv) # record changes made by collectstatic changed(ctx.pkg.staticdir)
def test_missing(): assert changed.changed("this-directory-doesnt-exist")
def test_changed(): files = """ emptydir: [] """ with create_files(files) as directory: assert changed.changed('emptydir')