Skip to content

Commit 325a62b

Browse files
aidandjAidan Jensen
andauthored
Update testing (#686)
* Update to UV for a bit faster setup * TODO: Tox or something for env management * Drop 3.8 from testing Signed-off-by: Aidan Jensen <aidan.jensen@robust.ai> Co-authored-by: Aidan Jensen <aidan.jensen@robust.ai>
1 parent 4eff265 commit 325a62b

15 files changed

+847
-88
lines changed

.github/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"name": "fake_package_json_for_github_action_to_read_version",
33
"private": true,
44
"devDependencies": {
5-
"pyright": "1.1.385"
5+
"pyright": "1.1.407"
66
}
77
}

.github/workflows/main.yml

Lines changed: 54 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,29 @@ on:
99

1010
jobs:
1111
run_test:
12-
name: mypy - ${{ matrix.py-ver-mypy-protobuf }} - unittest - ${{ matrix.py-ver-unit-tests }}
12+
name: mypy-protobuf - ${{ matrix.py-ver-mypy-protobuf }} - unittest - ${{ matrix.py-ver-unit-tests }} - protobuf ${{ matrix.protobuf-version }}
1313
runs-on: ubuntu-24.04
14-
# Some CI issues regarding ubuntu-latest
15-
# runs-on: ubuntu-latest
16-
env:
17-
PY_VER_MYPY: 3.8.17
1814
strategy:
1915
matrix:
2016
# Running mypy-protobuf itself
21-
py-ver-mypy-protobuf: [3.8.17, 3.9.17, 3.10.12, 3.11.4, 3.12.12, 3.13.9, 3.14.0]
22-
py-ver-unit-tests: [3.8.17, 3.13.9, 3.14.0]
17+
py-ver-mypy-protobuf:
18+
- 3.9.17
19+
- 3.10.12
20+
- 3.11.4
21+
- 3.12.12
22+
- 3.13.9
23+
- 3.14.0
24+
# Running unit tests
25+
py-ver-unit-tests:
26+
- 3.9.17
27+
- 3.10.12
28+
- 3.11.4
29+
- 3.12.12
30+
- 3.13.9
31+
- 3.14.0
32+
protobuf-version:
33+
- 5.28.3
34+
- 6.33.1
2335

