def get_installation_markdown(self):
        """ Get install markdown.

            :param generalpackager.Packager self: """
        markdown = Markdown(header="Installation")

        dependencies_required = self.localrepo.install_requires.copy()
        dependencies_optional = list(
            set().union(*self.localrepo.extras_require.values()))
        dependencies_optional.sort()

        options = {self.name: dependencies_required}
        options.update({
            f"{self.name}[{key}]": value + dependencies_required
            for key, value in self.localrepo.extras_require.items()
        })

        list_of_dicts = []

        for command, packages in options.items():
            row = {"Command": f"`pip install {command}`"}
            for dependency in dependencies_required + dependencies_optional:
                row[Markdown.link(
                    dependency,
                    url=f"https://pypi.org/project/{dependency}",
                    href=True)] = "Yes" if dependency in packages else "No"
            list_of_dicts.append(row)

        markdown.add_table_lines(*list_of_dicts)

        return markdown
    def generate_readme(self):
        """ Generate readme markdown and overwrite README.md in local repo.

            :param generalpackager.Packager self: """
        # Description
        markdown = self.get_description_markdown()

        # Information
        self.get_information_markdown().set_parent(parent=markdown)

        # Table of contents
        contents = Markdown(header="Contents", parent=markdown)

        # Installation
        self.get_installation_markdown().set_parent(parent=markdown)

        # Attributes
        self.get_attributes_markdown().set_parent(parent=markdown)

        # Todos
        self.get_todos_markdown(
            self, drop_package_col=True).set_parent(parent=markdown)

        # Table of contents - Configuration
        self._configure_contents_markdown(markdown=contents)

        # Generation timestamp
        self.get_footnote_markdown().set_parent(parent=markdown)

        return markdown
    def get_description_markdown(self):
        """ :param generalpackager.Packager self: """
        part_of = f"This package and {len(self.get_all()) - 1} other make up {Markdown.link(text='ManderaGeneral', url='https://github.com/ManderaGeneral')}."

        return Markdown(self.localrepo.description,
                        "\n",
                        part_of,
                        header=self.name)
    def github_link(self, text, suffix):
        """ Get an HREF link to this repo's github.

            :param generalpackager.Packager self:
            :param text: Text to be clickable.
            :param suffix: URL suffix. """
        url = f"{self.github.url}/{suffix}"
        return Markdown.link(text=text, url=url, href=True)
    def get_footnote_markdown(self, commit=True):
        """ Get a markdown for footnote containing date, time and commit link.

            :param generalpackager.Packager self:
            :param commit: """
        line = f"Generated {Date.now()}"
        if commit:
            line += f" for commit {self.github_link(text=self.commit_sha, suffix=f'commit/{self.commit_sha}')}."

        return Markdown(line).wrap_with_tags("sup")
 def _create_todo_dict(self, text, path, line):
     """ :param generalpackager.Packager self: """
     path = Path(path)
     return {
         "Package":
         Markdown.link(text=self.name, url=self.github.url),
         "Module":
         self.github_link_path_line(text=path.name(), path=path, line=1),
         "Message":
         self.github_link_path_line(text=text, path=path, line=line),
     }
    def get_information_markdown(self, *packagers):
        """ Get information table.

            :param generalpackager.Packager self: """
        if not packagers:
            packagers = (self, )

        markdown = Markdown(header="Information")
        python_url = "https://www.python.org/downloads/release/python-"

        list_of_dicts = []
        for packager in packagers:
            attrs = packager._get_attributes_view().count("\n")
            untested_attrs = len(packager.get_untested_objInfo_dict())
            test_percentage = floor(
                (attrs - untested_attrs) / attrs * 100, 1) if attrs else 100

            list_of_dicts.append({
                "Package":
                Markdown.link(text=packager.name, url=packager.github.url),
                "Ver":
                Markdown.link(text=packager.localrepo.version,
                              url=packager.pypi.url),
                "Latest Release":
                packager.get_latest_release(),
                "Python":
                ", ".join([
                    Markdown.link(
                        text=ver,
                        url=f"{python_url}{str(ver).replace('.', '')}0/")
                    for ver in packager.python
                ]),
                "Platform":
                ", ".join(map(str.capitalize, packager.os)),
                "Lvl":
                packager.get_ordered_index(),
                "Todo":
                Markdown.link(
                    text=len(packager.get_todos()),
                    url=f"{packager.github.url}#{self._todo_header}"),
                "Tests":
                f"{test_percentage} %",
            })
        markdown.add_table_lines(*list_of_dicts, sort_by=["Lvl", "Package"])
        return markdown
    def get_todos_markdown(self, *packagers, drop_package_col=False):
        """ :param generalpackager.Packager self:
            :param drop_package_col: """
        todos = flatten([packager.get_todos() for packager in packagers])
        if drop_package_col:
            todos = [exclusive(todo, "Package") for todo in todos]

        markdown = Markdown(header=self._todo_header)
        if todos:
            markdown.add_table_lines(*todos)
        else:
            markdown.add_node("No todos!")
        return markdown
    def generate_personal_readme(self):
        """ Generate personal readme markdown and overwrite README.md in local repo.

            :param generalpackager.Packager self: """
        ordered_packagers = type(self)().get_ordered_packagers()

        # Description
        markdown = Markdown(header="ManderaGeneral").add_list_lines(
            "A collection of connected packages.",
            "Violently updated with little regard for backwards compatability.",
            "Automatic workflows to unittest, sync and publish.",
        )

        # Package information
        self.get_information_markdown(*ordered_packagers).set_parent(
            parent=markdown)

        # Todos
        self.get_todos_markdown(*ordered_packagers).set_parent(parent=markdown)

        # Generation timestamp
        self.get_footnote_markdown(commit=False).set_parent(parent=markdown)

        return markdown
    def get_attributes_markdown(self):
        """ Get a recursive view of attributes markdown.

            :param generalpackager.Packager self: """
        return Markdown(header="Attributes").add_pre_lines(
            self._get_attributes_view())