Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_unicode_builder(tmpdir):
from lektor.project import Project
from lektor.environment import Environment
from lektor.db import Database
from lektor.builder import Builder
proj = Project.from_path(os.path.join(os.path.dirname(__file__),
u'ünicöde-project'))
env = Environment(proj)
pad = Database(env).new_pad()
return pad, Builder(pad, str(tmpdir.mkdir('output')))
# 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']
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']
If not build folder is provided, the default build folder of the project
in the Lektor cache is used.
"""
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(extra_flags=extra_flags)
env = ctx.get_env()
reporter = CliReporter(env, verbosity=verbosity)
with reporter:
builder = Builder(env.new_pad(), output_path)
builder.prune(all=True)
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
def build(self, update_source_info_first=False):
try:
db = Database(self.env)
builder = Builder(db.new_pad(), self.output_path,
extra_flags=self.extra_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 get_builder(self, pad=None):
if pad is None:
pad = self.get_pad()
return Builder(pad, self.output_path, extra_flags=self.extra_flags)
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
def get_builder(self, pad=None):
if pad is None:
pad = self.get_pad()
return Builder(pad, self.output_path, build_flags=self.build_flags)