aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpnv1 <pnv1@yandex-team.com>2024-09-30 16:19:32 +0300
committerpnv1 <pnv1@yandex-team.com>2024-09-30 16:31:03 +0300
commit334072c7351043236bdca34f2ede8ed1cb4a6d79 (patch)
tree227f6b426c7d19bee913d344df6515cdf48129ac
parentd4f5e798223ea2abf44ad38eab5673e1ee4654b0 (diff)
downloadydb-334072c7351043236bdca34f2ede8ed1cb4a6d79.tar.gz
Add ya.bat to ydb repo to use ya without python prefix
Add ya.bat to ydb repo commit_hash:a4a0d193c84235eb67e9cb3997af18ae5e107cd8
-rwxr-xr-xya.bat90
1 files changed, 90 insertions, 0 deletions
diff --git a/ya.bat b/ya.bat
new file mode 100755
index 0000000000..dc571c2c12
--- /dev/null
+++ b/ya.bat
@@ -0,0 +1,90 @@
+@echo off
+rem Ya Simple Windows launcher
+setlocal
+call :dbg Ya Simple Windows Launcher (Debug)
+call :find_ya
+if ERRORLEVEL 1 exit /b 1
+call :dbg Ya: %YA_BAT_REAL%
+call :fix_env
+call :find_python
+if ERRORLEVEL 1 exit /b 1
+call :dbg Python: "%YA_BAT_PYTHON%"
+call "%YA_BAT_PYTHON%" %YA_PY_KNOB% "%YA_BAT_REAL%" %*
+exit /b %ERRORLEVEL%
+
+:find_ya
+call :dbg Searching for ya near ya.bat...
+set YA_BAT_REAL=%~dp0ya
+if exist "%YA_BAT_REAL%" exit /b 0
+call :err Ya not found
+exit /b 1
+
+:fix_env
+call :dbg Fixing environment...
+for /f "delims=: tokens=2" %%F in ('chcp') do (
+ if "%%F" == " 65001" (
+ call :dbg -- Forcing I/O encoding for python: utf-8
+ set PYTHONIOENCODING=utf-8
+ set PYTHONUTF8=1
+ )
+)
+exit /b 0
+
+:find_python
+call :dbg Searching for python in PATH...
+for /f "delims=" %%F in ('where python 2^>nul') do (
+ call :test_python %%~sF
+ if not ERRORLEVEL 1 (
+ set YA_BAT_PYTHON=%%F
+ if /I "%%F" == "C:\Windows\py.exe" (
+ set YA_PY_KNOB=-3
+ )
+ exit /b 0
+ )
+)
+call :dbg Searching for python in ftypes...
+for /f delims^=^=^"^ tokens^=2 %%F in ('ftype Python.File 2^>nul') do (
+ call :test_python %%F
+ if not ERRORLEVEL 1 (
+ set YA_BAT_PYTHON=%%F
+ if /I "%%F" == "C:\Windows\py.exe" (
+ set YA_PY_KNOB=-3
+ )
+ exit /b 0
+ )
+)
+call :dbg Searching for python with Get-Command...
+for /f "delims=" %%i in ('powershell -Command "Get-Command python | Select-Object -ExpandProperty Source"') do (
+ call :test_python %%i
+ if not ERRORLEVEL 1 (
+ set YA_BAT_PYTHON=%%i
+ exit /b 0
+ )
+)
+call :err Python not found
+exit /b 1
+
+:test_python
+call :dbg -- Checking python: %1
+if not exist %1 (
+ call :dbg ---- Not found
+ exit /b 1
+)
+for /f %%P in ('%1 -c "import os, sys; sys.stdout.write(os.name + '\n')" 2^>nul') do set YA_BAT_PYTHON_PLATFORM=%%P
+if not defined YA_BAT_PYTHON_PLATFORM (
+ call :dbg ---- Not runnable
+ exit /b 2
+)
+if not "%YA_BAT_PYTHON_PLATFORM%"=="nt" (
+ call :dbg ---- Non-windows: %YA_BAT_PYTHON_PLATFORM%
+ exit /b 3
+)
+exit /b 0
+
+:dbg
+if defined YA_BAT_DEBUG echo [ya.bat] %* 1>&2
+exit /b 0
+
+:err
+echo [ya.bat] Error: %* 1>&2
+exit /b 0