From 9a7dbb514dc7bcc5cda929a546f5576121c0bb64 Mon Sep 17 00:00:00 2001 From: ivaquero Date: Fri, 22 Nov 2024 22:45:32 +0800 Subject: [PATCH] miniforge-cn: update installer section --- bucket/micromamba.json | 40 ++++++---- bucket/miniconda-cn.json | 22 +++--- bucket/miniforge-cn.json | 44 ++++++----- scripts/AppsUtils.psm1 | 155 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 213 insertions(+), 48 deletions(-) diff --git a/bucket/micromamba.json b/bucket/micromamba.json index cbac7993f..fd108ab6e 100644 --- a/bucket/micromamba.json +++ b/bucket/micromamba.json @@ -1,30 +1,40 @@ { "homepage": "https://github.com/mamba-org/mamba", - "version": "1.5.11-0", + "description": "Micromamba is a tiny version of mamba, the fast conda package installer.", + "version": "2.0.4alpha3-0", "license": "BSD-3-Clause", - "description": "The Fast Cross-Platform Package Manager", "architecture": { "64bit": { - "url": "https://micro.mamba.pm/api/micromamba/win-64/latest#/dl.tar.bz2", - "hash": "4e7af0e090e2dd4d0b245f62f1815de332fda1b1b6988eddb222904582d3f9d4" + "url": "https://github.com/mamba-org/micromamba-releases/releases/download/2.0.4alpha3-0/micromamba-win-64#/micromamba.exe", + "hash": "d486f9c47e3edf7f7682f4bfba76561935e99a6cc05327c06498bb4c3d6da5ad" } }, - "bin": "Library\\bin\\micromamba.exe", - "persist": [ - "envs", - "condabin", - "pkgs", - "Scripts" - ], + "post_install": "New-Item -Path \"$dir\\base\" -ItemType Directory -Force | Out-Null", + "env_set": { + "MAMBA_ROOT_PREFIX": "$dir\\base", + "MAMBA_EXE": "$dir\\micromamba.exe" + }, "checkver": { - "url": "https://anaconda.org/conda-forge/micromamba/files", - "regex": "win-64/micromamba-([\\d.-]+)\\.tar" + "url": "https://api.anaconda.org/release/conda-forge/micromamba/latest", + "regex": "win-64/micromamba-([\\d.]+([\\w-]+)).tar.bz2" }, "autoupdate": { "architecture": { "64bit": { - "url": "https://micro.mamba.pm/api/micromamba/win-64/latest#/dl.tar.bz2" + "url": "https://github.com/mamba-org/micromamba-releases/releases/download/$version/micromamba-win-64#/micromamba.exe", + "hash": { + "url": "$url.sha256" + } } } - } + }, + "notes": [ + "No shim is now exposed for micromamba, you have to add following hook to your PowerShell $PROFILE to use it:", + "", + "(& $env:MAMBA_EXE 'shell' 'hook' -s 'powershell') | Out-String | Invoke-Expression", + "", + "Also note that the mamba base environment located in $env:MAMBA_ROOT_PREFIX is now NOT persisted,", + "we advice to setup 'envs_dirs' to use a seperated path like '~/.conda/envs' and avoid using the base env.", + "https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#specify-environment-directories-envs-dirs" + ] } diff --git a/bucket/miniconda-cn.json b/bucket/miniconda-cn.json index bc0118ec6..23b6d3b28 100644 --- a/bucket/miniconda-cn.json +++ b/bucket/miniconda-cn.json @@ -1,20 +1,21 @@ { - "version": "23.5.2-0", - "description": "A cross-platform, Python-agnostic binary package manager.", - "homepage": "https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/", + "version": "24.9.2-0", + "description": "A cross-platform, Python-agnostic binary package manager", + "homepage": "https://docs.anaconda.com/free/miniconda/", "license": "BSD-3-Clause", "notes": [ "From 4.6.0, conda has built the support for Cmd, Powershell or other shells.", "Use \"conda init powershell\" or \"conda init __your_favorite_shell__\"", "", - "Miniconda3 drops support for 32-bit CPUs from v22.11.1. If you are running a 32-bit system, please install miniconda3-4.12.0 from the Versions bucket." + "Miniconda3 drops support for 32-bit CPUs from v22.9.0. If you are running a 32-bit system, please install miniconda3-4.12.0 from the Versions bucket." ], "architecture": { "64bit": { - "url": "https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_23.5.2-0-Windows-x86_64.exe#/setup.exe", - "hash": "e15638645b34921098a3f760fd8af07e53a427f59b99a0f049420a7751cbbc05" + "url": "https://repo.anaconda.com/miniconda/Miniconda3-py312_24.9.2-0-Windows-x86_64.exe#/setup.exe", + "hash": "3a8897cc5d27236ade8659f0e119f3a3ccaad68a45de45bfdd3102d8bec412ab" } }, + "pre_install": "if ($dir -match ' ') { error 'The installation directory cannot include a space'; break}", "installer": { "script": [ "# Using Start-Process as a workaround because the installer will not work properly when args are quoted (e.g. \"`\"/S`\"\")", @@ -23,6 +24,7 @@ "Start-Process \"$dir\\..\\setup.exe\" -ArgumentList @('/S', '/InstallationType=JustMe', '/RegisterPython=0', '/AddToPath=0', '/NoRegistry=1', \"/D=$dir\") -Wait | Out-Null" ] }, + "post_install": "Remove-Item \"$dir\\..\\setup.exe\" -Force | Out-Null", "uninstaller": { "script": [ "Start-Process \"$dir\\Uninstall-Miniconda3.exe\" -ArgumentList '/S' -Wait | Out-Null", @@ -44,17 +46,17 @@ ], "persist": "envs", "checkver": { - "url": "https://docs.conda.io/en/latest/miniconda.html", - "regex": "Miniconda3-py310_([\\d.-]+)-Windows" + "url": "https://docs.anaconda.com/free/miniconda/miniconda-other-installer-links/", + "regex": "Miniconda3-py(?\\d+)_([\\d.-]+)-Windows" }, "autoupdate": { "architecture": { "64bit": { - "url": "https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-py310_$version-Windows-x86_64.exe#/setup.exe" + "url": "https://repo.anaconda.com/miniconda/Miniconda3-py$matchPy_$version-Windows-x86_64.exe#/setup.exe" } }, "hash": { - "url": "https://docs.conda.io/en/latest/miniconda.html", + "url": "https://docs.anaconda.com/free/miniconda/miniconda-other-installer-links/", "regex": "(?sm)$basename.*?>$sha256<" } } diff --git a/bucket/miniforge-cn.json b/bucket/miniforge-cn.json index 2c1cd3532..0992964d2 100644 --- a/bucket/miniforge-cn.json +++ b/bucket/miniforge-cn.json @@ -12,31 +12,28 @@ "pre_install": "if ($dir -match ' ') { error 'The installation directory cannot include a space'; break}", "installer": { "script": [ - "Move-Item \"$dir\\$fname\" \"$dir\\..\\$fname\"", - "Start-Process -Wait \"$dir\\..\\$fname\" -ArgumentList @('/S', '/InstallationType=JustMe', '/RegisterPython=0', '/AddToPath=0', '/NoRegistry=1', \"/D=$dir\")", - "Remove-Item \"$dir\\..\\$fname\"" + "# https://github.com/ScoopInstaller/Scoop/pull/5065", + "Import-Module $(Join-Path $(Find-BucketDirectory -Root -Name scoopet) scripts/AppsUtils.psm1)", + "Move-Item \"$dir\\$fname\" \"$dir\\..\\setup.exe\" | Out-Null", + "Invoke-ExternalCommand2 -Path \"$dir\\..\\setup.exe\" -ArgumentList @('/S', '/InstallationType=JustMe', '/RegisterPython=0', '/AddToPath=0', '/NoRegistry=1', '/NoShortcuts=1', \"/D=$dir\") | Out-Null", + "Remove-Module -Name AppsUtils" ] }, "uninstaller": { "script": [ - "Start-Process -Wait \"$dir\\Uninstall-Miniforge.exe\" -ArgumentList '/S'", - "# Workaround for 'envs' being deleted by the uninstaller. This does not affect persist.", - "New-Item \"$dir\\envs\" -ItemType Directory | Out-Null" + "Import-Module $(Join-Path $(Find-BucketDirectory -Root -Name scoopet) scripts/AppsUtils.psm1)", + "Start-Process \"$dir\\Uninstall-Miniforge3.exe\" -ArgumentList '/S' -Wait | Out-Null", + "Remove-Module -Name AppsUtils" ] }, - "bin": [ - "python.exe", - "pythonw.exe", - [ - "python.exe", - "python3" - ] - ], - "env_add_path": [ - "scripts", - "Library\\bin" + "bin": "scripts\\conda.exe", + "post_install": [ + "Remove-Item \"$dir\\..\\setup.exe\" -Force | Out-Null", + "# Set auto_activate_base to false", + "(& $dir\\scripts\\conda.exe config --system --set auto_activate_base false) | Out-Null", + "# Invoke hook for current shell session", + "(& $dir\\scripts\\conda.exe shell.powershell hook) | Out-String | Invoke-Expression" ], - "persist": "envs", "checkver": { "github": "https://github.com/conda-forge/miniforge", "regex": "tag/([\\d.-]+)" @@ -52,7 +49,14 @@ } }, "notes": [ - "From 4.6.0, conda has built the support for Cmd, Powershell or other shells.", - "Use \"conda init powershell\" or \"conda init __your_favorite_shell__\"" + "This variant does not add the default venv into your PATH unless you activate it with 'conda activate base'.", + "You may choose to install the one from the official bucket if you do not care about python PATH pollution.", + "", + "Conda base env is not persisted by Scoop, packages installed to the base env will be removed when upgrading the app.", + "We advice to setup 'envs_dirs' to use a seperated path like '~/.conda/envs' and avoid using the base env.", + "https://conda.io/projects/conda/en/latest/user-guide/configuration/use-condarc.html#specify-environment-directories-envs-dirs", + "", + "To enable conda tab-completion autoload, you can add the following code to your PowerShell $PROFILE:", + "(& conda 'shell.powershell' 'hook') | Out-String | Invoke-Expression" ] } diff --git a/scripts/AppsUtils.psm1 b/scripts/AppsUtils.psm1 index 8f714c689..95a471d23 100644 --- a/scripts/AppsUtils.psm1 +++ b/scripts/AppsUtils.psm1 @@ -1,6 +1,154 @@ #Requires -Version 5.1 Set-StrictMode -Version 3.0 +# A temp fix for https://github.com/ScoopInstaller/Scoop/pull/5066#issuecomment-1372087032 +function Invoke-ExternalCommand2 { + [CmdletBinding(DefaultParameterSetName = 'Default')] + [OutputType([Boolean])] + param ( + [Parameter(Mandatory = $true, + Position = 0)] + [Alias('Path')] + [ValidateNotNullOrEmpty()] + [String] + $FilePath, + [Parameter(Position = 1)] + [Alias('Args')] + [String[]] + $ArgumentList, + [Parameter(ParameterSetName = 'UseShellExecute')] + [Switch] + $RunAs, + [Parameter(ParameterSetName = 'UseShellExecute')] + [Switch] + $Quiet, + [Alias('Msg')] + [String] + $Activity, + [Alias('cec')] + [Hashtable] + $ContinueExitCodes, + [Parameter(ParameterSetName = 'Default')] + [Alias('Log')] + [String] + $LogPath + ) + if ($Activity) { + Write-Host "$Activity " -NoNewline + } + $Process = New-Object System.Diagnostics.Process + $Process.StartInfo.FileName = $FilePath + $Process.StartInfo.UseShellExecute = $false + $redirectToLogFile = $false + if ($LogPath) { + if ($FilePath -match '^msiexec(.exe)?$') { + $ArgumentList += "/lwe `"$LogPath`"" + } else { + $redirectToLogFile = $true + $Process.StartInfo.RedirectStandardOutput = $true + $Process.StartInfo.RedirectStandardError = $true + } + } + if ($RunAs) { + $Process.StartInfo.UseShellExecute = $true + $Process.StartInfo.Verb = 'RunAs' + } + if ($Quiet) { + $Process.StartInfo.UseShellExecute = $true + $Process.StartInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden + } + if ($ArgumentList.Length -gt 0) { + if ($FilePath -match '^((cmd|cscript|wscript|msiexec)(\.exe)?|.*\.(bat|cmd|js|vbs|wsf))$') { + $Process.StartInfo.Arguments = $ArgumentList -join ' ' + } elseif ($Process.StartInfo.PSObject.Properties.Name -contains 'ArgumentList') { + # ArgumentList is supported in PowerShell 6.1 and later (built on .NET Core 2.1+) + # ref-1: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.processstartinfo.argumentlist?view=net-6.0 + # ref-2: https://docs.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell?view=powershell-7.2#net-framework-vs-net-core + $ArgumentList | ForEach-Object { $Process.StartInfo.ArgumentList.Add($_) } + } else { + # escape arguments manually in lower versions, refer to https://docs.microsoft.com/en-us/previous-versions/17w5ykft(v=vs.85) + $escapedArgs = $ArgumentList | ForEach-Object { + # escape N consecutive backslash(es), which are followed by a double quote, to 2N consecutive ones + $s = $_ -replace '(\\+)"', '$1$1"' + # escape N consecutive backslash(es), which are at the end of the string, to 2N consecutive ones + $s = $s -replace '(\\+)$', '$1$1' + # escape double quotes + $s = $s -replace '"', '\"' + # https://github.com/ScoopInstaller/Scoop/issues/5231#issuecomment-1295840608 + $s + } + $Process.StartInfo.Arguments = $escapedArgs -join ' ' + Write-Host $Process.StartInfo.Arguments + } + } + try { + [void]$Process.Start() + } catch { + if ($Activity) { + Write-Host 'error.' -ForegroundColor DarkRed + } + Write-Host $_.Exception.Message -ForegroundColor DarkRed + return $false + } + if ($redirectToLogFile) { + # we do this to remove a deadlock potential + # ref: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.standardoutput?view=netframework-4.5#remarks + $stdoutTask = $Process.StandardOutput.ReadToEndAsync() + $stderrTask = $Process.StandardError.ReadToEndAsync() + } + $Process.WaitForExit() + if ($redirectToLogFile) { + Out-UTF8File -FilePath $LogPath -Append -InputObject $stdoutTask.Result + Out-UTF8File -FilePath $LogPath -Append -InputObject $stderrTask.Result + } + if ($Process.ExitCode -ne 0) { + if ($ContinueExitCodes -and ($ContinueExitCodes.ContainsKey($Process.ExitCode))) { + if ($Activity) { + Write-Host 'done.' -ForegroundColor DarkYellow + } + Write-Host $ContinueExitCodes[$Process.ExitCode] -ForegroundColor DarkYellow + return $true + } else { + if ($Activity) { + Write-Host 'error.' -ForegroundColor DarkRed + } + Write-Host "Exit code was $($Process.ExitCode)!" -ForegroundColor DarkRed + return $false + } + } + if ($Activity) { + Write-Host 'done.' -ForegroundColor Green + } + return $true +} + +function Out-UTF8File { + param( + [Parameter(Mandatory = $True, Position = 0)] + [Alias('Path')] + [String] $FilePath, + [Switch] $Append, + [Switch] $NoNewLine, + [Parameter(ValueFromPipeline = $True)] + [PSObject] $InputObject + ) + process { + if ($Append) { + [System.IO.File]::AppendAllText($FilePath, $InputObject) + } else { + if (!$NoNewLine) { + # Ref: https://stackoverflow.com/questions/5596982 + # Performance Note: `WriteAllLines` throttles memory usage while + # `WriteAllText` needs to keep the complete string in memory. + [System.IO.File]::WriteAllLines($FilePath, $InputObject) + } else { + # However `WriteAllText` does not add ending newline. + [System.IO.File]::WriteAllText($FilePath, $InputObject) + } + } + } +} + function Mount-ExternalRuntimeData { <# .SYNOPSIS @@ -22,11 +170,11 @@ function Mount-ExternalRuntimeData { if (Test-Path $Source) { Remove-Item $Target -Force -Recurse -ErrorAction SilentlyContinue - } - else { + } else { New-Item -ItemType Directory $Source -Force | Out-Null if (Test-Path $Target) { Get-ChildItem $Target | Move-Item -Destination $Source -Force + Remove-Item $Target } } @@ -54,4 +202,5 @@ function Dismount-ExternalRuntimeData { Export-ModuleMember ` -Function ` - Mount-ExternalRuntimeData, Dismount-ExternalRuntimeData + Mount-ExternalRuntimeData, Dismount-ExternalRuntimeData, ` + Invoke-ExternalCommand2