Skip to content

Conversation

mutalibmohammed
Copy link

@mutalibmohammed mutalibmohammed commented Oct 1, 2025

This pull request adds support for automatically copying image assets generated by Doxygen (such as .png, .jpg, .svg, etc.) into the MkDocs API output directory.

This ensures that images referenced in the generated documentation are available and properly included in the MkDocs build.

Image asset handling:

  • Added a new method _copy_image_assets to the MkDoxy plugin, which finds and copies image files from the Doxygen XML output directory to the MkDocs API output directory. It supports common image extensions and returns the list of copied image paths.
  • Defined a set of supported image extensions (_IMAGE_EXTENSIONS) to identify image files to be copied.

Summary by Sourcery

Add support for copying Doxygen-generated image assets into the MkDocs API output directory and including them in the site build.

New Features:

  • Automatically copy and include Doxygen-generated image assets (png, jpg, jpeg, gif, bmp, svg, webp) into the MkDocs API output directory and site files list.

Enhancements:

  • Define a new _IMAGE_EXTENSIONS constant to configure recognized image file types.
  • Implement a _copy_image_assets method to discover, copy, and track image files preserving their directory structure.
  • Extend the on_files hook to invoke image copying, log the number of copied assets, and append them to the MkDocs files collection.

Copy link

sourcery-ai bot commented Oct 1, 2025

Reviewer's Guide

This PR extends the MkDoxy plugin to automatically discover, copy, and register Doxygen-generated image assets into the MkDocs API output directory by defining supported extensions, adding a copy routine, and integrating it into the file-gathering hook.

Class diagram for updated MkDoxy plugin image asset handling

classDiagram
    class MkDoxy {
        +_IMAGE_EXTENSIONS: set[str]
        +_copy_image_assets(source_xml_dir: Path, destination_dir: Path) list[PurePath]
        +on_files(files: Files, config: Config) Files
    }
    MkDoxy --|> BasePlugin
Loading

Flow diagram for image asset copying in MkDoxy plugin

flowchart TD
    A["Doxygen XML output directory"] --> B["Find image files with supported extensions"]
    B --> C["Copy image files to MkDocs API output directory"]
    C --> D["Register copied images in MkDocs file list"]
Loading

File-Level Changes

Change Details Files
Support automatic copying and inclusion of Doxygen image assets
  • Define a new set of supported image extensions (_IMAGE_EXTENSIONS)
  • Implement _copy_image_assets to locate, filter by extension, and copy image files
  • Invoke the copy routine in on_files, log the count, dedupe, and append new File entries
mkdoxy/plugin.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@mutalibmohammed mutalibmohammed marked this pull request as ready for review October 2, 2025 16:30
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `mkdoxy/plugin.py:67-76` </location>
<code_context>
+    def _copy_image_assets(self, source_xml_dir: Path, destination_dir: Path) -> list[PurePath]:
</code_context>

<issue_to_address>
**🚨 issue (security):** Potential issue with file overwrites if image names collide in nested directories.

Ensure the destination directory structure is unique per project and validate that both source and destination paths remain within intended directories. Explicitly handle symlinks to prevent overwrites or security issues.
</issue_to_address>

### Comment 2
<location> `mkdoxy/plugin.py:92-93` </location>
<code_context>
+            relative_path = image_path.relative_to(source_xml_dir)
+            destination_path = destination_dir.joinpath(relative_path)
+            destination_path.parent.mkdir(parents=True, exist_ok=True)
+            shutil.copy2(image_path, destination_path)
+            copied.append(relative_path)
+
</code_context>

<issue_to_address>
**suggestion (bug_risk):** shutil.copy2 may raise exceptions if file permissions or disk space are insufficient.

Consider handling exceptions during the copy operation to prevent the build from stopping unexpectedly. Logging errors and continuing with other files may improve robustness unless a fatal failure is desired.

```suggestion
            try:
                shutil.copy2(image_path, destination_path)
                copied.append(relative_path)
            except Exception as e:
                logging.error(f"Failed to copy {image_path} to {destination_path}: {e}")
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +67 to +76
def _copy_image_assets(self, source_xml_dir: Path, destination_dir: Path) -> list[PurePath]:
"""Copy image assets generated by Doxygen into the MkDocs API output directory.
Args:
source_xml_dir: Path where Doxygen stores the XML output (and accompanying assets).
destination_dir: Path inside MkDocs' temporary directory where generated markdown lives.
Returns:
List of relative paths (to ``destination_dir``) for the copied images.
"""
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 issue (security): Potential issue with file overwrites if image names collide in nested directories.

Ensure the destination directory structure is unique per project and validate that both source and destination paths remain within intended directories. Explicitly handle symlinks to prevent overwrites or security issues.

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant