Skip to content

Commit c77fa40

Browse files
authored
Remove ui-file-type and attributes (#101)
* Remove ui-file-type and attributes * Fix lint errors * Remove 'respectively' for one thing * Make the configuration_ui_url into an actual file url * Fix lint errors * Fix path so it works on Windows and Linux (hopefully)
1 parent 46c803b commit c77fa40

File tree

14 files changed

+31
-33
lines changed

14 files changed

+31
-33
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ Measurement and its related files can be maintained as a python package. The bas
248248
- UI file for the Measurement. Types of supported UI files are:
249249
- Measurement UI(.measui): created using the **Measurement UI Editor application**.
250250
- LabVIEW UI(.vi)
251-
- 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).
251+
- The path of this file is configured by `ui_file_path` in `measurement_info` variable definition in Measurement Python Module(.py file).
252252

253253
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.
254254

examples/sample_measurement/measurement.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
import ni_measurement_service as nims
1313

14-
1514
measurement_info = nims.MeasurementInfo(
1615
display_name="SampleMeasurement",
1716
version="0.1.0.0",
@@ -20,7 +19,6 @@
2019
ui_file_path=os.path.join(
2120
os.path.dirname(os.path.abspath(__file__)), "SampleMeasurement.measui"
2221
),
23-
ui_file_type=nims.UIFileType.MeasurementUI,
2422
)
2523

2624
service_info = nims.ServiceInfo(

ni_measurement_generator/ni_measurement_generator/templates/measurement.py.mako

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ measurement_info = nims.MeasurementInfo(
1414
measurement_type="${measurement_type}",
1515
product_type="${product_type}",
1616
ui_file_path=os.path.join(os.path.dirname(os.path.abspath(__file__)), "${ui_file}"),
17-
ui_file_type=nims.UIFileType.${ui_file_type},
1817
)
1918

2019
service_info = nims.ServiceInfo(

ni_measurement_generator/ni_measurement_generator/templates/measurement.serviceconfig.mako

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%page args="display_name, service_class, service_id, description, ui_file_type"/>\
1+
<%page args="display_name, service_class, service_id, description"/>\
22
\
33
{
44
"services": [
@@ -8,7 +8,6 @@
88
"serviceClass": "${service_class}",
99
"descriptionUrl": "${description}",
1010
"providedServices": [ "ni.measurements.v1.MeasurementService" ],
11-
"attributes": [ "UserInterfaceType=${ui_file_type}" ],
1211
"path": "start.bat"
1312
}
1413
]

ni_measurement_generator/tests/test_assets/example_renders/example.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
measurement_type="Measurement",
1313
product_type="Product",
1414
ui_file_path=os.path.join(os.path.dirname(os.path.abspath(__file__)), "MeasurementUI.measui"),
15-
ui_file_type=nims.UIFileType.MeasurementUI,
1615
)
1716

1817
service_info = nims.ServiceInfo(

ni_measurement_generator/tests/test_assets/example_renders/example.serviceconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"serviceClass": "SampleMeasurement_Python",
77
"descriptionUrl": "description",
88
"providedServices": [ "ni.measurements.v1.MeasurementService" ],
9-
"attributes": [ "UserInterfaceType=MeasurementUI" ],
109
"path": "start.bat"
1110
}
1211
]

ni_measurement_service/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from .measurement.info import DataType # noqa F401, declaring API
55
from .measurement.info import MeasurementInfo # noqa F401, declaring API
66
from .measurement.info import ServiceInfo # noqa F401, declaring API
7-
from .measurement.info import UIFileType # noqa F401, declaring API
87
from .measurement.service import MeasurementService # noqa F401, declaring API
98

109

ni_measurement_service/_internal/discovery_client.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
from ni_measurement_service._internal.stubs import ServiceLocation_pb2
1010
from ni_measurement_service.measurement.info import MeasurementInfo
1111
from ni_measurement_service.measurement.info import ServiceInfo
12-
from ni_measurement_service.measurement.info import UIFileType
1312

1413
_DISCOVERY_SERVICE_ADDRESS = "localhost:42000"
1514
_PROVIDED_MEASUREMENT_SERVICE = "ni.measurements.v1.MeasurementService"
16-
_MEASUREMENT_UI_ATTRIBUTE = "UserInterfaceType=MeasurementUI"
17-
_LABVIEW_ATTRIBUTE = "UserInterfaceType=LabVIEW"
1815

1916
_logger = logging.getLogger(__name__)
2017

