Ejemplo n.º 1
0
    def set_up(self):
        """Set up your applications and the test environment."""
        self.path.state = self.path.gen.joinpath("state")
        if self.path.state.exists():
            self.path.state.rmtree(ignore_errors=True)
        self.path.state.mkdir()

        self.path.profile = self.path.gen.joinpath("profile")
        dirtemplate.DirTemplate(
            "webapp", self.path.key / "htmltemplate", self.path.state
        ).with_vars(javascript=self.given.get("javascript", "")).with_files(
            base_html={
                filename: {
                    "content": content
                }
                for filename, content in self.given.get("website", {}).items()
            }).ensure_built()

        self.path.state.joinpath("selectors.yml").write_text(
            self.given["selectors.yml"])

        self.server = (python("-m", "http.server").in_dir(self.path.state /
                                                          "webapp").pexpect())
        self.server.expect("Serving HTTP on 0.0.0.0")

        if not self.path.profile.exists():
            self.path.profile.mkdir()

        self.python = project_build(self.path, self.given["python version"],
                                    self.given["selenium version"]).bin.python

        self.example_py_code = (ExamplePythonCode(
            self.python,
            self.path.state).with_setup_code(self.given.get(
                "setup", "")).with_terminal_size(160, 100).with_long_strings())
Ejemplo n.º 2
0
def docgen():
    """
    Build documentation.
    """
    def title(dirfile):
        assert len(dirfile.text().split(
            "---")) >= 3, "{} doesn't have ---".format(dirfile)
        return load(dirfile.text().split("---")[1]).data.get("title", "misc")

    docfolder = DIR.gen / "docs"

    if docfolder.exists():
        docfolder.rmtree(ignore_errors=True)
    docfolder.mkdir()

    template = dirtemplate.DirTemplate(
        "docs",
        DIR.project / "docs",
        DIR.gen,
    ).with_files(story_md={
        "using/alpha/{0}.md".format(story.info['docs']): {
            "story": story
        }
        for story in _storybook({}).ordered_by_name()
        if story.info.get("docs") is not None
    }, ).with_vars(
        readme=False,
        quickstart=_storybook({}).in_filename(
            DIR.key / "quickstart.story").non_variations().ordered_by_file(),
    ).with_functions(title=title)
    template.ensure_built()
    print("Docs generated")
Ejemplo n.º 3
0
def run():
    arguments = argv[1:]
    assert len(arguments) == 1 or len(arguments) == 2
    template_type = arguments[0]
    assert template_type in ["demo", "skeleton"]
    available_templates = sorted(
        [str(path.basename()) for path in THIS_DIR.joinpath(template_type).listdir()]
    )

    if len(arguments) == 1:
        template_commands = [
            "hk --{} {}".format(template_type, template)
            for template in available_templates
        ]
        for template, template_command in zip(available_templates, template_commands):
            print(
                "{}{}  # {}".format(
                    template_command,
                    (
                        max([len(cmd) for cmd in template_commands])
                        - len(template_command)
                    )
                    * " ",
                    load(
                        THIS_DIR.joinpath(template_type, template, "hitchqs.yml").text()
                    ).data["about"],
                )
            )
        exit(0)

    template = arguments[1]
    if template not in available_templates:
        print("{} '{}' does not exist.".format(template_type, template))
        exit(1)

    assert template in available_templates

    template_path = THIS_DIR / template_type / template

    hitchqs_settings = load(template_path.joinpath("hitchqs.yml").text()).data

    project_path_name = hitchqs_settings["path"]

    if Path(project_path_name).exists():
        print(
            (
                "Directory '{}' already exists here, "
                "remove it to run quickstart again."
            ).format(project_path_name)
        )
        exit(1)
    cwd = Path(os.getcwd()).abspath()
    dirtemplate.DirTemplate(
        src=template_path, dest=cwd / project_path_name
    ).ignore_files("hitchqs.yml").ensure_built()
    Path(cwd / project_path_name / "fingerprint.txt").remove()
    print("Quickstart run successfully!")
Ejemplo n.º 4
0
def directory_template(all_stories,
                       project_dir,
                       story_dir,
                       build_dir,
                       readme=False):
    return (dirtemplate.DirTemplate(
        project_dir / "docs" / "src", build_dir).with_files(
            template_story_jinja2={
                "using/alpha/{0}.md".format(story.info["docs"]): {
                    "story": story
                }
                for story in all_stories.ordered_by_name()
                if story.info.get("docs") is not None
            }).with_vars(
                readme=readme,
                quickstart=all_stories.in_filename(
                    story_dir /
                    "quickstart.story").non_variations().ordered_by_file(),
                include_title=True,
            ).with_functions(title=title))