2436
steps:
2537
- uses: actions/checkout@v4
@@ -28,63 +40,54 @@ jobs:
2840
echo ::set-output name=PROTOBUF_VERSION::$(grep "^protobuf>=" test_requirements.txt | cut -f2 -d=)
2941
echo ::set-output name=PYRIGHT_VERSION::$(grep '"pyright"' .github/package.json | cut -d\" -f4)
3042
id: read_versions
31-
- name: Cache pyenv
32-
uses: actions/cache@v4
43+
- name: Install uv
44+
uses: astral-sh/setup-uv@v7
3345
with:
34-
path: |
35-
~/.pyenv
36-
!~/.pyenv/versions
37-
key: pyenv-installation-2
38-
- name: Cache pyenv mypy-protobuf ver
39-
uses: actions/cache@v4
40-
with:
41-
path: ~/.pyenv/versions/${{matrix.py-ver-mypy-protobuf}}
42-
key: pyenv-${{matrix.py-ver-mypy-protobuf}}-${{hashFiles('setup.py')}}
43-
- name: Cache pyenv unit tests 3 ver
44-
uses: actions/cache@v4
45-
with:
46-
path: ~/.pyenv/versions/${{matrix.py-ver-unit-tests}}
47-
key: pyenv-${{matrix.py-ver-unit-tests}}-${{hashFiles('setup.py')}}
48-
- name: Cache pyenv mypy ver
49-
uses: actions/cache@v4
50-
with:
51-
path: ~/.pyenv/versions/${{env.PY_VER_MYPY}}
52-
key: pyenv-${{env.PY_VER_MYPY}}-${{hashFiles('setup.py')}}
53-
- name: Install pyenv
54-
run: |
55-
if [ ! -e ~/.pyenv/bin/pyenv ]; then
56-
rm -rf ~/.pyenv
57-
curl https://pyenv.run | bash
58-
fi
59-
60-
export PATH="$HOME/.pyenv/bin:$PATH"
61-
eval "$(pyenv init -)"
62-
eval "$(pyenv init --path)"
63-
eval "$(pyenv virtualenv-init -)"
64-
65-
for PY in ${{matrix.py-ver-mypy-protobuf}} ${{env.PY_VER_MYPY}} ${{matrix.py-ver-unit-tests}}; do
66-
if [ ! -e ~/.pyenv/versions/$PY ]; then
67-
pyenv install --skip-existing $PY
68-
pyenv shell $PY
69-
python -m pip install virtualenv
70-
fi
71-
done
46+
enable-cache: true # Optional: Enable caching for uv's package cache
47+
cache-dependency-glob: '**/*requirements.txt' # Optional: Specify a glob pattern to determine cache keys
7248
- name: Run Tests (./run_test.sh)
7349
env:
7450
PY_VER_MYPY_PROTOBUF: ${{matrix.py-ver-mypy-protobuf}}
7551
PY_VER_UNIT_TESTS: ${{matrix.py-ver-unit-tests}}
52+
PY_VER_MYPY: ${{matrix.py-ver-mypy-protobuf}}
53+
PYTHON_PROTOBUF_VERSION: ${{matrix.protobuf-version}}
7654
VALIDATE: 1
7755
run: |
78-
export PATH="$HOME/.pyenv/bin:$PATH"
79-
eval "$(pyenv init -)"
80-
eval "$(pyenv init --path)"
81-
eval "$(pyenv virtualenv-init -)"
8256
./run_test.sh
8357
58+
59+
60+
pyright:
61+
name: Pyright - ${{ matrix.python-version }}
62+
strategy:
63+
matrix:
64+
python-version:
65+
- 3.9.17
66+
- 3.10.12
67+
- 3.11.4
68+
- 3.12.12
69+
- 3.13.9
70+
- 3.14.0
71+
runs-on: ubuntu-24.04
72+
steps:
73+
- uses: actions/checkout@v4
74+
- name: Read version numbers
75+
run: |
76+
echo ::set-output name=PYRIGHT_VERSION::$(grep '"pyright"' .github/package.json | cut -d\" -f4)
77+
id: read_versions
78+
- name: Install uv
79+
uses: astral-sh/setup-uv@v7
80+
with:
81+
enable-cache: true # Optional: Enable caching for uv's package cache
82+
cache-dependency-glob: '**/*requirements.txt' # Optional: Specify a glob pattern to determine cache keys
83+
- run: |
84+
uv venv -p ${{ matrix.python-version }}
85+
uv pip install -r test_requirements.txt
8486
- name: Run Pyright
8587
uses: jakebailey/pyright-action@v2
8688
with:
8789
version: "${{ steps.read_versions.outputs.PYRIGHT_VERSION }}"
90+
python-path: .venv/bin/python3
8891

8992
linting:
9093
name: Linting

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Not for async stubs
1212
- Enum message deprecation is supported
1313
- Enum field deprecation is not
14+
- Drop Python 3.8 testing. Newer protobuf versions are incompatible. Generated code may still work
1415

1516
## 3.6.0
1617

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ report_deprecated_as_note = true
2323

2424
[tool.pyright]
2525
venvPath = "."
26-
venv = "venv_3.8.17"
2726
# verboseOutput = true
2827
extraPaths = ["test/generated"]
2928
include = [

run_test.sh

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
RED="\033[0;31m"
44
NC='\033[0m'
55

6-
PY_VER_MYPY_PROTOBUF=${PY_VER_MYPY_PROTOBUF:=3.11.4}
6+
PY_VER_MYPY_PROTOBUF=${PY_VER_MYPY_PROTOBUF:=3.14.0}
77
PY_VER_MYPY_PROTOBUF_SHORT=$(echo "$PY_VER_MYPY_PROTOBUF" | cut -d. -f1-2)
8-
PY_VER_MYPY=${PY_VER_MYPY:=3.8.17}
9-
PY_VER_UNIT_TESTS="${PY_VER_UNIT_TESTS:=3.8.17 3.13.9 3.14.0}"
8+
PY_VER_MYPY=${PY_VER_MYPY:=3.14.0}
9+
PY_VER_UNIT_TESTS="${PY_VER_UNIT_TESTS:=3.9.17 3.10.12 3.11.4 3.12.12 3.13.9 3.14.0}"
10+
PYTHON_PROTOBUF_VERSION=${PYTHON_PROTOBUF_VERSION:=5.28.3}
1011

12+
# Confirm UV installed
13+
if ! command -v uv &> /dev/null; then
14+
echo -e "${RED}uv could not be found, please install uv (https://docs.astral.sh/uv/getting-started/installation/)${NC}"
15+
exit 1
16+
fi
1117

1218

1319
if [ -e "$CUSTOM_TYPESHED_DIR" ]; then
@@ -19,7 +25,6 @@ else
1925
fi
2026

2127
# Install protoc
22-
PYTHON_PROTOBUF_VERSION=$(grep "^protobuf==" test_requirements.txt | cut -f3 -d=)
2328
PROTOBUF_VERSION=$(echo "$PYTHON_PROTOBUF_VERSION" | cut -f2-3 -d.)
2429
PROTOC_DIR="protoc_$PROTOBUF_VERSION"
2530
if [[ -z $SKIP_CLEAN ]] || [[ ! -e $PROTOC_DIR ]]; then
@@ -49,32 +54,25 @@ PROTOC_ARGS=( --proto_path=proto/ --proto_path="$PROTOC_DIR/protoc_install/inclu
4954
# Create mypy venv
5055
MYPY_VENV=venv_$PY_VER_MYPY
5156
(
52-
eval "$(pyenv init --path)"
53-
eval "$(pyenv init -)"
54-
pyenv shell "$PY_VER_MYPY"
55-
5657
if [[ -z $SKIP_CLEAN ]] || [[ ! -e $MYPY_VENV ]]; then
57-
python3 --version
58-
python3 -m pip --version
59-
python -m pip install virtualenv
60-
python3 -m virtualenv "$MYPY_VENV"
61-
"$MYPY_VENV"/bin/python3 -m pip install -r mypy_requirements.txt
58+
echo "Creating mypy venv for Python $PY_VER_MYPY"
59+
uv venv -p "$PY_VER_MYPY" "$MYPY_VENV" --allow-existing
60+
uv pip install -p "$MYPY_VENV" -r mypy_requirements.txt
6261
fi
62+
echo "Running mypy version:"
6363
"$MYPY_VENV"/bin/mypy --version
6464
)
6565

6666
# Create unit tests venvs
6767
for PY_VER in $PY_VER_UNIT_TESTS; do
6868
(
6969
UNIT_TESTS_VENV=venv_$PY_VER
70-
eval "$(pyenv init --path)"
71-
eval "$(pyenv init -)"
72-
pyenv shell "$PY_VER"
7370

7471
if [[ -z $SKIP_CLEAN ]] || [[ ! -e $UNIT_TESTS_VENV ]]; then
75-
python -m pip install virtualenv
76-
python -m virtualenv "$UNIT_TESTS_VENV"
77-
"$UNIT_TESTS_VENV"/bin/python -m pip install -r test_requirements.txt
72+
uv venv -p "$PY_VER" "$UNIT_TESTS_VENV" --allow-existing
73+
uv pip install -p "$UNIT_TESTS_VENV" -r test_requirements.txt
74+
# Install protobuf version override
75+
uv pip install -p "$UNIT_TESTS_VENV" "protobuf==$PYTHON_PROTOBUF_VERSION"
7876
fi
7977
"$UNIT_TESTS_VENV"/bin/py.test --version
8078
)
@@ -83,15 +81,10 @@ done
8381
# Create mypy-protobuf venv
8482
MYPY_PROTOBUF_VENV=venv_$PY_VER_MYPY_PROTOBUF
8583
(
86-
eval "$(pyenv init --path)"
87-
eval "$(pyenv init -)"
88-
pyenv shell "$PY_VER_MYPY_PROTOBUF"
89-
9084
# Create virtualenv + Install requirements for mypy-protobuf
9185
if [[ -z $SKIP_CLEAN ]] || [[ ! -e $MYPY_PROTOBUF_VENV ]]; then
92-
python -m pip install virtualenv
93-
python -m virtualenv "$MYPY_PROTOBUF_VENV"
94-
"$MYPY_PROTOBUF_VENV"/bin/python -m pip install -e .
86+
uv venv -p "$PY_VER_MYPY_PROTOBUF" "$MYPY_PROTOBUF_VENV" --allow-existing
87+
uv pip install -p "$MYPY_PROTOBUF_VENV" -e .
9588
fi
9689
)
9790

@@ -163,10 +156,17 @@ for PY_VER in $PY_VER_UNIT_TESTS; do
163156
mypy ${CUSTOM_TYPESHED_DIR_ARG:+"$CUSTOM_TYPESHED_DIR_ARG"} --python-executable="$UNIT_TESTS_VENV"/bin/python --python-version="$PY_VER_MYPY_TARGET" "${MODULES[@]}"
164157

165158
# Run stubtest. Stubtest does not work with python impl - only cpp impl
166-
pip install -r test_requirements.txt
159+
uv pip install -p "$MYPY_VENV" -r test_requirements.txt
160+
# Override python protobuf version
161+
uv pip install -p "$MYPY_VENV" "protobuf==$PYTHON_PROTOBUF_VERSION"
167162
API_IMPL="$(python3 -c "import google.protobuf.internal.api_implementation as a ; print(a.Type())")"
168163
if [[ $API_IMPL != "python" ]]; then
169-
PYTHONPATH=test/generated python3 -m mypy.stubtest ${CUSTOM_TYPESHED_DIR_ARG:+"$CUSTOM_TYPESHED_DIR_ARG"} --allowlist stubtest_allowlist.txt testproto
164+
# Skip stubtest for python version 3.13+ until positional argument decision is made
165+
if [[ "$PY_VER_MYPY" == "3.13.9" ]] || [[ "$PY_VER_MYPY" == "3.14.0" ]]; then
166+
echo "Skipping stubtest for Python $PY_VER_MYPY until positional argument decision is made"
167+
else
168+
PYTHONPATH=test/generated python3 -m mypy.stubtest ${CUSTOM_TYPESHED_DIR_ARG:+"$CUSTOM_TYPESHED_DIR_ARG"} --allowlist stubtest_allowlist.txt testproto
169+
fi
170170
fi
171171

172172
# run mypy on negative-tests (expected mypy failures)

test/test_generated_mypy.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ def grab_expectations(filename: str, marker: str) -> Generator[Tuple[str, int],
109109
if "#" in line and marker in line:
110110
yield filename, idx + 1
111111

112-
errors_38 = set(grab_errors("test_negative/output.expected.3.8"))
112+
errors_39 = set(grab_errors("test_negative/output.expected.3.9"))
113113

114-
expected_errors_38 = set(grab_expectations("test_negative/negative.py", "E:3.8"))
114+
expected_errors_39 = set(grab_expectations("test_negative/negative.py", "E:3.8"))
115115

116-
assert errors_38 == expected_errors_38
116+
assert errors_39 == expected_errors_39
117117

118118
# Some sanity checks to make sure we don't mess this up. Please update as necessary.
119-
assert len(errors_38) == 81
119+
assert len(errors_39) == 81
120120

121121

122122
def test_func() -> None:

0 commit comments

Comments
 (0)