From 0492b82b77b72fe6308463b683576970d8dcb7c4 Mon Sep 17 00:00:00 2001 From: Mitchell Hentges Date: Fri, 21 Jan 2022 18:22:58 +0000 Subject: [PATCH] Bug 1750874: Support launching Mach with `py` instead of `python` r=glandium When installing from Python.org, the `python` command isn't available by default (in favour of `py`). Support using `py` instead. There were issues running `hg` when `python` isn't added to the `PATH`, so the docs are being updated accordingly. Of course, it's still worth supporting `py`-instead-of-`python` workflows for `git` users who won't be impacted by that bug. Differential Revision: https://phabricator.services.mozilla.com/D136286 --- mach.cmd | 8 +++++++- mach.ps1 | 12 ++++++++++-- .../mach/docs/windows-usage-outside-mozillabuild.rst | 3 ++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/mach.cmd b/mach.cmd index 1d439effe3b0..7c7c6f74ae8f 100644 --- a/mach.cmd +++ b/mach.cmd @@ -1,3 +1,9 @@ @ECHO OFF SET topsrcdir=%~dp0 -python %topsrcdir%mach %* + +WHERE /q py +IF %ERRORLEVEL% EQU 0 ( + py %topsrcdir%mach %* +) ELSE ( + python %topsrcdir%mach %* +) diff --git a/mach.ps1 b/mach.ps1 index deec8a18322d..9fec76dc2b9a 100644 --- a/mach.ps1 +++ b/mach.ps1 @@ -1,8 +1,14 @@ $mypath = $MyInvocation.MyCommand.Path -$machpath = ($mypath -replace '\\', '/').substring(0, $mypath.length - 4) +$machpath = $mypath.substring(0, $mypath.length - 4) + +if (Get-Command py) { + $python_executable = "py" +} else { + $python_executable = "python" +} if (-not (test-path env:MACH_PS1_USE_MOZILLABUILD)) { - python $machpath $args + &$python_executable $machpath $args exit $lastexitcode } @@ -11,6 +17,8 @@ if (-not (test-path env:MOZILLABUILD)) { exit 1 } +$machpath = ($machpath -replace '\\', '/') + if ($machpath.contains(' ')) { echo @' The repository path contains whitespace which currently isn't supported in mach.ps1. diff --git a/python/mach/docs/windows-usage-outside-mozillabuild.rst b/python/mach/docs/windows-usage-outside-mozillabuild.rst index 5dfa860aec67..95d941a1d257 100644 --- a/python/mach/docs/windows-usage-outside-mozillabuild.rst +++ b/python/mach/docs/windows-usage-outside-mozillabuild.rst @@ -55,7 +55,8 @@ Download Python from the `the official website `__. .. note::