k
This commit is contained in:
@@ -302,6 +302,11 @@ def main() -> int:
|
||||
# This prevents issues when bootstrap.py is run from different directories
|
||||
script_dir = Path(__file__).resolve().parent
|
||||
repo_root = script_dir.parent
|
||||
|
||||
if not args.quiet:
|
||||
print(f"Bootstrap script location: {script_dir}")
|
||||
print(f"Detected project root: {repo_root}")
|
||||
print(f"Current working directory: {Path.cwd()}")
|
||||
|
||||
# Helpers for interactive menu and uninstall detection
|
||||
def _venv_python_path(p: Path) -> Path | None:
|
||||
@@ -554,6 +559,14 @@ def main() -> int:
|
||||
|
||||
# Opinionated: always create or use a local venv at the project root (.venv)
|
||||
venv_dir = repo_root / ".venv"
|
||||
|
||||
# Validate that venv_dir is where we expect it to be
|
||||
if not args.quiet:
|
||||
print(f"Planned venv location: {venv_dir}")
|
||||
if venv_dir.parent != repo_root:
|
||||
print(f"WARNING: venv parent is {venv_dir.parent}, expected {repo_root}", file=sys.stderr)
|
||||
if "scripts" in str(venv_dir).lower():
|
||||
print(f"WARNING: venv path contains 'scripts': {venv_dir}", file=sys.stderr)
|
||||
|
||||
def _venv_python(p: Path) -> Path:
|
||||
if platform.system().lower() == "windows":
|
||||
@@ -834,22 +847,25 @@ if (Test-Path (Join-Path $repo 'CLI.py')) {
|
||||
user_bin = Path(os.environ.get("USERPROFILE", str(home))) / "bin"
|
||||
user_bin.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Convert repo path to string with proper escaping
|
||||
repo_str = str(repo).replace("\\", "\\\\")
|
||||
|
||||
# Write mm.ps1 (PowerShell shim)
|
||||
mm_ps1 = user_bin / "mm.ps1"
|
||||
ps1_text = (
|
||||
"Param([Parameter(ValueFromRemainingArguments=$true)] $args)\n"
|
||||
f'$repo = "{repo}"\n'
|
||||
f'$repo = "{repo_str}"\n'
|
||||
"$venv = Join-Path $repo '.venv'\n"
|
||||
"$py = Join-Path $venv 'Scripts\\python.exe'\n"
|
||||
"if (Test-Path $py) {\n"
|
||||
" if ($env:MM_DEBUG) {\n"
|
||||
' Write-Host "MM_DEBUG: using venv python at $py" -ForegroundColor Yellow\n'
|
||||
" & $py -c \"import sys; print('sys.executable:', sys.executable)\"\n"
|
||||
" & $py -c \"import sys; print('sys.executable:', sys.executable); print('sys.path:', sys.path[:5])\"\n"
|
||||
" }\n"
|
||||
" & $py -m scripts.cli_entry @args; exit $LASTEXITCODE\n"
|
||||
"}\n"
|
||||
"# Fallback to system python if venv doesn't exist\n"
|
||||
"if ($env:MM_DEBUG) { Write-Host 'MM_DEBUG: venv python not found, trying system python' -ForegroundColor Yellow }\n"
|
||||
"if ($env:MM_DEBUG) { Write-Host 'MM_DEBUG: venv python not found at' $py ', trying system python' -ForegroundColor Yellow }\n"
|
||||
"python -m scripts.cli_entry @args\n"
|
||||
)
|
||||
if mm_ps1.exists():
|
||||
@@ -859,21 +875,22 @@ if (Test-Path (Join-Path $repo 'CLI.py')) {
|
||||
|
||||
# Write mm.bat (CMD shim for better compatibility)
|
||||
mm_bat = user_bin / "mm.bat"
|
||||
repo_bat_str = str(repo)
|
||||
bat_text = (
|
||||
"@echo off\n"
|
||||
"setlocal enabledelayedexpansion\n"
|
||||
f'set "REPO={repo}"\n'
|
||||
f'set "REPO={repo_bat_str}"\n'
|
||||
"set \"VENV=!REPO!\\.venv\"\n"
|
||||
"set \"PY=!VENV!\\Scripts\\python.exe\"\n"
|
||||
"if exist \"!PY!\" (\n"
|
||||
" if defined MM_DEBUG (\n"
|
||||
" echo MM_DEBUG: using venv python at !PY!\n"
|
||||
" \"!PY!\" -c \"import sys; print('sys.executable:', sys.executable)\"\n"
|
||||
" \"!PY!\" -c \"import sys; print('sys.executable:', sys.executable); print('sys.path:', sys.path[:5])\"\n"
|
||||
" )\n"
|
||||
" \"!PY!\" -m scripts.cli_entry %*\n"
|
||||
" exit /b !ERRORLEVEL!\n"
|
||||
")\n"
|
||||
"echo MM: venv not found at !VENV!, trying system python\n"
|
||||
"echo MM: venv python not found at !PY!\n"
|
||||
"if defined MM_DEBUG echo MM_DEBUG: venv python not found, trying system python\n"
|
||||
"python -m scripts.cli_entry %*\n"
|
||||
"exit /b !ERRORLEVEL!\n"
|
||||
|
||||
Reference in New Issue
Block a user