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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ Measurement and its related files can be maintained as a python package. The bas
- UI file for the Measurement. Types of supported UI files are:
- Measurement UI(.measui): created using the **Measurement UI Editor application**.
- LabVIEW UI(.vi)
- The path and type of this file are configured by `ui_file_path` and `ui_file_type` respectively in `measurement_info` variable definition in Measurement Python Module(.py file).
- The path of this file is configured by `ui_file_path` in `measurement_info` variable definition in Measurement Python Module(.py file).

Python communities have different ways of managing a python package and its dependencies. It is up to the measurement developer, on how they wanted to maintain the package and dependencies. Measurement developers can choose from a few common approaches discussed below based on their requirements.

Expand Down
2 changes: 0 additions & 2 deletions examples/sample_measurement/measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import ni_measurement_service as nims


measurement_info = nims.MeasurementInfo(
display_name="SampleMeasurement",
version="0.1.0.0",
Expand All @@ -20,7 +19,6 @@
ui_file_path=os.path.join(
os.path.dirname(os.path.abspath(__file__)), "SampleMeasurement.measui"
),
ui_file_type=nims.UIFileType.MeasurementUI,
)

service_info = nims.ServiceInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ measurement_info = nims.MeasurementInfo(
measurement_type="${measurement_type}",
product_type="${product_type}",
ui_file_path=os.path.join(os.path.dirname(os.path.abspath(__file__)), "${ui_file}"),
ui_file_type=nims.UIFileType.${ui_file_type},
)

service_info = nims.ServiceInfo(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%page args="display_name, service_class, service_id, description, ui_file_type"/>\
<%page args="display_name, service_class, service_id, description"/>\
\
{
"services": [
Expand All @@ -8,7 +8,6 @@
"serviceClass": "${service_class}",
"descriptionUrl": "${description}",
"providedServices": [ "ni.measurements.v1.MeasurementService" ],
"attributes": [ "UserInterfaceType=${ui_file_type}" ],
"path": "start.bat"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
measurement_type="Measurement",
product_type="Product",
ui_file_path=os.path.join(os.path.dirname(os.path.abspath(__file__)), "MeasurementUI.measui"),
ui_file_type=nims.UIFileType.MeasurementUI,
)

service_info = nims.ServiceInfo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"serviceClass": "SampleMeasurement_Python",
"descriptionUrl": "description",
"providedServices": [ "ni.measurements.v1.MeasurementService" ],
"attributes": [ "UserInterfaceType=MeasurementUI" ],
"path": "start.bat"
}
]
Expand Down
1 change: 0 additions & 1 deletion ni_measurement_service/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .measurement.info import DataType # noqa F401, declaring API
from .measurement.info import MeasurementInfo # noqa F401, declaring API
from .measurement.info import ServiceInfo # noqa F401, declaring API
from .measurement.info import UIFileType # noqa F401, declaring API
from .measurement.service import MeasurementService # noqa F401, declaring API


Expand Down
7 changes: 0 additions & 7 deletions ni_measurement_service/_internal/discovery_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@
from ni_measurement_service._internal.stubs import ServiceLocation_pb2
from ni_measurement_service.measurement.info import MeasurementInfo
from ni_measurement_service.measurement.info import ServiceInfo
from ni_measurement_service.measurement.info import UIFileType

