Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions news/fix-dep-test.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news needed.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
43 changes: 22 additions & 21 deletions requirements/packs/scripts/_pytest.bat
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
@echo off
REM Usage:
REM _pytest.bat urls.txt
REM _pytest.bat https://host/a.tar.gz https://host/b.tgz
REM From ChatGPT

setlocal EnableExtensions EnableDelayedExpansion

REM ---- temp workspace under %TEMP% ----
REM ---- temp workspace ----
set "TMPROOT=%TEMP%\remote_tests_%RANDOM%%RANDOM%"
md "%TMPROOT%" || (echo Failed to create TMPROOT & exit /b 1)

Expand All @@ -28,47 +23,49 @@ pushd "%TMPROOT%" >nul || (echo Failed to enter TMPROOT & exit /b 1)
set /a i=0
set /a overall_ec=0

REM read URL file line-by-line; hand off each line to a subroutine
for /f "usebackq delims=" %%L in ("%URLS_FILE%") do call :process_one "%%L"

popd >nul

REM -------- CLEANUP: do not poison exit code --------
rmdir /s /q "%TMPROOT%" >nul 2>&1
ver >nul REM reset errorlevel to 0

REM ---- FINAL EXIT ----
exit /b %overall_ec%

REM ===================== subroutine =====================

REM ===================================================
:process_one
setlocal EnableExtensions EnableDelayedExpansion

REM grab the raw line and trim leading spaces
set "url=%~1"
if "%url%"=="" (endlocal & goto :eof)

:trim
if not "%url:~0,1%"==" " goto :trim_done
set "url=%url:~1%"
goto trim
:trim_done

REM skip comments
if "%url:~0,1%"=="#" (endlocal & goto :eof)

REM ----- do the work for this URL -----
endlocal & set /a i+=1 & set "URL=%url%"

echo(
echo ==> [%i%]
echo ==> [%i%] %URL%

set "PKGDIR=%TMPROOT%\pkg_%i%"
md "%PKGDIR%"
md "%PKGDIR%" >nul 2>&1
pushd "%PKGDIR%" >nul || goto :after

REM download archive into PKGDIR
curl -L --fail -o "archive.tar.gz" "%URL%"
if errorlevel 1 (
echo curl failed
set /a overall_ec=1
popd >nul & goto :after
)

REM extract (try gzip flags, then plain)
tar -xzf "archive.tar.gz" >nul 2>&1
if errorlevel 1 tar -xf "archive.tar.gz" >nul 2>&1
if errorlevel 1 (
Expand All @@ -77,23 +74,21 @@ if errorlevel 1 (
popd >nul & goto :after
)

REM get first entry (try -tzf, then -tf)
set "FIRST="
for /f "delims=" %%F in ('tar -tzf "archive.tar.gz" 2^>nul') do set "FIRST=%%F" & goto got_first
for /f "delims=" %%F in ('tar -tf "archive.tar.gz" 2^>nul') do set "FIRST=%%F" & goto got_first
:got_first

REM choose project root (top dir if present)
set "PROJROOT=%CD%"
if defined FIRST for /f "tokens=1 delims=/" %%T in ("%FIRST%") do if exist ".\%%T\" set "PROJROOT=%CD%\%%T"

REM mirror original: drop src\ if present
if exist "%PROJROOT%\src\" rmdir /s /q "%PROJROOT%\src" >nul 2>&1
if exist "%PROJROOT%\src\" rmdir /s /q "%PROJROOT%\src" >nul 2>&1 & ver >nul

REM run pytest from repo root (with tests on PYTHONPATH if exists)
pushd "%PROJROOT%" >nul
echo Running pytest in: "%CD%"
echo Running pytest in "%CD%"

set "OLD_PYTHONPATH=%PYTHONPATH%"

if exist "tests\" (
if defined OLD_PYTHONPATH (
set "PYTHONPATH=%CD%;tests;%OLD_PYTHONPATH%"
Expand All @@ -107,12 +102,18 @@ if exist "tests\" (
set "PYTHONPATH=%CD%"
)
)

pytest
if errorlevel 1 set /a overall_ec=1

set "PYTHONPATH=%OLD_PYTHONPATH%"
popd >nul

popd >nul

:after
REM cleanup without poisoning errorlevel
rmdir /s /q "%PKGDIR%" >nul 2>&1
ver >nul

goto :eof
10 changes: 5 additions & 5 deletions requirements/packs/scripts/_pytest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# ./_pytest.sh urls.txt
# ./_pytest.sh https://host/a.tar.gz https://host/b.tgz
# From ChatGPT

set -euo pipefail

URLS=()
Expand All @@ -20,11 +19,12 @@ fi

START_DIR="$PWD"
TMPROOT="$(TMPDIR="$START_DIR" mktemp -d -t .tmp_remote_tests.XXXXXXXX)"
trap 'cd "$START_DIR" 2>/dev/null || true; rm -rf -- "$TMPROOT"' EXIT
trap 'cd "$START_DIR" 2>/dev/null || true; rm -rf -- "$TMPROOT" || true' EXIT
cd "$TMPROOT"

overall_ec=0
i=0

for url in "${URLS[@]}"; do
((++i))
printf '\n==> [%d] %s\n' "$i" "$url"
Expand All @@ -49,16 +49,16 @@ for url in "${URLS[@]}"; do
projroot="$pkgdir"
fi

[ -d "$projroot/src" ] && rm -rf -- "$projroot/src"
[ -d "$projroot/src" ] && rm -rf -- "$projroot/src" || true

if [ -d "$projroot/tests" ]; then
( cd "$projroot" && PYTHONPATH="$PWD:tests:${PYTHONPATH:-}" pytest ) || overall_ec=1
else
( cd "$projroot" && PYTHONPATH="$PWD:${PYTHONPATH:-}" pytest ) || overall_ec=1
fi

rm -f -- "$tarball" "$tfile"
rm -rf -- "$pkgdir"
rm -f -- "$tarball" "$tfile" || true
rm -rf -- "$pkgdir" || true
done

exit "$overall_ec"
Loading