def build_cmd(ctx, output_path, watch, prune, verbosity): """Builds the entire site out.""" from lektor.builder import Builder from lektor.reporter import CliReporter if output_path is None: output_path = ctx.get_default_output_path() env = ctx.get_env() def _build(): builder = Builder(ctx.new_pad(), output_path) builder.build_all() if prune: builder.prune() reporter = CliReporter(env, verbosity=verbosity) with reporter: _build() if not watch: return from lektor.watcher import watch click.secho('Watching for file system changes', fg='cyan') last_build = time.time() for ts, _, _ in watch(env): if ts > last_build: _build() last_build = time.time()
def build_cmd(ctx, output_path, watch, prune, verbosity, source_info_only, buildstate_path, profile, build_flags): """Builds the entire project into the final artifacts. The default behavior is to build the project into the default build output path which can be discovered with the `project-info` command but an alternative output folder can be provided with the `--output-path` option. The default behavior is to perform a build followed by a pruning step which removes no longer referenced artifacts from the output folder. Lektor will only build the files that require rebuilding if the output folder is reused. To enforce a clean build you have to issue a `clean` command first. If the build fails the exit code will be `1` otherwise `0`. This can be used by external scripts to only deploy on successful build for instance. """ from lektor.builder import Builder from lektor.reporter import CliReporter if output_path is None: output_path = ctx.get_default_output_path() ctx.load_plugins() env = ctx.get_env() def _build(): builder = Builder(env.new_pad(), output_path, buildstate_path=buildstate_path, build_flags=build_flags) if source_info_only: builder.update_all_source_infos() return True if profile: from .utils import profile_func failures = profile_func(builder.build_all) else: failures = builder.build_all() if prune: builder.prune() return failures == 0 reporter = CliReporter(env, verbosity=verbosity) with reporter: success = _build() if not watch: return sys.exit(0 if success else 1) from lektor.watcher import watch click.secho('Watching for file system changes', fg='cyan') last_build = time.time() for ts, _, _ in watch(env): if ts > last_build: _build() last_build = time.time()
def test_watch(env, mocker): Watcher = mocker.patch("lektor.watcher.Watcher") event1 = mocker.sentinel.event1 def events(): yield event1 raise KeyboardInterrupt() watcher = Watcher.return_value.__enter__.return_value watcher.__iter__.return_value = events() assert list(watch(env)) == [event1]
def build_cmd(ctx, output_path, watch, prune, verbosity, source_info_only, buildstate_path, profile, extra_flags, build_flags): """Builds the entire project into the final artifacts. The default behavior is to build the project into the default build output path which can be discovered with the `project-info` command but an alternative output folder can be provided with the `--output-path` option. The default behavior is to perform a build followed by a pruning step which removes no longer referenced artifacts from the output folder. Lektor will only build the files that require rebuilding if the output folder is reused. To enforce a clean build you have to issue a `clean` command first. If the build fails the exit code will be `1` otherwise `0`. This can be used by external scripts to only deploy on successful build for instance. """ from lektor.builder import Builder from lektor.reporter import CliReporter extra_flags = tuple(itertools.chain(extra_flags or (), build_flags or ())) if output_path is None: output_path = ctx.get_default_output_path() ctx.load_plugins() env = ctx.get_env() def _build(): builder = Builder(env.new_pad(), output_path, buildstate_path=buildstate_path, extra_flags=extra_flags) if source_info_only: builder.update_all_source_infos() return True if profile: from .utils import profile_func failures = profile_func(builder.build_all) else: failures = builder.build_all() if prune: builder.prune() return failures == 0 reporter = CliReporter(env, verbosity=verbosity) with reporter: success = _build() if not watch: return sys.exit(0 if success else 1) from lektor.watcher import watch click.secho('Watching for file system changes', fg='cyan') last_build = time.time() for ts, _, _ in watch(env): if ts > last_build: _build() last_build = time.time()