Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring/cleanup and typing #802

Merged
merged 2 commits into from
Feb 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions breathe/directives/index.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from ..renderer.mask import NullMaskFactory
from ..directives import BaseDirective
from ..project import ProjectError
from ..parser import ParserError, FileIOError

from breathe.directives import BaseDirective
from breathe.parser import ParserError, FileIOError
from breathe.project import ProjectError
from breathe.renderer import format_parser_error, RenderContext
from breathe.renderer.mask import NullMaskFactory
from breathe.renderer.sphinxrenderer import SphinxRenderer
from breathe.renderer.target import create_target_handler

from docutils.nodes import Node
from docutils.parsers.rst.directives import unchanged_required, flag # type: ignore

from typing import List


class RootDataObject:
node_type = "root"
Expand Down Expand Up @@ -95,9 +97,9 @@ class AutoDoxygenIndexDirective(_BaseIndexDirective):
}
has_content = False

def run(self):
def run(self) -> List[Node]:
"""Extract the project info from the auto project info store and pass it to the helper
method
method.
"""

try:
Expand Down
2 changes: 1 addition & 1 deletion breathe/directives/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def write_file(directory, filename, content):
subprocess.check_call, write_file, project_info_factory
)

def doxygen_hook(app):
def doxygen_hook(app: Sphinx):
doxygen_handle.generate_xml(
app.config.breathe_projects_source,
app.config.breathe_doxygen_config_options,
Expand Down
59 changes: 29 additions & 30 deletions breathe/process.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
from __future__ import unicode_literals

from breathe.project import ProjectInfoFactory

try:
from shlex import quote # py3
except ImportError:
from pipes import quote # py2
from breathe.project import AutoProjectInfo, ProjectInfoFactory

import os
from shlex import quote
from typing import Callable, Dict, List, Tuple


AUTOCFG_TEMPLATE = r"""
Expand All @@ -31,55 +26,59 @@
""".strip()


class ProjectData(object):
"Simple handler for the files and project_info for each project"

def __init__(self, auto_project_info, files):
class ProjectData:
"""Simple handler for the files and project_info for each project."""

def __init__(self, auto_project_info: AutoProjectInfo, files: List[str]) -> None:
self.auto_project_info = auto_project_info
self.files = files


class AutoDoxygenProcessHandle:
def __init__(self, run_process, write_file, project_info_factory: ProjectInfoFactory):
def __init__(
self,
run_process: Callable,
write_file: Callable[[str, str, str], None],
project_info_factory: ProjectInfoFactory,
) -> None:
self.run_process = run_process
self.write_file = write_file
self.project_info_factory = project_info_factory

def generate_xml(self, projects_source, doxygen_options, doxygen_aliases):

project_files = {}
def generate_xml(
self,
projects_source: Dict[str, Tuple[str, List[str]]],
doxygen_options: Dict[str, str],
doxygen_aliases: Dict[str, str],
) -> None:
project_files: Dict[str, ProjectData] = {}

# First collect together all the files which need to be doxygen processed for each project
for project_name, file_structure in projects_source.items():

folder = file_structure[0]
contents = file_structure[1]

folder, contents = file_structure
auto_project_info = self.project_info_factory.create_auto_project_info(
project_name, folder
)

project_files[project_name] = ProjectData(auto_project_info, contents)

# Iterate over the projects and generate doxygen xml output for the files for each one into
# a directory in the Sphinx build area
for project_name, data in project_files.items():

project_path = self.process(
data.auto_project_info, data.files, doxygen_options, doxygen_aliases
)

project_info = data.auto_project_info.create_project_info(project_path)

self.project_info_factory.store_project_info_for_auto(project_name, project_info)

def process(self, auto_project_info, files, doxygen_options, doxygen_aliases):

def process(
self,
auto_project_info: AutoProjectInfo,
files: List[str],
doxygen_options: Dict[str, str],
doxygen_aliases: Dict[str, str],
) -> str:
name = auto_project_info.name()
cfgfile = "%s.cfg" % name

full_paths = map(lambda x: auto_project_info.abs_path_to_source_file(x), files)
full_paths = [auto_project_info.abs_path_to_source_file(f) for f in files]

options = "\n".join("%s=%s" % pair for pair in doxygen_options.items())
aliases = "\n".join(
Expand All @@ -94,7 +93,7 @@ def process(self, auto_project_info, files, doxygen_options, doxygen_aliases):
)

build_dir = os.path.join(auto_project_info.build_dir(), "breathe", "doxygen")

cfgfile = "%s.cfg" % name
self.write_file(build_dir, cfgfile, cfg)

# Shell-escape the cfg file name to try to avoid any issue where the name might include
Expand Down