Sync from upstream: ncp.ps1 works under PowerShell on Linux

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
jon
2026-07-22 11:41:03 -05:00
co-authored by Claude Opus 4.8
parent 9e639100cf
commit 98006f395a
2 changed files with 41 additions and 14 deletions
+27 -14
View File
@@ -1,10 +1,11 @@
# ncp - Windows entry point. The CLI itself is management\ncp.py, the same file
# the Linux box runs; this only picks an interpreter and forwards the arguments.
# ncp - PowerShell entry point. The CLI itself is management/ncp.py, the same
# file the Linux shell wrapper runs; this only picks an interpreter and forwards
# the arguments.
#
# Register it once per machine by adding this to your PowerShell profile
# (notepad $PROFILE):
# Windows: install-windows.ps1 registers this automatically. To do it by hand,
# or to get ncp inside PowerShell on Linux, add to $PROFILE.CurrentUserAllHosts:
#
# function ncp { & "$HOME\nexus-core\management\ncp.ps1" @args }
# function ncp { & "<repo>/management/ncp.ps1" @args }
#
# ASCII only, no exceptions: PowerShell 5.1 decodes BOM-less files as ANSI, so a
# single Unicode dash eats a quote and the script dies at parse time. A test in
@@ -12,17 +13,29 @@
$Root = Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Path)
# Prefer the venv interpreter (ncp.py needs psutil for service management), but
# fall back to system Python so backup/restore still work before the venv is
# built - those delegate to the stdlib-only bin\sync.py.
$Py = Join-Path $Root "Promethean\Scripts\python.exe"
if (-not (Test-Path $Py)) {
$Py = (Get-Command python -ErrorAction SilentlyContinue).Source
# Forward slashes and per-platform venv layout: backslash is a literal character
# on Linux, not a separator, so "Promethean\Scripts\python.exe" would resolve to
# a single nonsense filename under pwsh on Linux. Windows accepts "/" happily.
# $env:OS is the 5.1-safe check; the automatic $IsWindows only exists on PS 6+.
$OnWindows = ($env:OS -eq "Windows_NT")
if ($OnWindows) {
$Py = Join-Path $Root "Promethean/Scripts/python.exe"
} else {
$Py = Join-Path $Root "Promethean/bin/python3"
}
if (-not $Py) {
Write-Error "No Python found. Run install-windows.ps1 first."
# Fall back to a system Python so backup/restore still work before the venv is
# built - those delegate to the stdlib-only bin/sync.py.
if (-not (Test-Path $Py)) {
foreach ($candidate in @("python3", "python")) {
$found = Get-Command $candidate -ErrorAction SilentlyContinue
if ($found) { $Py = $found.Source; break }
}
}
if (-not (Test-Path $Py)) {
Write-Error "No Python found. Run install.sh (Linux) or install-windows.ps1 first."
exit 1
}
& $Py (Join-Path $Root "management\ncp.py") @args
& $Py (Join-Path $Root "management/ncp.py") @args
exit $LASTEXITCODE