diff --git a/.github/workflows/check_nimg.yml b/.github/workflows/check_nimg.yml index 7ea1aaa90..8200b35c7 100644 --- a/.github/workflows/check_nimg.yml +++ b/.github/workflows/check_nimg.yml @@ -46,3 +46,13 @@ jobs: run: poetry run mypy --platform win32 - name: Bandit security checks (ni-measurement-plugin-sdk-generator, example_renders) run: poetry run bandit -c pyproject.toml -r ni_measurement_plugin_sdk_generator tests/test_assets/example_renders + - name: Generate gRPC stubs + run: | + find tests/utilities/measurements/non_streaming_data_measurement/_stubs -name \*_pb2.py\* -o -name \*_pb2_grpc.py\* -delete + poetry run python scripts/generate_grpc_stubs.py + - name: Check for out-of-date gRPC stubs + run: git diff --exit-code + - name: Revert gRPC stubs + run: | + git clean -dfx tests/utilities/measurements/non_streaming_data_measurement/_stubs + git restore tests/utilities/measurements/non_streaming_data_measurement/_stubs diff --git a/README.md b/README.md index d9b7b07a5..bc871bcb6 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ The generated client includes four APIs: `measure`, `stream_measure`, `register_ 1. Make sure the required measurement service is running before interacting with it via the client. -2. Use the client APIs from the ["Developing a Minimal Python MeasurementClient"](#developing-a-minimal-python-measurement-client) section. +2. Use the client APIs from the ["Generating a Minimal Python Measurement Client"](#generating-a-minimal-python-measurement-client) section. 1. For non-streaming measurements, use the `measure` method. diff --git a/packages/generator/README.md b/packages/generator/README.md index e9f5f3c3a..b86cdb0b3 100644 --- a/packages/generator/README.md +++ b/packages/generator/README.md @@ -92,7 +92,7 @@ The generated client includes four APIs: `measure`, `stream_measure`, `register_ 1. Make sure the required measurement service is running before interacting with it via the client. -2. Use the client APIs from the ["Developing a Minimal Python MeasurementClient"](#developing-a-minimal-python-measurement-client) section. +2. Use the client APIs from the ["Generating a Minimal Python Measurement Client"](#generating-a-minimal-python-measurement-client) section. 1. For non-streaming measurements, use the `measure` method. diff --git a/packages/generator/ni_measurement_plugin_sdk_generator/client/__init__.py b/packages/generator/ni_measurement_plugin_sdk_generator/client/__init__.py index b1a37e2c3..4a2130e6e 100644 --- a/packages/generator/ni_measurement_plugin_sdk_generator/client/__init__.py +++ b/packages/generator/ni_measurement_plugin_sdk_generator/client/__init__.py @@ -1,7 +1,6 @@ """Utilizes command line args to create a Measurement Plug-In Client using template files.""" import pathlib -import re from enum import Enum from typing import Any, Dict, List, Optional, Type @@ -39,18 +38,12 @@ def _render_template(template_name: str, **template_args: Any) -> bytes: return template.render(**template_args) -def _replace_enum_class_type(output: str) -> str: - pattern = "" - return re.sub(pattern, r"\1", output) - - def _create_file( template_name: str, file_name: str, directory_out: pathlib.Path, **template_args: Any ) -> None: output_file = directory_out / file_name output = _render_template(template_name, **template_args).decode("utf-8") - output = _replace_enum_class_type(output) formatted_output = black.format_str( src_contents=output, mode=black.Mode(line_length=100), @@ -231,7 +224,7 @@ def _create_clients( @optgroup.option( "-s", "--measurement-service-class", - help="Creates Python Measurement Plug-In Client for the given measurement services.", + help="Creates Python Measurement Plug-In Client for the given measurement service classes.", multiple=True, ) @optgroup.option( @@ -276,9 +269,6 @@ def create_client( """Generates a Python Measurement Plug-In Client module for the measurement service. You can use the generated module to interact with the corresponding measurement service. - - MEASUREMENT_SERVICE_CLASS: Accepts one or more measurement service classes. - Provide each service class separately. """ if all: _create_all_clients(directory_out) diff --git a/packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py b/packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py index 12db3693a..a661a16f3 100644 --- a/packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py +++ b/packages/generator/ni_measurement_plugin_sdk_generator/client/_support.py @@ -2,7 +2,6 @@ import json import keyword -import os import pathlib import re import sys @@ -154,7 +153,7 @@ def get_configuration_metadata_by_index( deserialized_parameters = deserialize_parameters( configuration_metadata, metadata.measurement_signature.configuration_defaults.value, - service_class + ".Configurations", + f"{service_class}.Configurations", ) for k, v in deserialized_parameters.items(): @@ -248,10 +247,7 @@ def get_configuration_parameters_with_type_and_default_values( configuration_parameters.append(f"{parameter_name}: {parameter_type} = {default_value}") - # Use line separator and spaces to align the parameters appropriately in the generated file. - configuration_parameters_with_type_and_value = f",{os.linesep} ".join( - configuration_parameters - ) + configuration_parameters_with_type_and_value = f", ".join(configuration_parameters) parameter_names_as_str = ", ".join(parameter_names) return (configuration_parameters_with_type_and_value, parameter_names_as_str) @@ -262,9 +258,9 @@ def get_output_parameters_with_type( built_in_import_modules: List[str], custom_import_modules: List[str], enum_values_by_type: Dict[Type[Enum], Dict[str, int]] = {}, -) -> str: +) -> List[str]: """Returns the output parameters of the measurement with type.""" - output_parameters_with_type = [] + output_parameters_with_type: List[str] = [] for metadata in output_metadata.values(): parameter_name = _get_python_identifier(metadata.display_name) parameter_type = _get_python_type_as_str(metadata.type, metadata.repeated) @@ -289,7 +285,7 @@ def get_output_parameters_with_type( output_parameters_with_type.append(f"{parameter_name}: {parameter_type}") - return f"{os.linesep} ".join(output_parameters_with_type) + return output_parameters_with_type def to_ordered_set(values: Iterable[_T]) -> AbstractSet[_T]: @@ -325,7 +321,7 @@ def extract_base_service_class(service_class: str) -> str: if not base_service_class.isidentifier(): raise click.ClickException( - "Client creation failed.\nEither provide a module name or update the measurement with a valid service class." + f"Client creation failed for '{service_class}'.\nEither provide a module name or update the measurement with a valid service class." ) if not any(ch.isupper() for ch in base_service_class): print( @@ -438,4 +434,4 @@ def _get_enum_class_name(name: str) -> str: name = "".join(s.capitalize() for s in split_string) else: name = name[0].upper() + name[1:] - return name + "Enum" + return f"{name}Enum" diff --git a/packages/generator/ni_measurement_plugin_sdk_generator/client/templates/measurement_plugin_client.py.mako b/packages/generator/ni_measurement_plugin_sdk_generator/client/templates/measurement_plugin_client.py.mako index 51319c317..f93933858 100644 --- a/packages/generator/ni_measurement_plugin_sdk_generator/client/templates/measurement_plugin_client.py.mako +++ b/packages/generator/ni_measurement_plugin_sdk_generator/client/templates/measurement_plugin_client.py.mako @@ -1,5 +1,21 @@ +<%! +import re +%>\ +\ <%page args="class_name, display_name, configuration_metadata, output_metadata, service_class, configuration_parameters_with_type_and_default_values, measure_api_parameters, output_parameters_with_type, built_in_import_modules, custom_import_modules, enum_by_class_name, configuration_parameters_type_url"/>\ \ +<% + def _replace_enum_class_type(input_string: str) -> str: + """Replace enum class type representation with the enum name.""" + pattern = r"" + return re.sub(pattern, r"\1", input_string) + + configuration_metadata = _replace_enum_class_type(str(configuration_metadata)) + if output_metadata: + output_metadata = _replace_enum_class_type(str(output_metadata)) +%>\ +\ + """Generated client API for the ${display_name | repr} measurement plug-in.""" import logging @@ -11,7 +27,9 @@ from pathlib import Path <% typing_imports = ["Any", "Generator", "List", "Optional"] if output_metadata: - typing_imports += ["Iterable", "NamedTuple"] + typing_imports += ["NamedTuple"] + if "from pathlib import Path" in built_in_import_modules: + typing_imports += ["Iterable"] %>\ from typing import ${", ".join(sorted(typing_imports))} @@ -57,7 +75,9 @@ class ${enum_name.__name__}(Enum): class Outputs(NamedTuple): """Outputs for the ${display_name | repr} measurement plug-in.""" - ${output_parameters_with_type} + % for output_parameter in output_parameters_with_type: + ${output_parameter} + % endfor <% output_type = "Outputs" %>\ % endif @@ -102,7 +122,7 @@ class ${class_name}: @property def pin_map_context(self) -> PinMapContext: - """Get the pin map context for the measurement.""" + """The pin map context for the measurement.""" return self._pin_map_context @pin_map_context.setter diff --git a/packages/generator/poetry.lock b/packages/generator/poetry.lock index 74f536865..6d980dec9 100644 --- a/packages/generator/poetry.lock +++ b/packages/generator/poetry.lock @@ -432,6 +432,133 @@ files = [ [package.extras] protobuf = ["grpcio-tools (>=1.66.1)"] +[[package]] +name = "grpcio-tools" +version = "1.49.1" +description = "Protobuf code generator for gRPC" +optional = false +python-versions = ">=3.7" +files = [ + {file = "grpcio-tools-1.49.1.tar.gz", hash = "sha256:84cc64e5b46bad43d5d7bd2fd772b656eba0366961187a847e908e2cb735db91"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-linux_armv7l.whl", hash = "sha256:2dfb6c7ece84d46bd690b23d3e060d18115c8bc5047d2e8a33e6747ed323a348"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:8f452a107c054a04db2570f7851a07f060313c6e841b0d394ce6030d598290e6"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:6a198871b582287213c4d70792bf275e1d7cf34eed1d019f534ddf4cd15ab039"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a0cca67a7d0287bdc855d81fdd38dc949c4273273a74f832f9e520abe4f20bc6"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bdaff4c89eecb37c247b93025410db68114d97fa093cbb028e9bd7cda5912473"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:bb8773118ad315db317d7b22b5ff75d649ca20931733281209e7cbd8c0fad53e"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:7cc5534023735b8a8f56760b7c533918f874ce5a9064d7c5456d2709ae2b31f9"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-win32.whl", hash = "sha256:d277642acbe305f5586f9597b78fb9970d6633eb9f89c61e429c92c296c37129"}, + {file = "grpcio_tools-1.49.1-cp310-cp310-win_amd64.whl", hash = "sha256:eed599cf08fc1a06c72492d3c5750c32f58de3750eddd984af1f257c14326701"}, + {file = "grpcio_tools-1.49.1-cp311-cp311-linux_armv7l.whl", hash = "sha256:9e5c13809ab2f245398e8446c4c3b399a62d591db651e46806cccf52a700452e"}, + {file = "grpcio_tools-1.49.1-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:ab3d0ee9623720ee585fdf3753b3755d3144a4a8ae35bca8e3655fa2f41056be"}, + {file = "grpcio_tools-1.49.1-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ba87e3512bc91d78bf9febcfb522eadda171d2d4ddaf886066b0f01aa4929ad"}, + {file = "grpcio_tools-1.49.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:13e13b3643e7577a3ec13b79689eb4d7548890b1e104c04b9ed6557a3c3dd452"}, + {file = "grpcio_tools-1.49.1-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:324f67d9cb4b7058b6ce45352fb64c20cc1fa04c34d97ad44772cfe6a4ae0cf5"}, + {file = "grpcio_tools-1.49.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:a64bab81b220c50033f584f57978ebbea575f09c1ccee765cd5c462177988098"}, + {file = "grpcio_tools-1.49.1-cp311-cp311-win32.whl", hash = "sha256:f632d376f92f23e5931697a3acf1b38df7eb719774213d93c52e02acd2d529ac"}, + {file = "grpcio_tools-1.49.1-cp311-cp311-win_amd64.whl", hash = "sha256:28ff2b978d9509474928b9c096a0cce4eaa9c8f7046136aee1545f6211ed8126"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-linux_armv7l.whl", hash = "sha256:46afd3cb7e555187451a5d283f108cdef397952a662cb48680afc615b158864a"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-macosx_10_10_x86_64.whl", hash = "sha256:9284568b728e41fa8f7e9c2e7399545d605f75d8072ef0e9aa2a05655cb679eb"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:aa34442cf787732cb41f2aa6172007e24f480b8b9d3dc5166de80d63e9072ea4"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3b8c9eb5a4250905414cd53a68caea3eb8f0c515aadb689e6e81b71ebe9ab5c6"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ab15db024051bf21feb21c29cb2c3ea0a2e4f5cf341d46ef76e17fcf6aaef164"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:502084b622f758bef620a9107c2db9fcdf66d26c7e0e481d6bb87db4dc917d70"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:4085890b77c640085f82bf1e90a0ea166ce48000bc2f5180914b974783c9c0a8"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-win32.whl", hash = "sha256:da0edb984699769ce02e18e3392d54b59a7a3f93acd285a68043f5bde4fc028e"}, + {file = "grpcio_tools-1.49.1-cp37-cp37m-win_amd64.whl", hash = "sha256:9887cd622770271101a7dd1832845d64744c3f88fd11ccb2620394079197a42e"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-linux_armv7l.whl", hash = "sha256:8440fe7dae6a40c279e3a24b82793735babd38ecbb0d07bb712ff9c8963185d9"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:b5de2bb7dd6b6231da9b1556ade981513330b740e767f1d902c71ceee0a7d196"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:1e6f06a763aea7836b63d9c117347f2bf7038008ceef72758815c9e09c5fb1fc"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e31562f90120318c5395aabec0f2f69ad8c14b6676996b7730d9d2eaf9415d57"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:49ef9a4e389a618157a9daa9fafdfeeaef1ece9adda7f50f85db928f24d4b3e8"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:b384cb8e8d9bcb55ee8f9b064374561c7a1a05d848249581403d36fc7060032f"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:73732f77943ac3e898879cbb29c27253aa3c47566b8a59780fd24c6a54de1b66"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-win32.whl", hash = "sha256:b594b2745a5ba9e7a76ce561bc5ab40bc65bb44743c505529b1e4f12af29104d"}, + {file = "grpcio_tools-1.49.1-cp38-cp38-win_amd64.whl", hash = "sha256:680fbc88f8709ddcabb88f86749f2d8e429160890cff2c70680880a6970d4eef"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-linux_armv7l.whl", hash = "sha256:e8c3869121860f6767eedb7d24fc54dfd71e737fdfbb26e1334684606f3274fd"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:73e9d7c886ba10e20c97d1dab0ff961ba5800757ae5e31be21b1cda8130c52f8"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:1760de2dd2c4f08de87b039043a4797f3c17193656e7e3eb84e92f0517083c0c"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:cd4b1e216dd04d9245ee8f4e601a1f98c25e6e417ea5cf8d825c50589a8b447e"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c1c28751ab5955cae563d07677e799233f0fe1c0fc49d9cbd61ff1957e83617f"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:c24239c3ee9ed16314c14b4e24437b5079ebc344f343f33629a582f8699f583b"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:892d3dacf1942820f0b7a868a30e6fbcdf5bec08543b682c7274b0101cee632d"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-win32.whl", hash = "sha256:704d21509ec06efc9d034dbe70e7152715aac004941f4f0f553cf3a0aff15bd5"}, + {file = "grpcio_tools-1.49.1-cp39-cp39-win_amd64.whl", hash = "sha256:1efa0c221c719433f441ac0e026fc3c4dbc9a1a08a552ecdc707775e2f2fbbae"}, +] + +[package.dependencies] +grpcio = ">=1.49.1" +protobuf = ">=4.21.3,<5.0dev" +setuptools = "*" + +[[package]] +name = "grpcio-tools" +version = "1.59.0" +description = "Protobuf code generator for gRPC" +optional = false +python-versions = ">=3.7" +files = [ + {file = "grpcio-tools-1.59.0.tar.gz", hash = "sha256:aa4018f2d8662ac4d9830445d3d253a11b3e096e8afe20865547137aa1160e93"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-linux_armv7l.whl", hash = "sha256:882b809b42b5464bee55288f4e60837297f9618e53e69ae3eea6d61b05ce48fa"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-macosx_12_0_universal2.whl", hash = "sha256:4499d4bc5aa9c7b645018d8b0db4bebd663d427aabcd7bee7777046cb1bcbca7"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-manylinux_2_17_aarch64.whl", hash = "sha256:f381ae3ad6a5eb27aad8d810438937d8228977067c54e0bd456fce7e11fdbf3d"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:f1c684c0d9226d04cadafced620a46ab38c346d0780eaac7448da96bf12066a3"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:40cbf712769242c2ba237745285ef789114d7fcfe8865fc4817d87f20015e99a"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:1df755951f204e65bf9232a9cac5afe7d6b8e4c87ac084d3ecd738fdc7aa4174"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:de156c18b0c638aaee3be6ad650c8ba7dec94ed4bac26403aec3dce95ffe9407"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-win32.whl", hash = "sha256:9af7e138baa9b2895cf1f3eb718ac96fc5ae2f8e31fca405e21e0e5cd1643c52"}, + {file = "grpcio_tools-1.59.0-cp310-cp310-win_amd64.whl", hash = "sha256:f14a6e4f700dfd30ff8f0e6695f944affc16ae5a1e738666b3fae4e44b65637e"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-linux_armv7l.whl", hash = "sha256:db030140d0da2368319e2f23655df3baec278c7e0078ecbe051eaf609a69382c"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-macosx_10_10_universal2.whl", hash = "sha256:eeed386971bb8afc3ec45593df6a1154d680d87be1209ef8e782e44f85f47e64"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-manylinux_2_17_aarch64.whl", hash = "sha256:962d1a3067129152cee3e172213486cb218a6bad703836991f46f216caefcf00"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:26eb2eebf150a33ebf088e67c1acf37eb2ac4133d9bfccbaa011ad2148c08b42"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5b2d6da553980c590487f2e7fd3ec9c1ad8805ff2ec77977b92faa7e3ca14e1f"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:335e2f355a0c544a88854e2c053aff8a3f398b84a263a96fa19d063ca1fe513a"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:204e08f807b1d83f5f0efea30c4e680afe26a43dec8ba614a45fa698a7ef0a19"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-win32.whl", hash = "sha256:05bf7b3ed01c8a562bb7e840f864c58acedbd6924eb616367c0bd0a760bdf483"}, + {file = "grpcio_tools-1.59.0-cp311-cp311-win_amd64.whl", hash = "sha256:df85096fcac7cea8aa5bd84b7a39c4cdbf556b93669bb4772eb96aacd3222a4e"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-linux_armv7l.whl", hash = "sha256:240a7a3c2c54f77f1f66085a635bca72003d02f56a670e7db19aec531eda8f78"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-macosx_10_10_universal2.whl", hash = "sha256:6119f62c462d119c63227b9534210f0f13506a888151b9bf586f71e7edf5088b"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-manylinux_2_17_aarch64.whl", hash = "sha256:387662bee8e4c0b52cc0f61eaaca0ca583f5b227103f685b76083a3590a71a3e"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8f0da5861ee276ca68493b217daef358960e8527cc63c7cb292ca1c9c54939af"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d0f0806de1161c7f248e4c183633ee7a58dfe45c2b77ddf0136e2e7ad0650b1b"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:c683be38a9bf4024c223929b4cd2f0a0858c94e9dc8b36d7eaa5a48ce9323a6f"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:f965707da2b48a33128615bcfebedd215a3a30e346447e885bb3da37a143177a"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-win32.whl", hash = "sha256:2ee960904dde12a7fa48e1591a5b3eeae054bdce57bacf9fd26685a98138f5bf"}, + {file = "grpcio_tools-1.59.0-cp312-cp312-win_amd64.whl", hash = "sha256:71cc6db1d66da3bc3730d9937bddc320f7b1f1dfdff6342bcb5741515fe4110b"}, + {file = "grpcio_tools-1.59.0-cp37-cp37m-linux_armv7l.whl", hash = "sha256:f6263b85261b62471cb97b7505df72d72b8b62e5e22d8184924871a6155b4dbf"}, + {file = "grpcio_tools-1.59.0-cp37-cp37m-macosx_10_10_universal2.whl", hash = "sha256:b8e95d921cc2a1521d4750eedefec9f16031457920a6677edebe9d1b2ad6ae60"}, + {file = "grpcio_tools-1.59.0-cp37-cp37m-manylinux_2_17_aarch64.whl", hash = "sha256:cb63055739808144b541986291679d643bae58755d0eb082157c4d4c04443905"}, + {file = "grpcio_tools-1.59.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:8c4634b3589efa156a8d5860c0a2547315bd5c9e52d14c960d716fe86e0927be"}, + {file = "grpcio_tools-1.59.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:2d970aa26854f535ffb94ea098aa8b43de020d9a14682e4a15dcdaeac7801b27"}, + {file = "grpcio_tools-1.59.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:821dba464d84ebbcffd9d420302404db2fa7a40c7ff4c4c4c93726f72bfa2769"}, + {file = "grpcio_tools-1.59.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:0548e901894399886ff4a4cd808cb850b60c021feb4a8977a0751f14dd7e55d9"}, + {file = "grpcio_tools-1.59.0-cp37-cp37m-win_amd64.whl", hash = "sha256:bb87158dbbb9e5a79effe78d54837599caa16df52d8d35366e06a91723b587ae"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-linux_armv7l.whl", hash = "sha256:1d551ff42962c7c333c3da5c70d5e617a87dee581fa2e2c5ae2d5137c8886779"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-macosx_10_10_universal2.whl", hash = "sha256:4ee443abcd241a5befb05629013fbf2eac637faa94aaa3056351aded8a31c1bc"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-manylinux_2_17_aarch64.whl", hash = "sha256:520c0c83ea79d14b0679ba43e19c64ca31d30926b26ad2ca7db37cbd89c167e2"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9fc02a6e517c34dcf885ff3b57260b646551083903e3d2c780b4971ce7d4ab7c"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6aec8a4ed3808b7dfc1276fe51e3e24bec0eeaf610d395bcd42934647cf902a3"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:99b3bde646720bbfb77f263f5ba3e1a0de50632d43c38d405a0ef9c7e94373cd"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:51d9595629998d8b519126c5a610f15deb0327cd6325ed10796b47d1d292e70b"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-win32.whl", hash = "sha256:bfa4b2b7d21c5634b62e5f03462243bd705adc1a21806b5356b8ce06d902e160"}, + {file = "grpcio_tools-1.59.0-cp38-cp38-win_amd64.whl", hash = "sha256:9ed05197c5ab071e91bcef28901e97ca168c4ae94510cb67a14cb4931b94255a"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-linux_armv7l.whl", hash = "sha256:498e7be0b14385980efa681444ba481349c131fc5ec88003819f5d929646947c"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-macosx_10_10_universal2.whl", hash = "sha256:b519f2ecde9a579cad2f4a7057d5bb4e040ad17caab8b5e691ed7a13b9db0be9"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-manylinux_2_17_aarch64.whl", hash = "sha256:ef3e8aca2261f7f07436d4e2111556c1fb9bf1f9cfcdf35262743ccdee1b6ce9"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:27a7f226b741b2ebf7e2d0779d2c9b17f446d1b839d59886c1619e62cc2ae472"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:784aa52965916fec5afa1a28eeee6f0073bb43a2a1d7fedf963393898843077a"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:e312ddc2d8bec1a23306a661ad52734f984c9aad5d8f126ebb222a778d95407d"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:868892ad9e00651a38dace3e4924bae82fc4fd4df2c65d37b74381570ee8deb1"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-win32.whl", hash = "sha256:a4f6cae381f21fee1ef0a5cbbbb146680164311157ae618edf3061742d844383"}, + {file = "grpcio_tools-1.59.0-cp39-cp39-win_amd64.whl", hash = "sha256:4a10e59cca462208b489478340b52a96d64e8b8b6f1ac097f3e8cb211d3f66c0"}, +] + +[package.dependencies] +grpcio = ">=1.59.0" +protobuf = ">=4.21.6,<5.0dev" +setuptools = "*" + [[package]] name = "iniconfig" version = "2.0.0" @@ -1221,4 +1348,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = "^3.8" -content-hash = "9ec09c8fc443ebc21b8bd92a3fb7b332fad5c0de6f97f8b393a1f6829fbc4673" +content-hash = "c50ba7b473c76982bde33eee8967436278c728498cb757a43b99be014416805a" diff --git a/packages/generator/pyproject.toml b/packages/generator/pyproject.toml index 6dd8d1542..57e74baaf 100644 --- a/packages/generator/pyproject.toml +++ b/packages/generator/pyproject.toml @@ -40,6 +40,10 @@ grpc-stubs = "^1.53" ni-measurement-plugin-sdk-service = {path = "../../packages/service"} bandit = { version = ">=1.7", extras = ["toml"] } tox = ">=4.0" +grpcio-tools = [ + {version = "1.49.1", python = ">=3.8,<3.12"}, + {version = "1.59.0", python = "^3.12"}, +] [tool.poetry.scripts] ni-measurement-plugin-generator = "ni_measurement_plugin_sdk_generator.plugin:create_measurement" @@ -50,8 +54,12 @@ requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" [tool.black] +extend_exclude = '\.tox/|_pb2(_grpc)?\.(py|pyi)$' line-length = 100 +[tool.ni-python-styleguide] +extend_exclude = '.tox/,*_pb2_grpc.py,*_pb2_grpc.pyi,*_pb2.py,*_pb2.pyi' + [tool.mypy] files = "ni_measurement_plugin_sdk_generator/,tests/" exclude = "^tests/test_assets/" @@ -65,6 +73,11 @@ warn_unused_ignores = true module = "mako.*" ignore_missing_imports = true +[[tool.mypy.overrides]] +# mypy-protobuf codegen has some unused ignores. +module = "tests.utilities.measurements.non_streaming_data_measurement._stubs.*" +warn_unused_ignores = false + [tool.pytest.ini_options] addopts = "--doctest-modules --ignore tests/test_assets --strict-markers" filterwarnings = ["always::ImportWarning", "always::ResourceWarning"] @@ -74,4 +87,4 @@ testpaths = ["tests"] skips = [ "B101", # assert_used "B702", # use_of_mako_templates -] +] \ No newline at end of file diff --git a/packages/generator/scripts/generate_grpc_stubs.py b/packages/generator/scripts/generate_grpc_stubs.py new file mode 100644 index 000000000..229c07492 --- /dev/null +++ b/packages/generator/scripts/generate_grpc_stubs.py @@ -0,0 +1,88 @@ +#!/usr/bin/env python3 +"""Generates gRPC Python stubs from proto files.""" + +import pathlib +from typing import Sequence + +import grpc_tools.protoc +import pkg_resources + +STUBS_NAMESPACE = "tests.utilities.measurements.non_streaming_data_measurement._stubs" +PROTO_PARENT_NAMESPACES = ["ni.measurementlink", "nidevice_grpc", "ni.protobuf.types"] +STUBS_PATH = pathlib.Path(__file__).parent.parent / STUBS_NAMESPACE.replace(".", "/") +STUBS_PROTO_PATH = STUBS_PATH +STUBS_PROTO_FILES = list(STUBS_PROTO_PATH.rglob("*.proto")) + + +def main(): + """Generate and fixup gRPC Python stubs.""" + generate_python_files(STUBS_PATH, STUBS_PROTO_PATH, STUBS_PROTO_FILES) + fix_import_paths(STUBS_PROTO_PATH, STUBS_PATH, STUBS_NAMESPACE, PROTO_PARENT_NAMESPACES) + + +def generate_python_files( + stubs_path: pathlib.Path, + proto_path: pathlib.Path, + proto_files: Sequence[pathlib.Path], +): + """Generate python files from .proto files with protoc.""" + arguments = [ + "protoc", + f"--proto_path={str(proto_path)}", + f"--proto_path={pkg_resources.resource_filename('grpc_tools', '_proto')}", + f"--python_out={str(stubs_path)}", + f"--mypy_out={str(stubs_path)}", + f"--grpc_python_out={str(stubs_path)}", + f"--mypy_grpc_out={str(stubs_path)}", + ] + + arguments += [str(path.relative_to(proto_path)).replace("\\", "/") for path in proto_files] + + grpc_tools.protoc.main(arguments) + + +def fix_import_paths( + protos_path: pathlib.Path, + stubs_path: pathlib.Path, + stubs_namespace: str, + proto_parent_namespaces: Sequence[str], +): + """Fix import paths of generated files.""" + print("Fixing import paths") + grpc_codegened_file_paths = list(protos_path.rglob("*pb2*py")) + stubs_codegened_file_paths = list(stubs_path.rglob("*pb2*py")) + imports_to_fix = [path.stem for path in stubs_codegened_file_paths if path.parent == stubs_path] + imports_to_alias = [ + ".".join(path.relative_to(stubs_path).with_suffix("").parts) + for path in stubs_codegened_file_paths + if path.stem not in imports_to_fix + ] + grpc_codegened_file_paths.extend(protos_path.rglob("*pb2*pyi")) + for path in grpc_codegened_file_paths: + print(f"Processing {path}") + data = path.read_bytes() + for name in imports_to_fix: + data = data.replace( + f"import {name}".encode(), f"from {stubs_namespace} import {name}".encode() + ) + for namespace in proto_parent_namespaces: + data = data.replace( + f"from {namespace}".encode(), + f"from {stubs_namespace}.{namespace}".encode(), + ) + if path.suffix == ".pyi": + for name in imports_to_alias: + alias = name.replace(".", "_") + data = data.replace( + f"import {name}\n".encode(), + f"import {stubs_namespace}.{name} as {alias}\n".encode(), + ) + data = data.replace( + f"{name}.".encode(), + f"{alias}.".encode(), + ) + path.write_bytes(data) + + +if __name__ == "__main__": + main() diff --git a/packages/generator/tests/acceptance/test_non_streaming_measurement_client.py b/packages/generator/tests/acceptance/test_non_streaming_measurement_client.py index b5fc85782..5341d5864 100644 --- a/packages/generator/tests/acceptance/test_non_streaming_measurement_client.py +++ b/packages/generator/tests/acceptance/test_non_streaming_measurement_client.py @@ -21,6 +21,15 @@ class EnumInEnum(Enum): BLUE = 3 +class ProtobufEnumInEnum(Enum): + """ProtobufEnumInEnum used for enum-typed measurement configs and outputs.""" + + NONE = 0 + PINK = 1 + WHITE = 2 + BLACK = 3 + + def test___measurement_plugin_client___measure___returns_output( measurement_plugin_client_module: ModuleType, ) -> None: @@ -54,6 +63,7 @@ def test___measurement_plugin_client___measure___returns_output( xy_data_out=None, enum_out=EnumInEnum.BLUE, enum_array_out=[EnumInEnum.RED, EnumInEnum.GREEN], + protobuf_enum_out=ProtobufEnumInEnum.BLACK, ) measurement_plugin_client = test_measurement_client_type() @@ -97,6 +107,7 @@ def test___measurement_plugin_client___stream_measure___returns_output( xy_data_out=None, enum_out=EnumInEnum.BLUE, enum_array_out=[EnumInEnum.RED, EnumInEnum.GREEN], + protobuf_enum_out=ProtobufEnumInEnum.BLACK, ) measurement_plugin_client = test_measurement_client_type() diff --git a/packages/generator/tests/test_assets/example_renders/measurement_plugin_client/non_streaming_data_measurement_client.py b/packages/generator/tests/test_assets/example_renders/measurement_plugin_client/non_streaming_data_measurement_client.py index c78aed13c..244035161 100644 --- a/packages/generator/tests/test_assets/example_renders/measurement_plugin_client/non_streaming_data_measurement_client.py +++ b/packages/generator/tests/test_assets/example_renders/measurement_plugin_client/non_streaming_data_measurement_client.py @@ -40,6 +40,15 @@ class EnumInEnum(Enum): BLUE = 3 +class ProtobufEnumInEnum(Enum): + """ProtobufEnumInEnum used for enum-typed measurement configs and outputs.""" + + NONE = 0 + PINK = 1 + WHITE = 2 + BLACK = 3 + + class Outputs(NamedTuple): """Outputs for the 'Non-Streaming Data Measurement (Py)' measurement plug-in.""" @@ -56,6 +65,7 @@ class Outputs(NamedTuple): xy_data_out: DoubleXYData enum_out: EnumInEnum enum_array_out: List[EnumInEnum] + protobuf_enum_out: ProtobufEnumInEnum class NonStreamingDataMeasurementClient: @@ -236,6 +246,19 @@ def __init__( field_name="Enum_Array_In", enum_type=EnumInEnum, ), + 13: ParameterMetadata( + display_name="Protobuf Enum In", + type=14, + repeated=False, + default_value=3, + annotations={ + "ni/enum.values": '{"NONE": 0, "PINK": 1, "WHITE": 2, "BLACK": 3}', + "ni/type_specialization": "enum", + }, + message_type="", + field_name="Protobuf_Enum_In", + enum_type=ProtobufEnumInEnum, + ), } self._output_metadata = { 1: ParameterMetadata( @@ -380,6 +403,19 @@ def __init__( field_name="Enum_Array_Out", enum_type=EnumInEnum, ), + 14: ParameterMetadata( + display_name="Protobuf Enum out", + type=14, + repeated=False, + default_value=None, + annotations={ + "ni/enum.values": '{"NONE": 0, "PINK": 1, "WHITE": 2, "BLACK": 3}', + "ni/type_specialization": "enum", + }, + message_type="", + field_name="Protobuf_Enum_out", + enum_type=ProtobufEnumInEnum, + ), } if grpc_channel is not None: self._stub = v2_measurement_service_pb2_grpc.MeasurementServiceStub(grpc_channel) @@ -388,7 +424,7 @@ def __init__( @property def pin_map_context(self) -> PinMapContext: - """Get the pin map context for the measurement.""" + """The pin map context for the measurement.""" return self._pin_map_context @pin_map_context.setter @@ -520,6 +556,7 @@ def measure( integer_in: int = 10, enum_in: EnumInEnum = EnumInEnum.BLUE, enum_array_in: List[EnumInEnum] = [EnumInEnum.RED, EnumInEnum.GREEN], + protobuf_enum_in: ProtobufEnumInEnum = ProtobufEnumInEnum.BLACK, ) -> Outputs: """Perform a single measurement. @@ -539,6 +576,7 @@ def measure( integer_in, enum_in, enum_array_in, + protobuf_enum_in, ) for response in stream_measure_response: result = response @@ -572,6 +610,7 @@ def stream_measure( integer_in: int = 10, enum_in: EnumInEnum = EnumInEnum.BLUE, enum_array_in: List[EnumInEnum] = [EnumInEnum.RED, EnumInEnum.GREEN], + protobuf_enum_in: ProtobufEnumInEnum = ProtobufEnumInEnum.BLACK, ) -> Generator[Outputs, None, None]: """Perform a streaming measurement. @@ -592,6 +631,7 @@ def stream_measure( integer_in, enum_in, enum_array_in, + protobuf_enum_in, ] ) with self._initialization_lock: diff --git a/packages/generator/tests/test_assets/example_renders/measurement_plugin_client/void_measurement_client.py b/packages/generator/tests/test_assets/example_renders/measurement_plugin_client/void_measurement_client.py index 4f467b169..0e63ed440 100644 --- a/packages/generator/tests/test_assets/example_renders/measurement_plugin_client/void_measurement_client.py +++ b/packages/generator/tests/test_assets/example_renders/measurement_plugin_client/void_measurement_client.py @@ -77,7 +77,7 @@ def __init__( @property def pin_map_context(self) -> PinMapContext: - """Get the pin map context for the measurement.""" + """The pin map context for the measurement.""" return self._pin_map_context @pin_map_context.setter diff --git a/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/__init__.py b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/__init__.py index 07da2ebc8..943007092 100644 --- a/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/__init__.py +++ b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/__init__.py @@ -7,6 +7,8 @@ import ni_measurement_plugin_sdk_service as nims from ni_measurement_plugin_sdk_service._internal.stubs.ni.protobuf.types import xydata_pb2 +from tests.utilities.measurements.non_streaming_data_measurement._stubs import color_pb2 + service_directory = Path(__file__).resolve().parent measurement_service = nims.MeasurementService( @@ -66,6 +68,12 @@ class Color(Enum): @measurement_service.configuration( "Enum Array In", nims.DataType.EnumArray1D, [1, 2], enum_type=Color ) +@measurement_service.configuration( + "Protobuf Enum In", + nims.DataType.Enum, + color_pb2.ProtobufColor.BLACK, + enum_type=color_pb2.ProtobufColor, +) @measurement_service.output("Float out", nims.DataType.Float) @measurement_service.output("Double Array out", nims.DataType.DoubleArray1D) @measurement_service.output("Bool out", nims.DataType.Boolean) @@ -79,6 +87,9 @@ class Color(Enum): @measurement_service.output("XY Data Out", nims.DataType.DoubleXYData) @measurement_service.output("Enum Out", nims.DataType.Enum, enum_type=Color) @measurement_service.output("Enum Array Out", nims.DataType.EnumArray1D, enum_type=Color) +@measurement_service.output( + "Protobuf Enum out", nims.DataType.Enum, enum_type=color_pb2.ProtobufColor +) def measure( float_input: float, double_array_input: Iterable[float], @@ -92,6 +103,7 @@ def measure( integer_input: int, enum_input: Color, enum_array_input: Iterable[Color], + protobuf_enum_input: color_pb2.ProtobufColor.ValueType, ) -> Tuple[ float, Iterable[float], @@ -106,6 +118,7 @@ def measure( xydata_pb2.DoubleXYData, Color, Iterable[Color], + color_pb2.ProtobufColor.ValueType, ]: """Perform a loopback measurement with various data types.""" float_output = float_input @@ -121,6 +134,7 @@ def measure( xy_data_output = xydata_pb2.DoubleXYData() enum_output = enum_input enum_array_output = enum_array_input + protobuf_enum_output = protobuf_enum_input return ( float_output, @@ -136,4 +150,5 @@ def measure( xy_data_output, enum_output, enum_array_output, + protobuf_enum_output, ) diff --git a/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/__init__.py b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/__init__.py new file mode 100644 index 000000000..503f299d6 --- /dev/null +++ b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/__init__.py @@ -0,0 +1 @@ +"""Stubs for non_streaming_data_measurement's color enum.""" diff --git a/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color.proto b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color.proto new file mode 100644 index 000000000..32d5bdfe4 --- /dev/null +++ b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color.proto @@ -0,0 +1,17 @@ +//--------------------------------------------------------------------- +//--------------------------------------------------------------------- +syntax = "proto3"; + +//--------------------------------------------------------------------- +//--------------------------------------------------------------------- +package ni.measurementlink.measurement.non_streaming_data_measurement.v1; + +//--------------------------------------------------------------------- +//--------------------------------------------------------------------- + +enum ProtobufColor{ + NONE = 0; + PINK = 1; + WHITE = 2; + BLACK = 3; +} \ No newline at end of file diff --git a/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2.py b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2.py new file mode 100644 index 000000000..cd0f837eb --- /dev/null +++ b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: color.proto +"""Generated protocol buffer code.""" +from google.protobuf.internal import builder as _builder +from google.protobuf import descriptor as _descriptor +from google.protobuf import descriptor_pool as _descriptor_pool +from google.protobuf import symbol_database as _symbol_database +# @@protoc_insertion_point(imports) + +_sym_db = _symbol_database.Default() + + + + +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x0b\x63olor.proto\x12@ni.measurementlink.measurement.non_streaming_data_measurement.v1*9\n\rProtobufColor\x12\x08\n\x04NONE\x10\x00\x12\x08\n\x04PINK\x10\x01\x12\t\n\x05WHITE\x10\x02\x12\t\n\x05\x42LACK\x10\x03\x62\x06proto3') + +_builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) +_builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'color_pb2', globals()) +if _descriptor._USE_C_DESCRIPTORS == False: + + DESCRIPTOR._options = None + _PROTOBUFCOLOR._serialized_start=81 + _PROTOBUFCOLOR._serialized_end=138 +# @@protoc_insertion_point(module_scope) diff --git a/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2.pyi b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2.pyi new file mode 100644 index 000000000..02093e37c --- /dev/null +++ b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2.pyi @@ -0,0 +1,41 @@ +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +--------------------------------------------------------------------- +--------------------------------------------------------------------- +""" + +import builtins +import google.protobuf.descriptor +import google.protobuf.internal.enum_type_wrapper +import sys +import typing + +if sys.version_info >= (3, 10): + import typing as typing_extensions +else: + import typing_extensions + +DESCRIPTOR: google.protobuf.descriptor.FileDescriptor + +class _ProtobufColor: + ValueType = typing.NewType("ValueType", builtins.int) + V: typing_extensions.TypeAlias = ValueType + +class _ProtobufColorEnumTypeWrapper(google.protobuf.internal.enum_type_wrapper._EnumTypeWrapper[_ProtobufColor.ValueType], builtins.type): + DESCRIPTOR: google.protobuf.descriptor.EnumDescriptor + NONE: _ProtobufColor.ValueType # 0 + PINK: _ProtobufColor.ValueType # 1 + WHITE: _ProtobufColor.ValueType # 2 + BLACK: _ProtobufColor.ValueType # 3 + +class ProtobufColor(_ProtobufColor, metaclass=_ProtobufColorEnumTypeWrapper): + """--------------------------------------------------------------------- + --------------------------------------------------------------------- + """ + +NONE: ProtobufColor.ValueType # 0 +PINK: ProtobufColor.ValueType # 1 +WHITE: ProtobufColor.ValueType # 2 +BLACK: ProtobufColor.ValueType # 3 +global___ProtobufColor = ProtobufColor diff --git a/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2_grpc.py b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2_grpc.py new file mode 100644 index 000000000..2daafffeb --- /dev/null +++ b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2_grpc.py @@ -0,0 +1,4 @@ +# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! +"""Client and server classes corresponding to protobuf-defined services.""" +import grpc + diff --git a/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2_grpc.pyi b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2_grpc.pyi new file mode 100644 index 000000000..8a5eee48d --- /dev/null +++ b/packages/generator/tests/utilities/measurements/non_streaming_data_measurement/_stubs/color_pb2_grpc.pyi @@ -0,0 +1,19 @@ +""" +@generated by mypy-protobuf. Do not edit manually! +isort:skip_file +--------------------------------------------------------------------- +--------------------------------------------------------------------- +""" + +import abc +import collections.abc +import grpc +import grpc.aio +import typing + +_T = typing.TypeVar("_T") + +class _MaybeAsyncIterator(collections.abc.AsyncIterator[_T], collections.abc.Iterator[_T], metaclass=abc.ABCMeta): ... + +class _ServicerContext(grpc.ServicerContext, grpc.aio.ServicerContext): # type: ignore[misc, type-arg] + ...