@@ -75,10 +72,6 @@ def register_measurement_service(
7572
service_descriptor.name = measurement_info.display_name
7673
service_descriptor.service_class = service_info.service_class
7774
service_descriptor.description_url = service_info.description_url
78-
if measurement_info.ui_file_type is UIFileType.LabVIEW:
79-
service_descriptor.attributes.append(_LABVIEW_ATTRIBUTE)
80-
elif measurement_info.ui_file_type is UIFileType.MeasurementUI:
81-
service_descriptor.attributes.append(_MEASUREMENT_UI_ATTRIBUTE)
8275

8376
# Registration Request Creation
8477
request = DiscoveryServices_pb2.RegisterServiceRequest(

ni_measurement_service/_internal/grpc_servicer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Contains Measurement Service Implementation class and method to host the service.
22
"""
33
import inspect
4+
import pathlib
45
from contextvars import ContextVar
56
from typing import Any, Callable, Dict, List
67

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

157-
ui_details.configuration_ui_url = self.measurement_info.ui_file_path
158+
ui_details.configuration_ui_url = pathlib.Path(self.measurement_info.ui_file_path).as_uri()
158159

159160
# Sending back Response
160161
metadata_response = Measurement_pb2.GetMetadataResponse(

ni_measurement_service/measurement/info.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
from google.protobuf import type_pb2
77

88

9-
class UIFileType(enum.Enum):
10-
"""Enum that represents the supported UI Types."""
11-
12-
MeasurementUI = "ni_measui://"
13-
LabVIEW = "ni_vi://"
14-
15-
169
class MeasurementInfo(NamedTuple):
1710
"""Class that represents the measurement information.
1811
@@ -31,16 +24,13 @@ class MeasurementInfo(NamedTuple):
3124
3225
ui_file_path (str): Path of the UI file linked to the measurement.
3326
34-
ui_file_type (UIFileType): Type of the linked UI file.
35-
3627
"""
3728

3829
display_name: str
3930
version: str
4031
measurement_type: str
4132
product_type: str
4233
ui_file_path: str
43-
ui_file_type: UIFileType
4434

4535

4636
class ServiceInfo(NamedTuple):

poetry.lock

Lines changed: 18 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pytest-cov = "^3.0.0"
4040
mypy = "^0.961"
4141
types-protobuf = "^3.19.21"
4242
typed-ast = "*"
43+
mako = "*"
4344

4445
[build-system]
4546
requires = ["poetry-core>=1.0.0"]

tests/acceptance/test_measurement_service.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Tests to validate measurement service. Uses the Sample Measurement Example."""
22
import random
3+
import urllib.parse
4+
import urllib.request
35
from os import path
46

57
import grpc
@@ -132,5 +134,8 @@ def _validate_metadata_response(get_metadata_response):
132134
assert len(get_metadata_response.measurement_parameters.outputs) == 4
133135

134136
assert len(get_metadata_response.user_interface_details) == 1
135-
url = get_metadata_response.user_interface_details[0].configuration_ui_url
136-
assert path.exists(url)
137+
url = urllib.parse.urlparse(
138+
get_metadata_response.user_interface_details[0].configuration_ui_url
139+
)
140+
localpath = urllib.request.url2pathname(url.path)
141+
assert path.exists(localpath)

tests/unit/test_discovery_client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Contains tests to validate the discovery_client.py.
22
"""
33
from ni_measurement_service._internal import discovery_client
4-
from ni_measurement_service.measurement.info import ServiceInfo, MeasurementInfo, UIFileType
4+
from ni_measurement_service.measurement.info import ServiceInfo, MeasurementInfo
55
from tests.utilities.fake_registry_service import (
66
FakeRegistryServiceStub,
77
FakeRegistryServiceStubError,
@@ -12,7 +12,6 @@
1212
_TEST_SERVICE_INFO = ServiceInfo("TestServiceClass", "TestServiceID", "TestUrl")
1313
_TEST_MEASUREMENT_INFO = MeasurementInfo(
1414
display_name="TestMeasurement",
15-
ui_file_type=UIFileType.LabVIEW,
1615
version="1.0.0.0",
1716
measurement_type="Test",
1817
product_type="Test",
@@ -76,5 +75,4 @@ def _validate_grpc_request(request):
7675
assert request.service_description.service_class == _TEST_SERVICE_INFO.service_class
7776
assert request.service_description.description_url == _TEST_SERVICE_INFO.description_url
7877
assert request.service_description.name == _TEST_MEASUREMENT_INFO.display_name
79-
assert discovery_client._LABVIEW_ATTRIBUTE in request.service_description.attributes
8078
assert discovery_client._PROVIDED_MEASUREMENT_SERVICE in request.provided_services

0 commit comments

Comments
 (0)