-
-
Notifications
You must be signed in to change notification settings - Fork 27
Copy images from xml output #144
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
base: main
Are you sure you want to change the base?
Conversation
Reviewer's GuideThis 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 handlingclassDiagram
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
Flow diagram for image asset copying in MkDoxy pluginflowchart 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"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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. | ||
""" |
There was a problem hiding this comment.
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>
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:
_copy_image_assets
to theMkDoxy
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._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:
Enhancements: