From 034b175819bed8179b0b551e712d66f60823ed60 Mon Sep 17 00:00:00 2001 From: pooya1380m Date: Tue, 29 Jul 2025 00:21:10 +0330 Subject: [PATCH] Add checks for Python and uv dependencies in build process --- dotnet/Directory.Build.targets | 19 ++++++++++ dotnet/eng/check-prereqs.ps1 | 69 ++++++++++++++++++++++++++++++++++ dotnet/eng/check-prereqs.sh | 69 ++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+) create mode 100644 dotnet/eng/check-prereqs.ps1 create mode 100644 dotnet/eng/check-prereqs.sh diff --git a/dotnet/Directory.Build.targets b/dotnet/Directory.Build.targets index 5a7247c3126f..a72aa5a6f50f 100644 --- a/dotnet/Directory.Build.targets +++ b/dotnet/Directory.Build.targets @@ -10,4 +10,23 @@ + + + false + + + + + + + + + + + + diff --git a/dotnet/eng/check-prereqs.ps1 b/dotnet/eng/check-prereqs.ps1 new file mode 100644 index 000000000000..5a69ee15bb33 --- /dev/null +++ b/dotnet/eng/check-prereqs.ps1 @@ -0,0 +1,69 @@ +param ( + [switch]$InstallMissing +) + +$ErrorActionPreference = "Stop" +$Missing = @() + +function Check-Command { + param ([string]$Name) + if (-not (Get-Command $Name -ErrorAction SilentlyContinue)) { + Write-Host ("Missing: {0,-10} - not found in PATH" -f $Name) + $script:Missing += $Name + } + else { + Write-Host ("Found: {0,-10}" -f $Name) + } +} + +function Install-Tool { + param ([string]$Tool) + Write-Host "Installing $Tool..." + + switch ($Tool) { + "python" { + if (Get-Command winget -ErrorAction SilentlyContinue) { + winget install -e --id Python.Python.3 + } + elseif (Get-Command choco -ErrorAction SilentlyContinue) { + choco install python3 -y + } + else { + Write-Host "No supported package manager (winget or choco) found." + exit 1 + } + } + "uv" { + Invoke-WebRequest -Uri "https://astral.sh/uv/install.ps1" -UseBasicParsing | Invoke-Expression + } + default { + Write-Host "No install logic defined for: $Tool" + exit 1 + } + } +} + +Write-Host "Checking for required tools..." +Check-Command python +Check-Command uv + +if ($Missing.Count -gt 0) { + Write-Host "`nMissing tools detected: $Missing" + + if ($InstallMissing) { + foreach ($tool in $Missing) { + Install-Tool $tool + } + Write-Host "`nAll missing tools installed." + } + else { + Write-Host "`nSome required tools are missing. Re-run with '--install-missing' to install them." + Write-Host "" + Write-Host "For manual setup instructions, see:" + Write-Host "https://github.com/microsoft/autogen/blob/main/python/README.md#setup" + exit 1 + } +} +else { + Write-Host "`nAll required tools are installed." +} diff --git a/dotnet/eng/check-prereqs.sh b/dotnet/eng/check-prereqs.sh new file mode 100644 index 000000000000..4a6134ebba8c --- /dev/null +++ b/dotnet/eng/check-prereqs.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +set -euo pipefail + +MISSING=() +INSTALL=false + +if [[ "${1:-}" == "--install-missing" ]]; then + INSTALL=true +fi + +check_command() { + local name=$1 + if ! command -v "$name" &>/dev/null; then + printf "Missing: %-10s - not found in PATH\n" "$name" + MISSING+=("$name") + else + printf "Found: %-10s\n" "$name" + fi +} + +install_tool() { + local tool=$1 + echo "Installing $tool..." + case "$tool" in + python3) + if command -v brew &>/dev/null; then + brew install python + elif command -v apt &>/dev/null; then + sudo apt update && sudo apt install -y python3 + elif command -v dnf &>/dev/null; then + sudo dnf install -y python3 + else + echo "Unsupported package manager. Please install $tool manually." + return 1 + fi + ;; + uv) + curl -Ls https://astral.sh/uv/install.sh | sh + ;; + *) + echo "No install method defined for: $tool" + return 1 + ;; + esac +} + +echo "Checking for required tools..." +check_command python3 +check_command uv + +if [ ${#MISSING[@]} -ne 0 ]; then + echo "" + echo "Missing tools detected: ${MISSING[*]}" + + if [ "$INSTALL" = true ]; then + for tool in "${MISSING[@]}"; do + install_tool "$tool" + done + echo "All missing tools have been installed." + else + echo "Some required tools are missing. Use '--install-missing' to install them automatically." + echo "" + echo "For manual setup instructions, see: " + echo "https://github.com/microsoft/autogen/blob/main/python/README.md#setup" + exit 1 + fi +else + echo "All required tools are installed." +fi