Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
def theme_project(theme_project_tmpdir, request):
    """Return the theme project created in a temp dir.

    Could be parametrize, if request.param=False themes variables won't be set
    """
    try:
        with_themes_var = request.param
    except AttributeError:
        with_themes_var = True

    # Create the .lektorproject file
    lektorfile_text = textwrap.dedent(
        """
        [project]
        name = Themes Project
        {}
    """.format(
            "themes = blog_theme, project_theme" if with_themes_var else ""
        )
    )

    theme_project_tmpdir.join("themes.lektorproject").write_text(
        lektorfile_text, "utf8", ensure=True
    )
    return Project.from_path(str(theme_project_tmpdir))
Ejemplo n.º 3
0
def get_unicode_builder(tmpdir):
    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")))
Ejemplo n.º 4
0
def scratch_project_with_plugin_no_params(
    scratch_project_data, request, isolated_cli_runner
):
    """Create a scratch project and add a plugin that has the named event listener.

    Return (project, current event, and attached cli_runner).
    """
    base = scratch_project_data

    # Minimum viable setup.py
    current_test_index = (request.param_index,) * 4
    setup_text = textwrap.dedent(
        u"""
        from setuptools import setup

        setup(
            name='lektor-event-test-no-params{}',
            entry_points={{
                'lektor.plugins': [
                    'event-test-no-params{} = lektor_event_test_no_params{}:NoParams{}',
                ]
            }}
        )
    """
    ).format(*current_test_index)
    base.join(
        "packages", "event-test-no-params{}".format(request.param_index), "setup.py"
    ).write_text(setup_text, "utf8", ensure=True)

    # Minimum plugin code
    plugin_text = textwrap.dedent(
        u"""
        from lektor.pluginsystem import Plugin
        import os

        class NoParams{}(Plugin):
            name = 'Event Test'
            description = u'Non-empty string'

            def on_{}(self):
                pass
    """
    ).format(request.param_index, request.param, request.param)
    base.join(
        "packages",
        "event-test-no-params{}".format(request.param_index),
        "lektor_event_test_no_params{}.py".format(request.param_index),
    ).write_text(plugin_text, "utf8", ensure=True)

    # Move into isolated path.
    for entry in os.listdir(str(base)):
        entry_path = os.path.join(str(base), entry)
        if os.path.isdir(entry_path):
            shutil.copytree(entry_path, entry)
        else:
            shutil.copy2(entry_path, entry)

    from lektor.project import Project

    yield (Project.from_path(str(base)), request.param, isolated_cli_runner)
Ejemplo n.º 5
0
def child_sources_test_project_builder(tmpdir):
    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), "child-sources-test-project"))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 6
0
def child_sources_test_project_builder(request):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project

    project = Project.from_path(os.path.join(os.path.dirname(__file__), "child-sources-test-project"))
    env = Environment(project)
    pad = Database(env).new_pad()

    return make_builder(request, pad)
Ejemplo n.º 7
0
def child_sources_test_project_builder(request):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project

    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), 'child-sources-test-project'))
    env = Environment(project)
    pad = Database(env).new_pad()

    return make_builder(request, pad)
Ejemplo n.º 8
0
def child_sources_test_project_builder(tmpdir):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project
    from lektor.builder import Builder

    project = Project.from_path(os.path.join(os.path.dirname(__file__),
                                             'child-sources-test-project'))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 9
0
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')))
Ejemplo n.º 10
0
def child_sources_test_project_builder(tmpdir):
    from lektor.db import Database
    from lektor.environment import Environment
    from lektor.project import Project
    from lektor.builder import Builder

    project = Project.from_path(
        os.path.join(os.path.dirname(__file__), 'child-sources-test-project'))
    env = Environment(project)
    pad = Database(env).new_pad()

    return Builder(pad, str(tmpdir.mkdir("output")))
