def serve(host='0.0.0.0', port=8000, root=_('')): server = Server() server.setHeader('Access-Control-Allow-Origin', '*') server.setHeader('Access-Control-Allow-Methods', '*') server.watch('data', generate) server.watch('static', generate) server.watch('src', generate) generate() server.serve(host=host, port=port, root=root)
def build_or_autobuild(cmd_name, port=None, sphinx_build=False, sphinx_autobuild=False): path = project_path() if not path: raise click.ClickException( f"You must be in a Runestone project to execute {cmd_name} command") os.chdir(path) sys.path.insert(0, str(path)) from pavement import options as paver_options # pylint: disable=import-error buildPath = Path(paver_options.build.builddir) if not buildPath.exists: os.makedirs(buildPath) args = [] if sphinx_autobuild: srcdir = os.path.realpath(paver_options.build.sourcedir) outdir = os.path.realpath(paver_options.build.builddir) if not os.path.exists(outdir): os.makedirs(outdir) server = Server() builder = get_builder( server.watcher, ['-b', 'html', '-d', './_build/doctrees', '-c', '.', srcdir, outdir], pre_build_commands=[] ) server.watch(srcdir, builder, ignore=[]) server.setHeader('Access-Control-Allow-Origin', '*') server.setHeader('Access-Control-Allow-Methods', '*') server.serve(port=port, host="127.0.0.1", root=outdir, open_url_delay=5) if sphinx_build: build_module = "sphinx.cmd.build" args.append('-a') args.append('-E') args.append('-b html') args.append(f'-c "{paver_options.build.confdir}"') args.append(f'-d "{paver_options.build.builddir}/doctrees"') for k, v in paver_options.build.template_args.items(): args.append(f'-A "{k}={v}"') args.append(f'"{paver_options.build.sourcedir}"') args.append(f'"{paver_options.build.builddir}"') sh(f'"{sys.executable}" -m {build_module} ' + " ".join(args))
from livereload import Server, shell print("Only use in dev") server = Server() server.watch('./') server.setHeader('Access-Control-Allow-Origin', '*') server.serve(root='./')