def _build(): builder = Builder(ctx.new_pad(), output_path) if source_info_only: builder.update_all_source_infos() else: builder.build_all() if prune: builder.prune()
def build(self): try: db = Database(self.env, lang=self.lang) builder = Builder(db.new_pad(), self.output_path) builder.build_all() except Exception: traceback.print_exc() else: self.last_build = time.time()
def build(self, update_source_info_first=False): try: db = Database(self.env) builder = Builder(db.new_pad(), self.output_path) if update_source_info_first: builder.update_all_source_infos() builder.build_all() builder.prune() except Exception: traceback.print_exc() else: self.last_build = time.time()
def _build(): builder = Builder(env.new_pad(), output_path, build_flags=build_flags) if source_info_only: builder.update_all_source_infos() else: if profile: from .utils import profile_func profile_func(builder.build_all) else: builder.build_all() if prune: builder.prune()
def build(self, update_source_info_first=False): try: db = Database(self.env) builder = Builder(db.new_pad(), self.output_path, build_flags=self.build_flags) if update_source_info_first: builder.update_all_source_infos() builder.build_all() if self.prune: builder.prune() except Exception: traceback.print_exc() else: self.last_build = time.time()
def _build(): builder = Builder(env.new_pad(), str(self._dst), buildstate_path=self._buildstate, extra_flags=self._buildflags if not tiny else []) failures = builder.build_all() builder.prune() return failures == 0
def test_prev_next_dependencies(request, tmpdir, pntest_env, pntest_reporter): env, reporter = pntest_env, pntest_reporter builder = Builder(env.new_pad(), str(tmpdir.mkdir("output"))) builder.build_all() # We start with posts 1, 2, and 4. Posts 1 and 2 depend on each other, # posts 2 and 3 depend on each other, but posts 1 and 3 are independent. assert "content/post2/contents.lr" in reporter.deps["post1"] assert "content/post3/contents.lr" not in reporter.deps["post1"] assert "/post1@siblings" in reporter.deps["post1"] assert "content/post1/contents.lr" in reporter.deps["post2"] assert "content/post4/contents.lr" in reporter.deps["post2"] assert "/post2@siblings" in reporter.deps["post2"] assert "content/post1/contents.lr" not in reporter.deps["post4"] assert "content/post2/contents.lr" in reporter.deps["post4"] assert "/post4@siblings" in reporter.deps["post4"] # Create post3, check that post2 and post4's dependencies are updated. post3_dir = os.path.join(env.project.tree, "content", "post3") def cleanup(): try: shutil.rmtree(post3_dir) except (OSError, IOError): pass request.addfinalizer(cleanup) os.makedirs(post3_dir) with open(os.path.join(post3_dir, "contents.lr"), "w+", encoding="utf-8"): pass reporter.clear() builder = Builder(env.new_pad(), builder.destination_path) builder.build_all() # post2, post3, and post4 had to be rebuilt, but not post1. assert set(["post2", "post3", "post4"]) == set(reporter.artifact_ids) # post2 depends on post3 now, not post4. assert "content/post3/contents.lr" in reporter.deps["post2"] assert "content/post4/contents.lr" not in reporter.deps["post2"] # post4 depends on post3 now, not post2. assert "content/post3/contents.lr" in reporter.deps["post4"] assert "content/post2/contents.lr" not in reporter.deps["post4"]
def test_prev_next_dependencies(request, pntest_env, pntest_reporter): env, reporter = pntest_env, pntest_reporter builder = make_builder(request, env.new_pad()) builder.build_all() # We start with posts 1, 2, and 4. Posts 1 and 2 depend on each other, # posts 2 and 3 depend on each other, but posts 1 and 3 are independent. assert 'content/post2/contents.lr' in reporter.deps['post1'] assert 'content/post3/contents.lr' not in reporter.deps['post1'] assert '/post1@siblings' in reporter.deps['post1'] assert 'content/post1/contents.lr' in reporter.deps['post2'] assert 'content/post4/contents.lr' in reporter.deps['post2'] assert '/post2@siblings' in reporter.deps['post2'] assert 'content/post1/contents.lr' not in reporter.deps['post4'] assert 'content/post2/contents.lr' in reporter.deps['post4'] assert '/post4@siblings' in reporter.deps['post4'] # Create post3, check that post2 and post4's dependencies are updated. post3_dir = os.path.join(env.project.tree, 'content', 'post3') def cleanup(): try: shutil.rmtree(post3_dir) except (OSError, IOError): pass request.addfinalizer(cleanup) os.makedirs(post3_dir) open(os.path.join(post3_dir, 'contents.lr'), 'w+').close() reporter.clear() builder = Builder(env.new_pad(), builder.destination_path) builder.build_all() # post2, post3, and post4 had to be rebuilt, but not post1. assert set(['post2', 'post3', 'post4']) == set(reporter.artifact_ids) # post2 depends on post3 now, not post4. assert 'content/post3/contents.lr' in reporter.deps['post2'] assert 'content/post4/contents.lr' not in reporter.deps['post2'] # post4 depends on post3 now, not post2. assert 'content/post3/contents.lr' in reporter.deps['post4'] assert 'content/post2/contents.lr' not in reporter.deps['post4']
class TestLektorPythonMarkdown(unittest.TestCase): def setUp(self): self.project = Project.from_path( os.path.join(os.path.dirname(__file__), 'demo-project')) self.env = Environment(self.project) self.pad = Database(self.env).new_pad() self.out = tempfile.mkdtemp() self.builder = Builder(self.pad, self.out) def tearDown(self): try: shutil.rmtree(self.out) except (OSError, IOError): pass def test_basic(self): failures = self.builder.build_all() assert not failures page_path = os.path.join(self.builder.destination_path, 'fr/index.html') html = open(page_path).read() print(html) assert '<h1 id="header-1">Header 1</h1>' in html assert '<h2 class="customclass" id="header-2">Header 2</h2>' in html # The output changes depending on the version of python-markdown uses. # assert '<pre class="codehilite"><code class="linenums">code here</code></pre>' in html # Check url & image substitution assert '<a href="/fr/sub-page/">Link to Sub Page</a>' in html assert '<a href="/fr/slug-url/">Link to Slug</a>' in html assert '<a href="/invalid-page">Link to Invalid Page</a>' in html assert '<img alt="alttxt" src="/fr/logo.png" />' in html # Check references assert '<a href="/fr/sub-page/" title="Sub Page">Sub Page</a>' in html assert '<a href="http://search.yahoo.com/" title="Yahoo Search">Yahoo</a>' in html def test_basic_alt_en(self): failures = self.builder.build_all() assert not failures page_path = os.path.join(self.builder.destination_path, 'en/index.html') html = open(page_path).read() print(html) assert '<img alt="alttxt" src="/fr/logo.png" />' in html
def _build(): builder = Builder(env.new_pad(), output_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
def build(ctx): lektor_cli_ctx = Context() lektor_cli_ctx.load_plugins() env = lektor_cli_ctx.get_env() pad = env.new_pad() # This is essentially `lektor build --output-path build`. with CliReporter(env, verbosity=0): builder = Builder(pad, OUTPUT_DIR) failures = builder.build_all() if failures: raise invoke.Exit('Builder failed.')
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
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: failures = profile_func(builder.build_all) else: failures = builder.build_all() if prune: builder.prune() return failures == 0
def build(ctx, bust=False): lektor_cli_ctx = Context() if bust: project = lektor_cli_ctx.get_project() shutil.rmtree(project.get_package_cache_path(), ignore_errors=True) shutil.rmtree(project.get_output_path(), ignore_errors=True) lektor_cli_ctx.load_plugins() env = lektor_cli_ctx.get_env() pad = env.new_pad() # This is essentially `lektor build --output-path build`. with CliReporter(env, verbosity=0): builder = Builder(pad, OUTPUT_DIR) failures = builder.build_all() if failures: raise invoke.Exit('Builder failed.') # Generate redirect file. redirect_filename = os.path.join(OUTPUT_DIR, '_redirects') with io.open(redirect_filename, mode='w', encoding='utf8') as f: static_redirect = get_static_redirect() f.write(static_redirect) if not static_redirect.endswith('\n'): f.write('\n') f.write('\n') f.write('# Blog posts.\n') f.write('\n'.join(generate_blog_post_redirects(pad))) f.write('\n') f.write('\n') f.write('# Download redirects.\n') f.write('\n'.join(generate_download_redirects(pad))) f.write('\n') latest_redirect = get_latest_download_redirect(pad) if latest_redirect is not None: f.write('\n') f.write('# Latests version download links.\n') f.write(latest_redirect) f.write('\n')
def demo_output(site_path, my_plugin_id, my_plugin_cls, tmp_path_factory): """ Build the demo site. Return path to output directory. """ project = Project.from_path(str(site_path)) env = Environment(project, load_plugins=False) # Load our plugin env.plugin_controller.instanciate_plugin(my_plugin_id, my_plugin_cls) env.plugin_controller.emit('setup-env') pad = Database(env).new_pad() output_path = tmp_path_factory.mktemp('demo-site') builder = Builder(pad, str(output_path)) with CliReporter(env): failures = builder.build_all() assert failures == 0 return output_path
def demo_output(tmp_path_factory): """ Build the demo site. Return path to output director. """ site_dir = os.path.join(os.path.dirname(__file__), 'test-site') project = Project.from_path(site_dir) env = project.make_env(load_plugins=False) # Load our plugin env.plugin_controller.instanciate_plugin('polymorphic-type', PolymorphicTypePlugin) env.plugin_controller.emit('setup-env') output_path = tmp_path_factory.mktemp('output') builder = Builder(env.new_pad(), str(output_path)) with CliReporter(env): failures = builder.build_all() assert failures == 0 return output_path
def _build(): builder = Builder(ctx.new_pad(), output_path) builder.build_all() if prune: builder.prune()