Ejemplo n.º 11
0
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')))
Ejemplo n.º 12
0
def scratch_project(request):
    base = tempfile.mkdtemp()
    with open(os.path.join(base, 'Scratch.lektorproject'), 'w') as f:
        f.write(
            '[project]\n'
            'name = Scratch\n\n'
            '[alternatives.en]\n'
            'primary = yes\n'
            '[alternatives.de]\n'
            'url_prefix = /de/\n'
            '[servers.production]\n'
            'enabled = yes\n'
            'name = Production\n'
            'target = rsync://example.com/path/to/website\n'
            'name[de] = Produktion\n'
            'extra_field = extra_value\n'
        )

    os.mkdir(os.path.join(base, 'content'))
    with open(os.path.join(base, 'content', 'contents.lr'), 'w') as f:
        f.write(
            '_model: page\n'
            '---\n'
            'title: Index\n'
            '---\n'
            'body: Hello World!\n'
        )
    os.mkdir(os.path.join(base, 'templates'))
    with open(os.path.join(base, 'templates', 'page.html'), 'w') as f:
        f.write('<h1>{{ this.title }}</h1>\n{{ this.body }}\n')
    os.mkdir(os.path.join(base, 'models'))
    with open(os.path.join(base, 'models', 'page.ini'), 'w') as f:
        f.write(
            '[model]\n'
            'label = {{ this.title }}\n\n'
            '[fields.title]\n'
            'type = string\n'
            '[fields.body]\n'
            'type = markdown\n'
        )

    def cleanup():
        try:
            shutil.rmtree(base)
        except (OSError, IOError):
            pass
    request.addfinalizer(cleanup)

    from lektor.project import Project
    return Project.from_path(base)
Ejemplo n.º 13
0
def scratch_project(tmpdir):
    base = tmpdir.mkdir("scratch-proj")
    lektorfile_text = textwrap.dedent(u"""
        [project]
        name = Scratch

        [alternatives.en]
        primary = yes
        [alternatives.de]
        url_prefix = /de/
    """)
    base.join("Scratch.lektorproject").write_text(lektorfile_text,
                                                  "utf8",
                                                  ensure=True)
    content_text = textwrap.dedent(u"""
        _model: page
        ---
        title: Index
        ---
        body: Hello World!
    """)
    base.join("content", "contents.lr").write_text(content_text,
                                                   "utf8",
                                                   ensure=True)
    template_text = textwrap.dedent(u"""
        <h1>{{ this.title }}</h1>
        {{ this.body }}
    """)
    base.join("templates", "page.html").write_text(template_text,
                                                   "utf8",
                                                   ensure=True)
    model_text = textwrap.dedent(u"""
        [model]
        label = {{ this.title }}

        [fields.title]
        type = string
        [fields.body]
        type = markdown
    """)
    base.join("models", "page.ini").write_text(model_text, "utf8", ensure=True)

    from lektor.project import Project
    return Project.from_path(str(base))
Ejemplo n.º 14
0
 def get_project(self, silent=False):
     if self._project is not None:
         return self._project
     if self._project_path is not None:
         rv = Project.from_path(self._project_path)
     else:
         rv = Project.discover()
     if rv is None:
         if silent:
             return None
         if self._project_path is None:
             raise click.UsageError("Could not automatically discover "
                                    "project.  A Lektor project must "
                                    "exist in the working directory or "
                                    "any of the parent directories.")
         raise click.UsageError('Could not find project "%s"' %
                                self._project_path)
     self._project = rv
     return rv
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
def no_alt_pad(tmp_path_factory):
    no_alt_project = tmp_path_factory.mktemp("no-alts") / "demo-project"
    demo_project = Path(__file__).parent / "demo-project"
    shutil.copytree(demo_project, no_alt_project)

    project_file = no_alt_project / "Website.lektorproject"
    alt_section_re = r"(?ms)^\[alternatives\.\w+\].*?(?=^\[)"
    project_file.write_text(
        re.sub(alt_section_re, "", project_file.read_text()))

    dirs = [no_alt_project]
    while dirs:
        for child in dirs.pop().iterdir():
            if child.is_dir():
                dirs.append(child)
            elif child.match("contents+*.lr"):
                child.unlink()

    project = Project.from_path(no_alt_project)
    return project.make_env().new_pad()
Ejemplo n.º 17
0
def scratch_project(request):
    base = tempfile.mkdtemp()
    with open(os.path.join(base, "Scratch.lektorproject"), "w") as f:
        f.write(
            "[project]\n"
            "name = Scratch\n\n"
            "[alternatives.en]\n"
            "primary = yes\n"
            "[alternatives.de]\n"
            "url_prefix = /de/\n"
        )

    os.mkdir(os.path.join(base, "content"))
    with open(os.path.join(base, "content", "contents.lr"), "w") as f:
        f.write("_model: page\n" "---\n" "title: Index\n" "---\n" "body: Hello World!\n")
    os.mkdir(os.path.join(base, "templates"))
    with open(os.path.join(base, "templates", "page.html"), "w") as f:
        f.write("<h1>{{ this.title }}</h1>\n{{ this.body }}\n")
    os.mkdir(os.path.join(base, "models"))
    with open(os.path.join(base, "models", "page.ini"), "w") as f:
        f.write(
            "[model]\n"
            "label = {{ this.title }}\n\n"
            "[fields.title]\n"
            "type = string\n"
            "[fields.body]\n"
            "type = markdown\n"
        )

    def cleanup():
        try:
            shutil.rmtree(base)
        except (OSError, IOError):
            pass

    request.addfinalizer(cleanup)

    from lektor.project import Project

    return Project.from_path(base)
