microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/experimental/tts-voiceover/scripts/Modules/TtsVoiceoverHelpers.psm1
75lines · modecode
| 1 | # Copyright (c) Microsoft Corporation. |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # TtsVoiceoverHelpers.psm1 |
| 4 | # Purpose: Shared helper functions for tts-voiceover skill PowerShell wrappers. |
| 5 | #Requires -Version 7.0 |
| 6 | |
| 7 | function Test-UvAvailability { |
| 8 | <# |
| 9 | .SYNOPSIS |
| 10 | Verifies uv is available on PATH. |
| 11 | .OUTPUTS |
| 12 | [string] The resolved uv command path. |
| 13 | #> |
| 14 | [CmdletBinding()] |
| 15 | [OutputType([string])] |
| 16 | param() |
| 17 | |
| 18 | $resolved = Get-Command 'uv' -ErrorAction SilentlyContinue |
| 19 | if ($resolved) { |
| 20 | return $resolved.Source |
| 21 | } |
| 22 | throw 'uv is required but was not found on PATH. Install with: curl -LsSf https://astral.sh/uv/install.sh | sh' |
| 23 | } |
| 24 | |
| 25 | function Initialize-PythonEnvironment { |
| 26 | <# |
| 27 | .SYNOPSIS |
| 28 | Syncs the Python virtual environment and dependencies via uv. |
| 29 | .PARAMETER SkillRoot |
| 30 | Root directory of the skill containing pyproject.toml. |
| 31 | #> |
| 32 | [CmdletBinding()] |
| 33 | [OutputType([void])] |
| 34 | param( |
| 35 | [Parameter(Mandatory = $true)] |
| 36 | [ValidateNotNullOrEmpty()] |
| 37 | [string]$SkillRoot |
| 38 | ) |
| 39 | |
| 40 | Write-Host 'Syncing Python environment via uv...' |
| 41 | & uv sync --directory "$SkillRoot" |
| 42 | if ($LASTEXITCODE -ne 0) { |
| 43 | throw 'Failed to sync Python environment via uv.' |
| 44 | } |
| 45 | Write-Host 'Environment synchronized.' |
| 46 | } |
| 47 | |
| 48 | function Get-VenvPythonPath { |
| 49 | <# |
| 50 | .SYNOPSIS |
| 51 | Returns the path to the venv Python executable. |
| 52 | .PARAMETER VenvDir |
| 53 | Path to the .venv directory. |
| 54 | .OUTPUTS |
| 55 | [string] Absolute path to the venv python binary. |
| 56 | #> |
| 57 | [CmdletBinding()] |
| 58 | [OutputType([string])] |
| 59 | param( |
| 60 | [Parameter(Mandatory = $true)] |
| 61 | [ValidateNotNullOrEmpty()] |
| 62 | [string]$VenvDir |
| 63 | ) |
| 64 | |
| 65 | if ($IsWindows) { |
| 66 | return Join-Path $VenvDir 'Scripts/python.exe' |
| 67 | } |
| 68 | return Join-Path $VenvDir 'bin/python' |
| 69 | } |
| 70 | |
| 71 | Export-ModuleMember -Function @( |
| 72 | 'Test-UvAvailability' |
| 73 | 'Initialize-PythonEnvironment' |
| 74 | 'Get-VenvPythonPath' |
| 75 | ) |
| 76 | |