Skip to content

Commit

Permalink
Merge pull request #3 from zerlok/dev
Browse files Browse the repository at this point in the history
fix protoc plugin run
  • Loading branch information
zerlok authored Aug 23, 2024
2 parents fbbe628 + 0b744f6 commit b186e57
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pyprotostuben"
version = "0.1.0"
version = "0.1.1"
description = ""
authors = ["zerlok <[email protected]>"]
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion src/pyprotostuben/codegen/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ def run(self, request: CodeGeneratorRequest) -> CodeGeneratorResponse:

class ProtoFileGenerator(metaclass=abc.ABCMeta):
@abc.abstractmethod
def run(self, file: ProtoFile) -> t.Iterable[t.Tuple[ProtoFile, Path, str]]:
def run(self, file: ProtoFile) -> t.Sequence[t.Tuple[ProtoFile, Path, str]]:
raise NotImplementedError
12 changes: 10 additions & 2 deletions src/pyprotostuben/codegen/module_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path

from pyprotostuben.codegen.abc import ProtoFileGenerator
from pyprotostuben.logging import LoggerMixin
from pyprotostuben.logging import Logger, LoggerMixin
from pyprotostuben.protobuf.file import ProtoFile
from pyprotostuben.protobuf.visitor.abc import visit
from pyprotostuben.protobuf.visitor.decorator import ProtoVisitorDecorator
Expand All @@ -21,7 +21,7 @@ class ModuleASTBasedProtoFileGenerator(ProtoFileGenerator, LoggerMixin):
def __init__(self, factory: ModuleASTProtoVisitorDecoratorFactory) -> None:
self.__factory = factory

def run(self, file: ProtoFile) -> t.Iterable[t.Tuple[ProtoFile, Path, str]]:
def run(self, file: ProtoFile) -> t.Sequence[t.Tuple[ProtoFile, Path, str]]:
log = self._log.bind_details(file_name=file.name)
log.debug("file received")

Expand All @@ -33,6 +33,14 @@ def run(self, file: ProtoFile) -> t.Iterable[t.Tuple[ProtoFile, Path, str]]:
visit(DFSWalkingProtoVisitor(generator), file.descriptor)
log.debug("proto visited", modules=modules)

return list(self.__gen_modules(file, modules, log))

def __gen_modules(
self,
file: ProtoFile,
modules: t.Mapping[Path, ast.Module],
log: Logger,
) -> t.Iterable[t.Tuple[ProtoFile, Path, str]]:
for path, module_ast in modules.items():
if not module_ast.body:
continue
Expand Down
8 changes: 6 additions & 2 deletions src/pyprotostuben/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from logging.config import dictConfig
from pathlib import Path

from typing_extensions import Self
if t.TYPE_CHECKING:
from typing_extensions import Self

else:
Self = t.Any


class Logger(
Expand Down Expand Up @@ -39,7 +43,7 @@ def configure(cls) -> None:
},
},
"root": {
"level": os.getenv("LOGGING_LEVEL", "INFO").strip().upper(),
"level": os.getenv("LOGGING_LEVEL", "WARNING").strip().upper(),
"handlers": ["stderr"],
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/pyprotostuben/protobuf/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def build(cls, request: CodeGeneratorRequest) -> CodeGeneratorContext:
return CodeGeneratorContext(
request=request,
params=parser.parse(request.parameter),
files=[files[file.name] for file in request.proto_file],
files=[files[name] for name in request.file_to_generate],
registry=TypeRegistry(infos, map_entries),
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import builtins
import google.protobuf.message
import google.protobuf.timestamp_pb2
import message1_pb2
import message2_pb2
import message3_pb2
import typing

class MessageImport(google.protobuf.message.Message):

def __init__(self, *, m1: message1_pb2.Message1, m2: message2_pb2.Message2, m3: message3_pb2.Message3) -> None:...
def __init__(self, *, m1: message1_pb2.Message1, m2: message2_pb2.Message2, m3: message3_pb2.Message3, ts: google.protobuf.timestamp_pb2.Timestamp) -> None:...

@builtins.property
def m1(self) -> message1_pb2.Message1:...
Expand All @@ -18,6 +19,9 @@ class MessageImport(google.protobuf.message.Message):
@builtins.property
def m3(self) -> message3_pb2.Message3:...

@builtins.property
def ts(self) -> google.protobuf.timestamp_pb2.Timestamp:...

def HasField(self, field_name: typing.NoReturn) -> typing.NoReturn:...

def WhichOneof(self, oneof_group: typing.NoReturn) -> typing.NoReturn:...
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package message_import;
import "message1.proto";
import "message2.proto";
import "message3.proto";
import "google/protobuf/timestamp.proto";

message MessageImport {
message_import.Message1 m1 = 1;
message_import.Message2 m2 = 2;
message3.Message3 m3 = 3;
google.protobuf.Timestamp ts = 4;
}

0 comments on commit b186e57

Please sign in to comment.