Skip to content
Open
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
14 changes: 9 additions & 5 deletions protogen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,11 +1279,12 @@ def __init__(
self,
proto: google.protobuf.descriptor_pb2.FileDescriptorProto,
generate: bool,
py_import_func: Callable[[str, str], PyImportPath],
py_import_func: Callable[[str, str, Dict[str, str]], PyImportPath],
parameters: Dict[str, str]
):
self.proto = proto
self.generated_filename_prefix = proto.name[: -len(".proto")]
self.py_import_path = py_import_func(proto.name, proto.package)
self.py_import_path = py_import_func(proto.name, proto.package, parameters)
self.py_package_name = str(proto.package)
self.generate = generate
self.dependencies: List[File] = []
Expand Down Expand Up @@ -1660,7 +1661,7 @@ def error(self, msg: str):
self._error = msg


def default_py_import_func(filename: str, package: str) -> PyImportPath:
def default_py_import_func(filename: str, package: str, parameters: Dict[str, str]) -> PyImportPath:
"""Return the Python import path for a file.

Return the Python import path for a file following the behaviour of the
Expand All @@ -1675,6 +1676,9 @@ def default_py_import_func(filename: str, package: str) -> PyImportPath:
Filename of the proto file to request the import path for.
package : str
Proto package name of the file to request the import path for.
parameters: Dict[str, str]
Parameters passed to the plugin using ``{plugin name}_opt=<key>=<value>`
or ``<plugin>_out=<key>=<value>`` command line flags.

Returns
-------
Expand Down Expand Up @@ -1703,7 +1707,7 @@ class Options:
def __init__(
self,
*,
py_import_func: Callable[[str, str], PyImportPath] = default_py_import_func,
py_import_func: Callable[[str, str, Dict[str, str]], PyImportPath] = default_py_import_func,
input: Optional[BinaryIO] = None,
output: Optional[BinaryIO] = None,
supported_features: List[
Expand Down Expand Up @@ -1807,7 +1811,7 @@ def run(self, f: Callable[[Plugin], None]):
files_to_generate: List[File] = []
for proto in req.proto_file:
generate = proto.name in req.file_to_generate
file = File(proto, generate, self._py_import_func)
file = File(proto, generate, self._py_import_func, parameter)
file._register(registry)
file._resolve(registry)
if generate:
Expand Down