Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 2070825

Browse files
committed
Simplify test compilation
1 parent 541484b commit 2070825

File tree

2 files changed

+18
-50
lines changed

2 files changed

+18
-50
lines changed

tests/generate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ async def generate_test_case_output(test_case_input_path: Path, test_case_name:
6464

6565
clear_directory(test_case_output_path_reference)
6666
clear_directory(test_case_output_path_betterproto)
67+
clear_directory(test_case_output_path_betterproto_pyd)
6768

6869
(
6970
(ref_out, ref_err, ref_code),

tests/util.py

Lines changed: 17 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import asyncio
2-
import atexit
32
import os
4-
import platform
53
import sys
6-
import tempfile
74
from collections.abc import Generator
85
from pathlib import Path
96

@@ -30,53 +27,23 @@ def get_directories(path):
3027
async def protoc(path: str | Path, output_dir: str | Path, reference: bool = False, pydantic_dataclasses: bool = False):
3128
path: Path = Path(path).resolve()
3229
output_dir: Path = Path(output_dir).resolve()
33-
python_out_option: str = "python_betterproto2_out" if not reference else "python_out"
34-
35-
if pydantic_dataclasses:
36-
plugin_path = Path("src/betterproto2_compiler/plugin/main.py")
37-
38-
if "Win" in platform.system():
39-
with tempfile.NamedTemporaryFile("w", encoding="UTF-8", suffix=".bat", delete=False) as tf:
40-
# See https://stackoverflow.com/a/42622705
41-
tf.writelines(
42-
[
43-
"@echo off",
44-
f"\nchdir {os.getcwd()}",
45-
f"\n{sys.executable} -u {plugin_path.as_posix()}",
46-
],
47-
)
48-
49-
tf.flush()
50-
51-
plugin_path = Path(tf.name)
52-
atexit.register(os.remove, plugin_path)
53-
54-
command = [
55-
sys.executable,
56-
"-m",
57-
"grpc.tools.protoc",
58-
f"--plugin=protoc-gen-custom={plugin_path.as_posix()}",
59-
"--experimental_allow_proto3_optional",
60-
"--custom_opt=pydantic_dataclasses",
61-
"--custom_opt=client_generation=async_sync",
62-
"--custom_opt=server_generation=async",
63-
f"--proto_path={path.as_posix()}",
64-
f"--custom_out={output_dir.as_posix()}",
65-
*[p.as_posix() for p in path.glob("*.proto")],
66-
]
67-
else:
68-
command = [
69-
sys.executable,
70-
"-m",
71-
"grpc.tools.protoc",
72-
f"--proto_path={path.as_posix()}",
73-
f"--{python_out_option}={output_dir.as_posix()}",
74-
*[p.as_posix() for p in path.glob("*.proto")],
75-
]
76-
77-
if not reference:
78-
command.insert(3, "--python_betterproto2_opt=server_generation=async")
79-
command.insert(3, "--python_betterproto2_opt=client_generation=async_sync")
30+
python_out_option: str = "python_out" if reference else "python_betterproto2_out"
31+
32+
command = [
33+
sys.executable,
34+
"-m",
35+
"grpc.tools.protoc",
36+
f"--proto_path={path.as_posix()}",
37+
f"--{python_out_option}={output_dir.as_posix()}",
38+
*[p.as_posix() for p in path.glob("*.proto")],
39+
]
40+
41+
if not reference:
42+
command.insert(3, "--python_betterproto2_opt=server_generation=async")
43+
command.insert(3, "--python_betterproto2_opt=client_generation=async_sync")
44+
45+
if pydantic_dataclasses:
46+
command.insert(3, "--python_betterproto2_opt=pydantic_dataclasses")
8047

8148
proc = await asyncio.create_subprocess_exec(
8249
*command,

0 commit comments

Comments
 (0)