11@ echo off
2- REM Usage:
3- REM _pytest.bat urls.txt
4- REM _pytest.bat https://host/a.tar.gz https://host/b.tgz
5- REM From ChatGPT
6-
72setlocal EnableExtensions EnableDelayedExpansion
83
9- REM ---- temp workspace under %TEMP% ----
4+ REM ---- temp workspace ----
105set " TMPROOT = %TEMP% \remote_tests_%RANDOM%%RANDOM% "
116md " %TMPROOT% " || (echo Failed to create TMPROOT & exit /b 1)
127
@@ -28,47 +23,49 @@ pushd "%TMPROOT%" >nul || (echo Failed to enter TMPROOT & exit /b 1)
2823set /a i = 0
2924set /a overall_ec = 0
3025
31- REM read URL file line-by-line; hand off each line to a subroutine
3226for /f " usebackq delims=" %%L in (" %URLS_FILE% " ) do call :process_one " %%L "
3327
3428popd > nul
29+
30+ REM -------- CLEANUP: do not poison exit code --------
3531rmdir /s /q " %TMPROOT% " > nul 2 >& 1
32+ ver > nul REM reset errorlevel to 0
33+
34+ REM ---- FINAL EXIT ----
3635exit /b %overall_ec%
3736
38- REM ===================== subroutine =====================
37+
38+ REM ===================================================
3939:process_one
4040setlocal EnableExtensions EnableDelayedExpansion
4141
42- REM grab the raw line and trim leading spaces
4342set " url = %~1 "
4443if " %url% " == " " (endlocal & goto :eof)
44+
4545:trim
4646if not " %url:~0 ,1 % " == " " goto :trim_done
4747set " url = %url:~1 % "
4848goto trim
4949:trim_done
5050
51- REM skip comments
5251if " %url:~0 ,1 % " == " #" (endlocal & goto :eof)
5352
54- REM ----- do the work for this URL -----
5553endlocal & set /a i += 1 & set " URL = %url% "
54+
5655echo(
57- echo ==> [%i% ]
56+ echo ==> [%i% ] %URL%
5857
5958set " PKGDIR = %TMPROOT% \pkg_%i% "
60- md " %PKGDIR% "
59+ md " %PKGDIR% " > nul 2 >& 1
6160pushd " %PKGDIR% " > nul || goto :after
6261
63- REM download archive into PKGDIR
6462curl -L --fail -o " archive.tar.gz" " %URL% "
6563if errorlevel 1 (
6664 echo curl failed
6765 set /a overall_ec = 1
6866 popd > nul & goto :after
6967)
7068
71- REM extract (try gzip flags, then plain)
7269tar -xzf " archive.tar.gz" > nul 2 >& 1
7370if errorlevel 1 tar -xf " archive.tar.gz" > nul 2 >& 1
7471if errorlevel 1 (
@@ -77,23 +74,21 @@ if errorlevel 1 (
7774 popd > nul & goto :after
7875)
7976
80- REM get first entry (try -tzf, then -tf)
8177set " FIRST = "
8278for /f " delims=" %%F in ('tar -tzf " archive.tar.gz" 2^ > nul ') do set " FIRST = %%F " & goto got_first
8379for /f " delims=" %%F in ('tar -tf " archive.tar.gz" 2^ > nul ') do set " FIRST = %%F " & goto got_first
8480:got_first
8581
86- REM choose project root (top dir if present)
8782set " PROJROOT = %CD% "
8883if defined FIRST for /f " tokens=1 delims=/" %%T in (" %FIRST% " ) do if exist " .\%%T \" set " PROJROOT = %CD% \%%T "
8984
90- REM mirror original: drop src\ if present
91- if exist " %PROJROOT% \src\" rmdir /s /q " %PROJROOT% \src" > nul 2 >& 1
85+ if exist " %PROJROOT% \src\" rmdir /s /q " %PROJROOT% \src" > nul 2 >& 1 & ver > nul
9286
93- REM run pytest from repo root (with tests on PYTHONPATH if exists)
9487pushd " %PROJROOT% " > nul
95- echo Running pytest in: " %CD% "
88+ echo Running pytest in " %CD% "
89+
9690set " OLD_PYTHONPATH = %PYTHONPATH% "
91+
9792if exist " tests\" (
9893 if defined OLD_PYTHONPATH (
9994 set " PYTHONPATH = %CD% ;tests;%OLD_PYTHONPATH% "
@@ -107,12 +102,18 @@ if exist "tests\" (
107102 set " PYTHONPATH = %CD% "
108103 )
109104)
105+
110106pytest
111107if errorlevel 1 set /a overall_ec = 1
108+
112109set " PYTHONPATH = %OLD_PYTHONPATH% "
113110popd > nul
114111
115112popd > nul
113+
116114:after
115+ REM cleanup without poisoning errorlevel
117116rmdir /s /q " %PKGDIR% " > nul 2 >& 1
117+ ver > nul
118+
118119goto :eof
0 commit comments