Skip to content

Commit d422c9e

Browse files
committed
Add Windows support
1 parent a955ec6 commit d422c9e

3 files changed

Lines changed: 72 additions & 10 deletions

File tree

justfile

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,11 @@ _coverage-py html='':
5151

5252
[private]
5353
_coverage-py-pylib html='':
54-
mkdir -p out/coverage/python-pylib
55-
PYTHONPATH=out/pylib ANKI_TEST_MODE=1 out/pyenv/bin/python -m coverage run --source=pylib/anki --data-file=out/coverage/python-pylib/.coverage -m pytest -p no:cacheprovider pylib/tests
56-
out/pyenv/bin/python -m coverage json --data-file=out/coverage/python-pylib/.coverage -o out/coverage/python-pylib/coverage-summary.json
57-
out/pyenv/bin/python -m coverage report --data-file=out/coverage/python-pylib/.coverage --fail-under=65
58-
{{ if html == "--html" { "out/pyenv/bin/python -m coverage html --data-file=out/coverage/python-pylib/.coverage -d out/coverage/python-pylib/html --fail-under=65 && echo 'Python pylib coverage report: out/coverage/python-pylib/html/index.html'" } else { "true" } }}
54+
{{ if os_family() == "windows" { "tools\\coverage-py" } else { "tools/coverage-py" } }} pylib {{ html }}
5955

6056
[private]
6157
_coverage-py-qt html='':
62-
mkdir -p out/coverage/python-qt
63-
PYTHONPATH=pylib:out/pylib:out/qt ANKI_TEST_MODE=1 out/pyenv/bin/python -m coverage run --source=qt/aqt --data-file=out/coverage/python-qt/.coverage -m pytest -p no:cacheprovider qt/tests
64-
out/pyenv/bin/python -m coverage json --data-file=out/coverage/python-qt/.coverage -o out/coverage/python-qt/coverage-summary.json
65-
out/pyenv/bin/python -m coverage report --data-file=out/coverage/python-qt/.coverage --fail-under=20
66-
{{ if html == "--html" { "out/pyenv/bin/python -m coverage html --data-file=out/coverage/python-qt/.coverage -d out/coverage/python-qt/html --fail-under=20 && echo 'Python qt coverage report: out/coverage/python-qt/html/index.html'" } else { "true" } }}
58+
{{ if os_family() == "windows" { "tools\\coverage-py" } else { "tools/coverage-py" } }} qt {{ html }}
6759

6860
# Check formatting (fast, no build needed)
6961
fmt:

tools/coverage-py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
target="$1"
6+
html="$2"
7+
8+
case "$target" in
9+
pylib)
10+
pythonpath="out/pylib"
11+
source="pylib/anki"
12+
outdir="out/coverage/python-pylib"
13+
tests="pylib/tests"
14+
threshold=65
15+
;;
16+
qt)
17+
pythonpath="pylib:out/pylib:out/qt"
18+
source="qt/aqt"
19+
outdir="out/coverage/python-qt"
20+
tests="qt/tests"
21+
threshold=20
22+
;;
23+
*)
24+
echo "Usage: $0 [pylib|qt] [--html]"
25+
exit 1
26+
;;
27+
esac
28+
29+
mkdir -p "$outdir"
30+
PYTHONPATH="$pythonpath" ANKI_TEST_MODE=1 out/pyenv/bin/python -m coverage run \
31+
--source="$source" --data-file="$outdir/.coverage" \
32+
-m pytest -p no:cacheprovider "$tests"
33+
out/pyenv/bin/python -m coverage json \
34+
--data-file="$outdir/.coverage" -o "$outdir/coverage-summary.json"
35+
out/pyenv/bin/python -m coverage report \
36+
--data-file="$outdir/.coverage" --fail-under="$threshold"
37+
if [ "$html" = "--html" ]; then
38+
out/pyenv/bin/python -m coverage html \
39+
--data-file="$outdir/.coverage" -d "$outdir/html" --fail-under="$threshold"
40+
echo "Python $target coverage report: $outdir/html/index.html"
41+
fi

tools/coverage-py.bat

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
@echo off
2+
setlocal
3+
4+
if "%1"=="pylib" (
5+
set "PYTHONPATH=out/pylib"
6+
set "source=pylib/anki"
7+
set "outdir=out\coverage\python-pylib"
8+
set "tests=pylib/tests"
9+
set "threshold=65"
10+
) else if "%1"=="qt" (
11+
set "PYTHONPATH=pylib;out/pylib;out/qt"
12+
set "source=qt/aqt"
13+
set "outdir=out\coverage\python-qt"
14+
set "tests=qt/tests"
15+
set "threshold=20"
16+
) else (
17+
echo Usage: %0 [pylib^|qt] [--html]
18+
exit /b 1
19+
)
20+
21+
set "ANKI_TEST_MODE=1"
22+
if not exist %outdir% mkdir %outdir%
23+
out\pyenv\Scripts\python -m coverage run --source=%source% --data-file=%outdir%\.coverage -m pytest -p no:cacheprovider %tests% || exit /b 1
24+
out\pyenv\Scripts\python -m coverage json --data-file=%outdir%\.coverage -o %outdir%\coverage-summary.json || exit /b 1
25+
out\pyenv\Scripts\python -m coverage report --data-file=%outdir%\.coverage --fail-under=%threshold% || exit /b 1
26+
if "%2"=="--html" (
27+
out\pyenv\Scripts\python -m coverage html --data-file=%outdir%\.coverage -d %outdir%\html --fail-under=%threshold% || exit /b 1
28+
echo Python %1 coverage report: %outdir%\html\index.html
29+
)

0 commit comments

Comments
 (0)