_DISCOVERY_SERVICE_ADDRESS = "localhost:42000"
_PROVIDED_MEASUREMENT_SERVICE = "ni.measurements.v1.MeasurementService"
_MEASUREMENT_UI_ATTRIBUTE = "UserInterfaceType=MeasurementUI"
_LABVIEW_ATTRIBUTE = "UserInterfaceType=LabVIEW"

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -75,10 +72,6 @@ def register_measurement_service(
service_descriptor.name = measurement_info.display_name
service_descriptor.service_class = service_info.service_class
service_descriptor.description_url = service_info.description_url
if measurement_info.ui_file_type is UIFileType.LabVIEW:
service_descriptor.attributes.append(_LABVIEW_ATTRIBUTE)
elif measurement_info.ui_file_type is UIFileType.MeasurementUI:
service_descriptor.attributes.append(_MEASUREMENT_UI_ATTRIBUTE)

# Registration Request Creation
request = DiscoveryServices_pb2.RegisterServiceRequest(
Expand Down
3 changes: 2 additions & 1 deletion ni_measurement_service/_internal/grpc_servicer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Contains Measurement Service Implementation class and method to host the service.
"""
import inspect
import pathlib
from contextvars import ContextVar
from typing import Any, Callable, Dict, List

Expand Down Expand Up @@ -154,7 +155,7 @@ def GetMetadata(self, request, context): # noqa N802:inherited method names-aut
# User Interface details - Framed relative to the metadata python File
ui_details = Measurement_pb2.UserInterfaceDetails()

ui_details.configuration_ui_url = self.measurement_info.ui_file_path
ui_details.configuration_ui_url = pathlib.Path(self.measurement_info.ui_file_path).as_uri()

# Sending back Response
metadata_response = Measurement_pb2.GetMetadataResponse(
Expand Down
10 changes: 0 additions & 10 deletions ni_measurement_service/measurement/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
from google.protobuf import type_pb2


class UIFileType(enum.Enum):
"""Enum that represents the supported UI Types."""

MeasurementUI = "ni_measui://"
LabVIEW = "ni_vi://"


class MeasurementInfo(NamedTuple):
"""Class that represents the measurement information.

Expand All @@ -31,16 +24,13 @@ class MeasurementInfo(NamedTuple):

ui_file_path (str): Path of the UI file linked to the measurement.

ui_file_type (UIFileType): Type of the linked UI file.

"""

display_name: str
version: str
measurement_type: str
product_type: str
ui_file_path: str
Comment thread
dixonjoel marked this conversation as resolved.
ui_file_type: UIFileType


class ServiceInfo(NamedTuple):
Expand Down
19 changes: 18 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pytest-cov = "^3.0.0"
mypy = "^0.961"
types-protobuf = "^3.19.21"
typed-ast = "*"
mako = "*"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
9 changes: 7 additions & 2 deletions tests/acceptance/test_measurement_service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Tests to validate measurement service. Uses the Sample Measurement Example."""
import random
import urllib.parse
import urllib.request
from os import path

import grpc
Expand Down Expand Up @@ -132,5 +134,8 @@ def _validate_metadata_response(get_metadata_response):
assert len(get_metadata_response.measurement_parameters.outputs) == 4

assert len(get_metadata_response.user_interface_details) == 1
url = get_metadata_response.user_interface_details[0].configuration_ui_url
assert path.exists(url)
url = urllib.parse.urlparse(
get_metadata_response.user_interface_details[0].configuration_ui_url
)
localpath = urllib.request.url2pathname(url.path)
assert path.exists(localpath)
4 changes: 1 addition & 3 deletions tests/unit/test_discovery_client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Contains tests to validate the discovery_client.py.
"""
from ni_measurement_service._internal import discovery_client
from ni_measurement_service.measurement.info import ServiceInfo, MeasurementInfo, UIFileType
from ni_measurement_service.measurement.info import ServiceInfo, MeasurementInfo
from tests.utilities.fake_registry_service import (
FakeRegistryServiceStub,
FakeRegistryServiceStubError,
Expand All @@ -12,7 +12,6 @@
_TEST_SERVICE_INFO = ServiceInfo("TestServiceClass", "TestServiceID", "TestUrl")
_TEST_MEASUREMENT_INFO = MeasurementInfo(
display_name="TestMeasurement",
ui_file_type=UIFileType.LabVIEW,
version="1.0.0.0",
measurement_type="Test",
product_type="Test",
Expand Down Expand Up @@ -76,5 +75,4 @@ def _validate_grpc_request(request):
assert request.service_description.service_class == _TEST_SERVICE_INFO.service_class
assert request.service_description.description_url == _TEST_SERVICE_INFO.description_url
assert request.service_description.name == _TEST_MEASUREMENT_INFO.display_name
assert discovery_client._LABVIEW_ATTRIBUTE in request.service_description.attributes
assert discovery_client._PROVIDED_MEASUREMENT_SERVICE in request.provided_services