Skip to content

Commit fe47d4a

Browse files
authored
Add empty Python protobuf generation tool (#5)
* Bootstrapped with "poetry new --src grpc_generator" * Set minimum Python version to 3.11 * Use a namespaced name for the package
1 parent d8f134c commit fe47d4a

9 files changed

Lines changed: 950 additions & 0 deletions

File tree

tools/grpc_generator/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# About
2+
3+
`grpc_generator` is a Python tool that generates gRPC stubs from proto files.
4+
5+
It supports emitting stubs into namespace packages, transforming them as necessary from submodules to subpackages.

tools/grpc_generator/poetry.lock

Lines changed: 834 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/grpc_generator/poetry.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[virtualenvs]
2+
in-project = true
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[tool.poetry]
2+
name = "ni-apis-grpc-generator"
3+
version = "0.1.0"
4+
license = "MIT"
5+
description = "Python generator for NI gRPC APIs"
6+
authors = ["NI <opensource@ni.com>"]
7+
readme = "README.md"
8+
packages = [{include = "grpc_generator", from = "src"}]
9+
10+
[tool.poetry.scripts]
11+
grpc-generator = "grpc_generator.__main__:cli"
12+
13+
[tool.poetry.dependencies]
14+
python = "^3.11"
15+
click = "^8.2.1"
16+
17+
[tool.poetry.group.lint.dependencies]
18+
bandit = { version = ">=1.7", extras = ["toml"] }
19+
ni-python-styleguide = ">=0.4.1"
20+
mypy = ">=1.0"
21+
pyright = { version = ">=1.1.400", extras = ["nodejs"] }
22+
23+
[tool.poetry.group.test.dependencies]
24+
pytest = ">=7.2"
25+
pytest-cov = ">=4.0"
26+
pytest-mock = ">=3.0"
27+
28+
[build-system]
29+
requires = ["poetry-core>=1.8"]
30+
build-backend = "poetry.core.masonry.api"
31+
32+
33+
[tool.bandit]
34+
skips = [
35+
"B101", # assert_used
36+
]
37+
38+
[tool.black]
39+
line-length = 100
40+
41+
[tool.mypy]
42+
files = "src/,tests/"
43+
namespace_packages = true
44+
strict = true
45+
46+
[tool.pyright]
47+
include = ["src/", "tests/"]
48+
49+
[tool.pytest.ini_options]
50+
addopts = "--strict-markers"
51+
testpaths = ["tests"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""grpc_generator package."""
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""grpc_generator entry points."""
2+
3+
import logging
4+
5+
import click
6+
7+
from . import generator
8+
9+
10+
_logger = logging.getLogger(__name__)
11+
_logger.addHandler(logging.NullHandler())
12+
13+
14+
@click.command()
15+
@click.help_option()
16+
def cli() -> None:
17+
"""Generate gRPC Python stubs from proto files."""
18+
generator.handle_cli()
19+
20+
21+
if __name__ == "__main__":
22+
cli()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""Generate gRPC Python stubs from proto files."""
2+
3+
import logging
4+
5+
import click
6+
7+
8+
_logger = logging.getLogger(__name__)
9+
_logger.addHandler(logging.NullHandler())
10+
11+
12+
def handle_cli() -> None:
13+
"""Handle the command line interface invocation."""
14+
color_world = {
15+
"W": "red",
16+
"o": "yellow",
17+
"r": "green",
18+
"l": "blue",
19+
"d": "magenta",
20+
}
21+
message = "".join([click.style(text, color) for text, color in color_world.items()])
22+
click.echo(f"Hello {message}!")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Tests for grpc_generator."""
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""Tests for the command line interface."""
2+
3+
from click.testing import CliRunner
4+
5+
from grpc_generator import __main__
6+
7+
8+
def test_console() -> None:
9+
"""Does it invoke the base command group?"""
10+
runner = CliRunner()
11+
result = runner.invoke(__main__.cli)
12+
assert result.exit_code == 0

0 commit comments

Comments
 (0)