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
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ jobs:
${{ runner.os }}-poetry-
- name: Install dependencies
run: |
sudo apt install protobuf-compiler libprotobuf-dev
poetry install
- name: Run tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ clean: ## - Clean out generated files from the workspace
o=output
plugin: ## - Execute the protoc plugin, with output write to `output` or the value passed to `-o`
mkdir -p $(o)
protoc --plugin=protoc-gen-custom=betterproto/plugin.py $(i) --custom_out=$(o)
poetry run python -m grpc.tools.protoc $(i) --python_betterproto_out=$(o)

# CI tasks

Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,6 @@ Join us on [Slack](https://join.slack.com/t/betterproto/shared_invite/zt-f0n0uol

- Python (3.6 or higher)

- [protoc](https://grpc.io/docs/protoc-installation/) (3.12 or higher)
*Needed to compile `.proto` files and run the tests*

- [poetry](https://python-poetry.org/docs/#installation)
*Needed to install dependencies in a virtual environment*

Expand Down
7 changes: 3 additions & 4 deletions betterproto/tests/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
inputs_path,
output_path_betterproto,
output_path_reference,
protoc_plugin,
protoc_reference,
protoc,
)

# Force pure-python implementation instead of C++, otherwise imports
Expand Down Expand Up @@ -88,8 +87,8 @@ async def generate_test_case_output(
(ref_out, ref_err, ref_code),
(plg_out, plg_err, plg_code),
) = await asyncio.gather(
protoc_reference(test_case_input_path, test_case_output_path_reference),
protoc_plugin(test_case_input_path, test_case_output_path_betterproto),
protoc(test_case_input_path, test_case_output_path_reference, True),
protoc(test_case_input_path, test_case_output_path_betterproto, False),
)

message = f"Generated output for {test_case_name!r}"
Expand Down
41 changes: 20 additions & 21 deletions betterproto/tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import importlib
import os
import pathlib
import sys
from pathlib import Path
from types import ModuleType
from typing import Callable, Generator, Optional
from typing import Callable, Generator, Optional, Union

os.environ["PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION"] = "python"

Expand All @@ -13,11 +14,6 @@
output_path_reference = root_path.joinpath("output_reference")
output_path_betterproto = root_path.joinpath("output_betterproto")

if os.name == "nt":
plugin_path = root_path.joinpath("..", "plugin.bat").resolve()
else:
plugin_path = root_path.joinpath("..", "plugin.py").resolve()


def get_files(path, suffix: str) -> Generator[str, None, None]:
for r, dirs, files in os.walk(path):
Expand All @@ -31,22 +27,25 @@ def get_directories(path):
yield directory


async def protoc_plugin(path: str, output_dir: str):
proc = await asyncio.create_subprocess_shell(
f"protoc --plugin=protoc-gen-custom={plugin_path} --custom_out={output_dir} --proto_path={path} {path}/*.proto",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
return (*(await proc.communicate()), proc.returncode)


async def protoc_reference(path: str, output_dir: str):
proc = await asyncio.create_subprocess_shell(
f"protoc --python_out={output_dir} --proto_path={path} {path}/*.proto",
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
async def protoc(
path: Union[str, Path], output_dir: Union[str, Path], reference: bool = False
):
path: Path = Path(path).resolve()
output_dir: Path = Path(output_dir).resolve()
python_out_option: str = "python_betterproto_out" if not reference else "python_out"
command = [
sys.executable,
"-m",
"grpc.tools.protoc",
f"--proto_path={path.as_posix()}",
f"--{python_out_option}={output_dir.as_posix()}",
*[p.as_posix() for p in path.glob("*.proto")],
]
proc = await asyncio.create_subprocess_exec(
*command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE,
)
return (*(await proc.communicate()), proc.returncode)
stdout, stderr = await proc.communicate()
return stdout, stderr, proc.returncode


def get_test_case_json_data(test_case_name: str, json_file_name: Optional[str] = None):
Expand Down
Loading