Commit Graph

5 Commits

Author SHA1 Message Date
Muyuan Li (from Dev Box)
8c1cf09802 Add audio and video format support to Python extensions
- Update regex and ApInputTypeToFormat to recognize audio/video input types
- Add audio_path/video_path fields to input payload (Windows + WSL)
- Handle audio/video result types in ParseOutputAsync (Windows + WSL)
- Update _runner.py pattern, input_map, _apply_output_hint, _format_output
- Add 4 unit tests for audio/video metadata (input + output hints)
- Update documentation with audio/video in input/output tables

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-15 16:26:40 +08:00
Muyuan Li (from Dev Box)
78d05c9082 Python scripts: mandatory _to_ format, single function per script, WSL support
- Function naming: advanced_paste_from_<input>_to_<output> is now the only
  supported format. The old format without _to_ is removed.
- Each script must define exactly one advanced_paste_from_* function.
- Added WSL execution path (ExecuteScriptViaWslAsync) for users with Python
  only in WSL.
- New settings: UseWsl toggle and WslDistribution text field in Settings UI.
- Runner sets ADVANCED_PASTE_WORK_DIR env var so file-output scripts write
  to Windows-accessible paths under /mnt/c/ when running in WSL.
- Updated unit tests: replaced InferFormatsFromSignature tests with
  ReadMetadata tests covering the new naming convention.
- Updated documentation with WSL mode instructions and work_dir guidance.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-15 10:32:18 +08:00
Muyuan Li (from Dev Box)
8778af2e32 Add InferFormatsFromSignature unit tests and fix mock
- Add 11 unit tests for V2 format inference from convert() signature
- Fix IntegrationTestUserSettings mock to implement IsPythonScriptsEnabled
- All 33 PythonScriptServiceTests pass

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-05-11 10:44:12 +08:00
Muyuan Li
2051c13bf9 Improve Python script error handling and prevent freezes
- Extract script name, line, and column from Python tracebacks in error summaries
- Add ParsePipInstallError to show concise pip errors with full stderr in details tooltip
- Add timeouts to pip install (Windows/WSL) and import-check subprocesses to prevent UI freezes
- Add PythonPackageInstallTimeout resource string
- Add unit tests for all new parsing logic
2026-04-15 16:10: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