Ejemplo n.º 18
0
def scratch_project(tmpdir):
    base = tmpdir.mkdir("scratch-proj")
    lektorfile_text = textwrap.dedent(u"""
        [project]
        name = Scratch

        [alternatives.en]
        primary = yes
        [alternatives.de]
        url_prefix = /de/
    """)
    base.join("Scratch.lektorproject").write_text(lektorfile_text, "utf8", ensure=True)
    content_text = textwrap.dedent(u"""
        _model: page
        ---
        title: Index
        ---
        body: Hello World!
    """)
    base.join("content", "contents.lr").write_text(content_text, "utf8", ensure=True)
    template_text = textwrap.dedent(u"""
        <h1>{{ this.title }}</h1>
        {{ this.body }}
    """)
    base.join("templates", "page.html").write_text(template_text, "utf8", ensure=True)
    model_text = textwrap.dedent(u"""
        [model]
        label = {{ this.title }}

        [fields.title]
        type = string
        [fields.body]
        type = markdown
    """)
    base.join("models", "page.ini").write_text(model_text, "utf8", ensure=True)

    from lektor.project import Project
    return Project.from_path(str(base))
Ejemplo n.º 19
0
def theme_project(theme_project_tmpdir, request):
    """Return the theme project created in a temp dir.

    Could be parametrize, if request.param=False themes variables won't be set
    """
    try:
        with_themes_var = request.param
    except AttributeError:
        with_themes_var = True

    from lektor.project import Project

    # Create the .lektorproject file
    lektorfile_text = textwrap.dedent(u"""
        [project]
        name = Themes Project
        {}
    """.format("themes = blog_theme, project_theme"
               if with_themes_var else ""))

    theme_project_tmpdir.join("themes.lektorproject").write_text(
        lektorfile_text, "utf8", ensure=True)
    return Project.from_path(str(theme_project_tmpdir))
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
Ejemplo n.º 21
0
def project():
    from lektor.project import Project
    return Project.from_path(
        os.path.join(os.path.dirname(__file__), 'demo-project'))
Ejemplo n.º 22
0
def project(expected):
    return Project.from_path(str(expected.project_path))
Ejemplo n.º 23
0
def pntest_project(tmp_path):
    src = Path(__file__).parent / "dependency-test-project"
    tmp_project = tmp_path / "project"
    shutil.copytree(src, tmp_project)
    return Project.from_path(tmp_project)
Ejemplo n.º 24
0
def project():
    from lektor.project import Project
    return Project.from_path(os.path.join(os.path.dirname(__file__),
                                          'demo-project'))
Ejemplo n.º 25
0
def project(lektorproject):
    #if lektorproject['branch'] != 'lektor-admin-extra':
    #    pytest.skip('already tested')
    from lektor.project import Project
    return Project.from_path(lektorproject['path'])
Ejemplo n.º 26
0
def project():
    return Project.from_path(os.path.join(os.path.dirname(__file__), "demo-project"))
Ejemplo n.º 27
0
def pntest_project(request):
    from lektor.project import Project

    return Project.from_path(
        os.path.join(os.path.dirname(__file__), "dependency-test-project"))
Ejemplo n.º 28
0
def scratch_project(scratch_project_data):
    from lektor.project import Project

    base = scratch_project_data
    return Project.from_path(str(base))
Ejemplo n.º 29
0
def scratch_project(scratch_project_data):
    base = scratch_project_data
    return Project.from_path(str(base))
Ejemplo n.º 30
0
def lektor_env():
    site_path = os.path.join(os.path.dirname(__file__), 'test-site')
    return Project.from_path(site_path).make_env(load_plugins=False)
Ejemplo n.º 31
0
def project(request):
    from lektor.project import Project

    return Project.from_path(
        os.path.join(os.path.dirname(__file__), "demo-project"))
Ejemplo n.º 32
0
def project(request, project_path):
    from lektor.project import Project
    prj = Project.from_path(project_path.strpath)
    assert prj is not None
    return prj
Ejemplo n.º 33
0
def pntest_project(request):
    from lektor.project import Project
    return Project.from_path(os.path.join(os.path.dirname(__file__),
                                          'dependency-test-project'))
def project():
    project = Project.from_path(str(ROOT / "example-project"))
    assert project
    return project
Ejemplo n.º 35
-1
def project(request):
    from lektor.project import Project

    return Project.from_path(os.path.join(os.path.dirname(__file__), "demo-project"))