예제 #1
0
    def dumps(self, story_steps: List[StoryStep]) -> Text:
        """Turns Story steps into a string.

        Args:
            story_steps: Original story steps to be converted to the YAML.
        Returns:
            String with story steps in the YAML format.
        """
        stream = yaml.StringIO()
        self.dump(stream, story_steps)
        return stream.getvalue()
예제 #2
0
 def __init__(self, title, workflow_definition: WorkflowDefinition):
     super().__init__(title)
     try:
         self.relative_filename = workflow_definition.relative_filename
         self.workflow_source = workflow_definition.file_contents
         with yaml.StringIO() as stream:
             yaml.dump(workflow_definition.inputs,
                       stream,
                       default_flow_style=False)
             self.inputs = stream.getvalue()
     except AttributeError:
         self.inputs = ''
         self.relative_filename = ''
         self.workflow_source = ''
예제 #3
0
    def dumps(self,
              story_steps: List[StoryStep],
              is_appendable: bool = False,
              **kwargs: Any) -> Text:
        """Turns Story steps into an YAML string.

        Args:
            story_steps: Original story steps to be converted to the YAML.
            is_appendable: Specify if result should not contain
                           high level keys/definitions and can be appended to
                           the existing story file.
        Returns:
            String with story steps in the YAML format.
        """
        stream = yaml.StringIO()
        self.dump(stream, story_steps, is_appendable)
        return stream.getvalue()
예제 #4
0
def make_rtfd(repo_path: pathlib.Path, templates: Environment) -> List[str]:
    """
	Add configuration for ``ReadTheDocs``.

	https://readthedocs.org/

	See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

	:param repo_path: Path to the repository root.
	:param templates:
	"""

    file = PathPlus(repo_path / ".readthedocs.yml")

    docs_dir = PathPlus(repo_path / templates.globals["docs_dir"])

    sphinx_config = {
        "builder": "html",
        "configuration": f"{templates.globals['docs_dir']}/conf.py",
    }

    install_requirements = [
        "requirements.txt",
        f"{templates.globals['docs_dir']}/requirements.txt",
        *templates.globals["additional_requirements_files"],
    ]

    install_config: List[Dict] = [{
        "requirements": r
    } for r in install_requirements]

    if (docs_dir / "rtd-extra-deps.txt").is_file():
        install_config.append({
            "requirements":
            f"{templates.globals['docs_dir']}/rtd-extra-deps.txt"
        })
    elif templates.globals["tox_testenv_extras"]:
        install_config.append({
            "method":
            "pip",
            "path":
            '.',
            "extra_requirements": [templates.globals["tox_testenv_extras"]],
        })

    else:
        install_config.append({"method": "pip", "path": '.'})

    python_config = {"version": 3.8, "install": install_config}

    # Formats: Optionally build your docs in additional formats such as PDF and ePub
    config = {
        "version": 2,
        "sphinx": sphinx_config,
        "formats": ["pdf", "htmlzip"],
        "python": python_config
    }

    # TODO: support user customisation of search rankings
    # https://docs.readthedocs.io/en/stable/config-file/v2.html#search-ranking

    dumper = yaml.YAML()
    dumper.indent(mapping=2, sequence=3, offset=1)

    yaml_buf = yaml.StringIO()
    dumper.dump(config, yaml_buf)

    file.write_lines([
        f"# {templates.globals['managed_message']}",
        "# Read the Docs configuration file", "---",
        yaml_buf.getvalue()
    ])

    return [file.relative_to(repo_path).as_posix()]
예제 #5
0
 def get_workflow_contents(self):
     with yaml.StringIO() as stream:
         yaml.dump(self.get_file_info(), stream)
         return stream.getvalue()