Commit Graph

2 Commits

Author SHA1 Message Date
Muyuan Li (from Dev Box)
aa3f1165b3 AdvancedPaste: V2 unified Python script interface with convert() function
Redesign the Python script extension interface to use a function-based
contract instead of platform-specific clipboard access:

- Scripts define a single convert() function that receives clipboard data
  as keyword arguments and returns the result
- Format support is inferred from the function's parameter names
  (text, html, image_path, file_paths, work_dir)
- Return value can be str, dict, Path, or list — runner normalizes it
- Platform tag eliminated — unified execution on Windows and WSL
- Only 'name' header remains required; desc, formats, platform all optional/inferred
- Ships _runner.py bootstrap that handles JSON stdin/stdout plumbing
- Full backward compat: scripts without convert() use legacy V1 paths

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-07 16:09:49 +08:00
Muyuan Li
4c7bf3df79 [AdvancedPaste] Python scripts: docs, custom folder, auto-import detection, better errors
1. Script header documentation (doc/devdocs/modules/advancedpaste-python-scripts.md)
   - Complete reference for all @advancedpaste: header tags
   - Windows and WSL/Linux execution mode protocols
   - Declaring dependencies, security trust model, error handling
   - Example scripts for both platforms

2. Custom scripts folder setting in Settings UI
   - Added ScriptsFolder property to AdvancedPasteViewModel
   - Added SettingsCard with TextBox + Browse folder dialog in XAML
   - Added localization strings for the new setting

3. Auto-detect missing Python modules from import statements
   - Scans script body for import/from-import statements
   - Filters Python stdlib modules (CPython 3.12 set)
   - Well-known import-to-pip mapping table (pywin32, Pillow, opencv-python, etc.)
   - Merges auto-detected imports with explicit @advancedpaste:requires entries
   - Explicit requires always take precedence

4. Better error messages for Python script failures
   - Parses stderr to extract the final Python exception line
   - User-friendly summaries for ModuleNotFoundError, SyntaxError, etc.
   - ModuleNotFoundError includes pip install hint from the mapping table
   - Full traceback available in Details section of the error UI

Added 12 unit tests for MergeWithAutoDetectedImports and ParsePythonError.
Fixed IntegrationTestUserSettings mock to implement IUserSettings Python members.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-04-02 16:56:42 +08:00