Skip to content

AI turns documents or topics into real, native PowerPoint decks—with native shapes, transitions and animations, data-backed charts and tables on demand, audio narration from speaker notes, and support for your own .pptx templates. · by Hugo He

fix(scripts): keep source converter help dependency-free

QiuLG79b1e108feab
diff --git a/skills/ppt-master/scripts/source_to_md/pdf_to_md.py b/skills/ppt-master/scripts/source_to_md/pdf_to_md.py
index 55104fcf..b07eb859 100644
--- a/skills/ppt-master/scripts/source_to_md/pdf_to_md.py
+++ b/skills/ppt-master/scripts/source_to_md/pdf_to_md.py
@@ -5,6 +5,8 @@ Uses PyMuPDF to extract PDF text content and convert to Markdown format.
Supports heading levels, bold, italic, and list detection.
"""
+from __future__ import annotations
+
import argparse
import hashlib
import json
@@ -24,11 +26,17 @@ from _conversion_profile import write_conversion_profile_best_effort # noqa: E4
configure_utf8_stdio()
-try:
- import fitz # PyMuPDF
-except ImportError:
- print("[ERROR] PyMuPDF not installed. Run: pip install PyMuPDF", file=sys.stderr)
- sys.exit(1)
+# Help must not depend on the optional conversion packages: a stdlib-only
+# interpreter still gets the argparse usage (docs/rules/code-style.md §4).
+_HELP_REQUESTED = __name__ == "__main__" and any(
+ arg in {"-h", "--help"} for arg in sys.argv[1:]
+)
+if not _HELP_REQUESTED:
+ try:
+ import fitz # PyMuPDF
+ except ImportError:
+ print("[ERROR] PyMuPDF not installed. Run: pip install PyMuPDF", file=sys.stderr)
+ sys.exit(1)
FONT_BODY_SIZE = 12
FONT_H1_SIZE = 24
@@ -1746,7 +1754,7 @@ def extract_pdf_to_markdown(
return markdown_content
-def main() -> int:
+def main(argv: list[str] | None = None) -> int:
"""Run the CLI entry point."""
parser = argparse.ArgumentParser(
description='PDF to Markdown converter (with structure detection and LLM optimization)',
@@ -1793,7 +1801,7 @@ Structure detection features:
help=f'DPI for --render-vector-figures output (default: {VECTOR_FIGURE_DPI})',
)
- args = parser.parse_args()
+ args = parser.parse_args(argv)
return run_path_batch(
args.inputs,
diff --git a/skills/ppt-master/scripts/source_to_md/ppt_to_md.py b/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
index 24622245..56192d6d 100644
--- a/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
+++ b/skills/ppt-master/scripts/source_to_md/ppt_to_md.py
@@ -50,13 +50,23 @@ from pptx_ooxml.diagram_read import ( # noqa: E402
smartart_to_markdown,
)
-from pptx import Presentation
-from pptx.enum.action import PP_ACTION
-from pptx.enum.shapes import MSO_SHAPE_TYPE
-from pptx.oxml.ns import qn
-
configure_utf8_stdio()
+# Help must not depend on the optional conversion packages: a stdlib-only
+# interpreter still gets the argparse usage (docs/rules/code-style.md §4).
+_HELP_REQUESTED = __name__ == "__main__" and any(
+ arg in {"-h", "--help"} for arg in sys.argv[1:]
+)
+if not _HELP_REQUESTED:
+ try:
+ from pptx import Presentation
+ from pptx.enum.action import PP_ACTION
+ from pptx.enum.shapes import MSO_SHAPE_TYPE
+ from pptx.oxml.ns import qn
+ except ImportError:
+ print("[ERROR] python-pptx not installed. Run: pip install python-pptx", file=sys.stderr)
+ sys.exit(1)
+
EMU_PER_INCH = 914400
DRAWINGML_NS = "http://schemas.openxmlformats.org/drawingml/2006/main"
@@ -1294,7 +1304,7 @@ def convert_presentation_to_markdown(
return markdown_content
-def main() -> int:
+def main(argv: list[str] | None = None) -> int:
"""Run the CLI entry point."""
parser = argparse.ArgumentParser(
description="Convert PowerPoint files to Markdown",
@@ -1320,7 +1330,7 @@ Legacy .ppt is not parsed directly. Resave it as .pptx or export it to PDF first
help="Output Markdown file for one input, or output directory for multiple inputs/directories",
)
- args = parser.parse_args()
+ args = parser.parse_args(argv)
return run_path_batch(
args.inputs,
diff --git a/skills/ppt-master/scripts/source_to_md/web_to_md.py b/skills/ppt-master/scripts/source_to_md/web_to_md.py
index 200aa477..8e3271d2 100644
--- a/skills/ppt-master/scripts/source_to_md/web_to_md.py
+++ b/skills/ppt-master/scripts/source_to_md/web_to_md.py
@@ -26,6 +26,8 @@ TLS fingerprint handling:
(scripts/source_to_md/web_to_md.cjs) remains available as a fallback.
"""
+from __future__ import annotations
+
import argparse
import codecs
import datetime
@@ -50,13 +52,19 @@ from _conversion_profile import ( # noqa: E402
configure_utf8_stdio()
-try:
- import requests
- from bs4 import BeautifulSoup, Comment, NavigableString, Tag
-except ImportError:
- print("Error: This script requires 'requests' and 'beautifulsoup4'.")
- print("Please run: pip install requests beautifulsoup4")
- sys.exit(1)
+# Help must not depend on the optional conversion packages: a stdlib-only
+# interpreter still gets the argparse usage (docs/rules/code-style.md §4).
+_HELP_REQUESTED = __name__ == "__main__" and any(
+ arg in {"-h", "--help"} for arg in sys.argv[1:]
+)
+if not _HELP_REQUESTED:
+ try:
+ import requests
+ from bs4 import BeautifulSoup, Comment, NavigableString, Tag
+ except ImportError:
+ print("Error: This script requires 'requests' and 'beautifulsoup4'.", file=sys.stderr)
+ print("Please run: pip install requests beautifulsoup4", file=sys.stderr)
+ sys.exit(1)
# Prefer curl_cffi for TLS-fingerprint impersonation (bypasses JA3 blocking on
# sites like WeChat). Fall back to plain requests when it's not installed.
@@ -178,8 +186,9 @@ try:
PILLOW_AVAILABLE = True
except ImportError:
PILLOW_AVAILABLE = False
- print("[WARN] Pillow not installed. WebP images will not be converted to PNG.")
- print(" Run: pip install Pillow")
+ if not _HELP_REQUESTED:
+ print("[WARN] Pillow not installed. WebP images will not be converted to PNG.", file=sys.stderr)
+ print(" Run: pip install Pillow", file=sys.stderr)
# ============ Config ============
CONFIG = {
@@ -1090,7 +1099,8 @@ def main(argv: list[str] | None = None) -> int:
if __name__ == "__main__":
- # Disable warnings for verify=False if needed, though often useful to see
- import urllib3
- urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+ if not _HELP_REQUESTED:
+ # Disable warnings for verify=False if needed, though often useful to see
+ import urllib3
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
raise SystemExit(main())