Skip to content

Commit f8c6f32

Browse files
authored
Merge pull request #94 from cadenmyers13/fix-dep-test
bug: Fix CI dependency tests
2 parents 323cb00 + 5ce0654 commit f8c6f32

File tree

3 files changed

+50
-26
lines changed

3 files changed

+50
-26
lines changed

news/fix-dep-test.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news needed.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>
Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
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-
72
setlocal EnableExtensions EnableDelayedExpansion
83

9-
REM ---- temp workspace under %TEMP% ----
4+
REM ---- temp workspace ----
105
set "TMPROOT=%TEMP%\remote_tests_%RANDOM%%RANDOM%"
116
md "%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)
2823
set /a i=0
2924
set /a overall_ec=0
3025

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

3428
popd >nul
29+
30+
REM -------- CLEANUP: do not poison exit code --------
3531
rmdir /s /q "%TMPROOT%" >nul 2>&1
32+
ver >nul REM reset errorlevel to 0
33+
34+
REM ---- FINAL EXIT ----
3635
exit /b %overall_ec%
3736

38-
REM ===================== subroutine =====================
37+
38+
REM ===================================================
3939
:process_one
4040
setlocal EnableExtensions EnableDelayedExpansion
4141

42-
REM grab the raw line and trim leading spaces
4342
set "url=%~1"
4443
if "%url%"=="" (endlocal & goto :eof)
44+
4545
:trim
4646
if not "%url:~0,1%"==" " goto :trim_done
4747
set "url=%url:~1%"
4848
goto trim
4949
:trim_done
5050

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

54-
REM ----- do the work for this URL -----
5553
endlocal & set /a i+=1 & set "URL=%url%"
54+
5655
echo(
57-
echo ==> [%i%]
56+
echo ==> [%i%] %URL%
5857

5958
set "PKGDIR=%TMPROOT%\pkg_%i%"
60-
md "%PKGDIR%"
59+
md "%PKGDIR%" >nul 2>&1
6160
pushd "%PKGDIR%" >nul || goto :after
6261

63-
REM download archive into PKGDIR
6462
curl -L --fail -o "archive.tar.gz" "%URL%"
6563
if 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)
7269
tar -xzf "archive.tar.gz" >nul 2>&1
7370
if errorlevel 1 tar -xf "archive.tar.gz" >nul 2>&1
7471
if 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)
8177
set "FIRST="
8278
for /f "delims=" %%F in ('tar -tzf "archive.tar.gz" 2^>nul') do set "FIRST=%%F" & goto got_first
8379
for /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)
8782
set "PROJROOT=%CD%"
8883
if 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)
9487
pushd "%PROJROOT%" >nul
95-
echo Running pytest in: "%CD%"
88+
echo Running pytest in "%CD%"
89+
9690
set "OLD_PYTHONPATH=%PYTHONPATH%"
91+
9792
if 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+
110106
pytest
111107
if errorlevel 1 set /a overall_ec=1
108+
112109
set "PYTHONPATH=%OLD_PYTHONPATH%"
113110
popd >nul
114111

115112
popd >nul
113+
116114
:after
115+
REM cleanup without poisoning errorlevel
117116
rmdir /s /q "%PKGDIR%" >nul 2>&1
117+
ver >nul
118+
118119
goto :eof

requirements/packs/scripts/_pytest.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# ./_pytest.sh urls.txt
44
# ./_pytest.sh https://host/a.tar.gz https://host/b.tgz
55
# From ChatGPT
6-
76
set -euo pipefail
87

98
URLS=()
@@ -20,11 +19,12 @@ fi
2019

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

2625
overall_ec=0
2726
i=0
27+
2828
for url in "${URLS[@]}"; do
2929
((++i))
3030
printf '\n==> [%d] %s\n' "$i" "$url"
@@ -49,16 +49,16 @@ for url in "${URLS[@]}"; do
4949
projroot="$pkgdir"
5050
fi
5151

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

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

60-
rm -f -- "$tarball" "$tfile"
61-
rm -rf -- "$pkgdir"
60+
rm -f -- "$tarball" "$tfile" || true
61+
rm -rf -- "$pkgdir" || true
6262
done
6363

6464
exit "$overall_ec"

0 commit comments

Comments
 (0)