Skip to content

Commit

Permalink
examples, generator: Remove GrpcChannelPoolHelper (#558)
Browse files Browse the repository at this point in the history
* examples: Update minimum nims version to 1.3.0-dev2 for examples that use GrpcChannelPool directly

* examples: Remove GrpcChannelPoolHelper from _helpers.py

* generator: Remove GrpcChannelPoolHelper from _helpers.py(.mako)

* examples: Remove usage of GrpcChannelPoolHelper
  • Loading branch information
bkeryan authored Dec 15, 2023
1 parent e499d4a commit 6e9b30c
Show file tree
Hide file tree
Showing 33 changed files with 52 additions and 350 deletions.
22 changes: 0 additions & 22 deletions examples/game_of_life/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@
from typing import Any, Callable, TypeVar

import click
import grpc
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.measurement.service import GrpcChannelPool


class GrpcChannelPoolHelper(GrpcChannelPool):
"""Class that manages gRPC channel lifetimes."""

def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()

@property
def pin_map_channel(self) -> grpc.Channel:
"""Return gRPC channel to pin map service."""
return self.get_channel(
self._discovery_client.resolve_service(
provided_interface="ni.measurementlink.pinmap.v1.PinMapService",
service_class="ni.measurementlink.pinmap.v1.PinMapService",
).insecure_address
)


class TestStandSupport(object):
Expand Down
22 changes: 0 additions & 22 deletions examples/nidaqmx_analog_input/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@
from typing import Any, Callable, TypeVar

import click
import grpc
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.measurement.service import GrpcChannelPool


class GrpcChannelPoolHelper(GrpcChannelPool):
"""Class that manages gRPC channel lifetimes."""

def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()

@property
def pin_map_channel(self) -> grpc.Channel:
"""Return gRPC channel to pin map service."""
return self.get_channel(
self._discovery_client.resolve_service(
provided_interface="ni.measurementlink.pinmap.v1.PinMapService",
service_class="ni.measurementlink.pinmap.v1.PinMapService",
).insecure_address
)


class TestStandSupport(object):
Expand Down
2 changes: 1 addition & 1 deletion examples/nidaqmx_analog_input/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["National Instruments"]
[tool.poetry.dependencies]
python = "^3.8"
nidaqmx = { version = ">=0.8.0", extras = ["grpc"] }
ni-measurementlink-service = {version = "^1.3.0-dev0", allow-prereleases = true}
ni-measurementlink-service = {version = "^1.3.0-dev2", allow-prereleases = true}
click = ">=7.1.2, !=8.1.4" # mypy fails with click 8.1.4: https://github.com/pallets/click/issues/2558

[tool.poetry.group.dev.dependencies]
Expand Down
7 changes: 4 additions & 3 deletions examples/nidaqmx_analog_input/teststand_nidaqmx.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Functions to set up and tear down sessions of NI-DAQmx devices in NI TestStand."""
from typing import Any

from _helpers import GrpcChannelPoolHelper, TestStandSupport
from _helpers import TestStandSupport
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.grpc.channelpool import GrpcChannelPool
from ni_measurementlink_service.session_management import (
INSTRUMENT_TYPE_NI_DAQMX,
PinMapContext,
Expand All @@ -18,7 +19,7 @@ def create_nidaqmx_tasks(sequence_context: Any) -> None:
sequence_context: The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
teststand_support = TestStandSupport(sequence_context)
pin_map_id = teststand_support.get_active_pin_map_id()
pin_map_context = PinMapContext(pin_map_id=pin_map_id, sites=None)
Expand All @@ -42,7 +43,7 @@ def create_nidaqmx_tasks(sequence_context: Any) -> None:

def destroy_nidaqmx_tasks() -> None:
"""Destroy and unregister all NI-DAQmx tasks."""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand Down
22 changes: 0 additions & 22 deletions examples/nidcpower_source_dc_voltage/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@
from typing import Any, Callable, TypeVar

import click
import grpc
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.measurement.service import GrpcChannelPool


class GrpcChannelPoolHelper(GrpcChannelPool):
"""Class that manages gRPC channel lifetimes."""

def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()

@property
def pin_map_channel(self) -> grpc.Channel:
"""Return gRPC channel to pin map service."""
return self.get_channel(
self._discovery_client.resolve_service(
provided_interface="ni.measurementlink.pinmap.v1.PinMapService",
service_class="ni.measurementlink.pinmap.v1.PinMapService",
).insecure_address
)


class TestStandSupport(object):
Expand Down
2 changes: 1 addition & 1 deletion examples/nidcpower_source_dc_voltage/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["National Instruments"]
[tool.poetry.dependencies]
python = "^3.8"
nidcpower = { version = ">=1.4.4", extras = ["grpc"] }
ni-measurementlink-service = {version = "^1.3.0-dev0", allow-prereleases = true}
ni-measurementlink-service = {version = "^1.3.0-dev2", allow-prereleases = true}
click = ">=7.1.2, !=8.1.4" # mypy fails with click 8.1.4: https://github.com/pallets/click/issues/2558
grpcio = "*"

Expand Down
7 changes: 4 additions & 3 deletions examples/nidcpower_source_dc_voltage/teststand_nidcpower.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Functions to set up and tear down sessions of NI-DCPower devices in NI TestStand."""
from typing import Any

from _helpers import GrpcChannelPoolHelper, TestStandSupport
from _helpers import TestStandSupport
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.grpc.channelpool import GrpcChannelPool
from ni_measurementlink_service.session_management import (
INSTRUMENT_TYPE_NI_DCPOWER,
PinMapContext,
Expand All @@ -18,7 +19,7 @@ def create_nidcpower_sessions(sequence_context: Any) -> None:
sequence_context: The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
teststand_support = TestStandSupport(sequence_context)
pin_map_id = teststand_support.get_active_pin_map_id()
pin_map_context = PinMapContext(pin_map_id=pin_map_id, sites=None)
Expand All @@ -40,7 +41,7 @@ def create_nidcpower_sessions(sequence_context: Any) -> None:

def destroy_nidcpower_sessions() -> None:
"""Destroy and unregister all NI-DCPower sessions."""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand Down
22 changes: 0 additions & 22 deletions examples/nidigital_spi/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@
from typing import Any, Callable, TypeVar

import click
import grpc
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.measurement.service import GrpcChannelPool


class GrpcChannelPoolHelper(GrpcChannelPool):
"""Class that manages gRPC channel lifetimes."""

def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()

@property
def pin_map_channel(self) -> grpc.Channel:
"""Return gRPC channel to pin map service."""
return self.get_channel(
self._discovery_client.resolve_service(
provided_interface="ni.measurementlink.pinmap.v1.PinMapService",
service_class="ni.measurementlink.pinmap.v1.PinMapService",
).insecure_address
)


class TestStandSupport(object):
Expand Down
2 changes: 1 addition & 1 deletion examples/nidigital_spi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["National Instruments"]
[tool.poetry.dependencies]
python = "^3.8"
nidigital = ">=1.4.4"
ni-measurementlink-service = {version = "^1.3.0-dev0", allow-prereleases = true}
ni-measurementlink-service = {version = "^1.3.0-dev2", allow-prereleases = true}
click = ">=7.1.2, !=8.1.4" # mypy fails with click 8.1.4: https://github.com/pallets/click/issues/2558
grpcio = "*"

Expand Down
13 changes: 7 additions & 6 deletions examples/nidigital_spi/teststand_nidigital.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Functions to set up and tear down sessions of NI Digital Pattern instruments in NI TestStand."""
from typing import Any, Iterable

from _helpers import GrpcChannelPoolHelper, TestStandSupport
from _helpers import TestStandSupport
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.grpc.channelpool import GrpcChannelPool
from ni_measurementlink_service.session_management import (
INSTRUMENT_TYPE_NI_DIGITAL_PATTERN,
PinMapContext,
Expand All @@ -22,7 +23,7 @@ def create_nidigital_sessions(sequence_context: Any) -> None:
teststand_support = TestStandSupport(sequence_context)
pin_map_id = teststand_support.get_active_pin_map_id()

with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand Down Expand Up @@ -50,7 +51,7 @@ def load_nidigital_pin_map(pin_map_path: str, sequence_context: Any) -> None:
pin_map_id = teststand_support.get_active_pin_map_id()
pin_map_abs_path = teststand_support.resolve_file_path(pin_map_path)

with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand Down Expand Up @@ -88,7 +89,7 @@ def load_nidigital_specifications_levels_and_timing(
levels_file_abs_paths = [teststand_support.resolve_file_path(p) for p in levels_file_paths]
timing_file_abs_paths = [teststand_support.resolve_file_path(p) for p in timing_file_paths]

with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand Down Expand Up @@ -120,7 +121,7 @@ def load_nidigital_patterns(
pin_map_id = teststand_support.get_active_pin_map_id()
pattern_file_abs_paths = [teststand_support.resolve_file_path(p) for p in pattern_file_paths]

with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand All @@ -138,7 +139,7 @@ def load_nidigital_patterns(

def destroy_nidigital_sessions() -> None:
"""Destroy and unregister all NI-Digital sessions."""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand Down
22 changes: 0 additions & 22 deletions examples/nidmm_measurement/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@
from typing import Any, Callable, TypeVar

import click
import grpc
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.measurement.service import GrpcChannelPool


class GrpcChannelPoolHelper(GrpcChannelPool):
"""Class that manages gRPC channel lifetimes."""

def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()

@property
def pin_map_channel(self) -> grpc.Channel:
"""Return gRPC channel to pin map service."""
return self.get_channel(
self._discovery_client.resolve_service(
provided_interface="ni.measurementlink.pinmap.v1.PinMapService",
service_class="ni.measurementlink.pinmap.v1.PinMapService",
).insecure_address
)


class TestStandSupport(object):
Expand Down
2 changes: 1 addition & 1 deletion examples/nidmm_measurement/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["National Instruments"]
[tool.poetry.dependencies]
python = "^3.8"
nidmm = { version = ">=1.4.4", extras = ["grpc"] }
ni-measurementlink-service = {version = "^1.3.0-dev0", allow-prereleases = true}
ni-measurementlink-service = {version = "^1.3.0-dev2", allow-prereleases = true}
click = ">=7.1.2, !=8.1.4" # mypy fails with click 8.1.4: https://github.com/pallets/click/issues/2558
grpcio = "*"

Expand Down
7 changes: 4 additions & 3 deletions examples/nidmm_measurement/teststand_nidmm.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Functions to set up and tear down sessions of NI-DMM devices in NI TestStand."""
from typing import Any

from _helpers import GrpcChannelPoolHelper, TestStandSupport
from _helpers import TestStandSupport
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.grpc.channelpool import GrpcChannelPool
from ni_measurementlink_service.session_management import (
INSTRUMENT_TYPE_NI_DMM,
PinMapContext,
Expand All @@ -18,7 +19,7 @@ def create_nidmm_sessions(sequence_context: Any) -> None:
sequence_context: The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
teststand_support = TestStandSupport(sequence_context)
pin_map_id = teststand_support.get_active_pin_map_id()
pin_map_context = PinMapContext(pin_map_id=pin_map_id, sites=None)
Expand All @@ -41,7 +42,7 @@ def create_nidmm_sessions(sequence_context: Any) -> None:

def destroy_nidmm_sessions() -> None:
"""Destroy and unregister all NI-DMM sessions."""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand Down
22 changes: 0 additions & 22 deletions examples/nifgen_standard_function/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,6 @@
from typing import Any, Callable, TypeVar

import click
import grpc
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.measurement.service import GrpcChannelPool


class GrpcChannelPoolHelper(GrpcChannelPool):
"""Class that manages gRPC channel lifetimes."""

def __init__(self) -> None:
"""Initialize the GrpcChannelPool object."""
super().__init__()
self._discovery_client = DiscoveryClient()

@property
def pin_map_channel(self) -> grpc.Channel:
"""Return gRPC channel to pin map service."""
return self.get_channel(
self._discovery_client.resolve_service(
provided_interface="ni.measurementlink.pinmap.v1.PinMapService",
service_class="ni.measurementlink.pinmap.v1.PinMapService",
).insecure_address
)


class TestStandSupport(object):
Expand Down
2 changes: 1 addition & 1 deletion examples/nifgen_standard_function/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ authors = ["National Instruments"]
[tool.poetry.dependencies]
python = "^3.8"
nifgen = { version = ">=1.4.4", extras = ["grpc"] }
ni-measurementlink-service = {version = "^1.3.0-dev0", allow-prereleases = true}
ni-measurementlink-service = {version = "^1.3.0-dev2", allow-prereleases = true}
click = ">=7.1.2, !=8.1.4" # mypy fails with click 8.1.4: https://github.com/pallets/click/issues/2558
grpcio = "*"

Expand Down
7 changes: 4 additions & 3 deletions examples/nifgen_standard_function/teststand_nifgen.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Functions to set up and tear down sessions of NI-FGEN devices in NI TestStand."""
from typing import Any

from _helpers import GrpcChannelPoolHelper, TestStandSupport
from _helpers import TestStandSupport
from ni_measurementlink_service.discovery import DiscoveryClient
from ni_measurementlink_service.grpc.channelpool import GrpcChannelPool
from ni_measurementlink_service.session_management import (
INSTRUMENT_TYPE_NI_FGEN,
PinMapContext,
Expand All @@ -18,7 +19,7 @@ def create_nifgen_sessions(sequence_context: Any) -> None:
sequence_context: The SequenceContext COM object from the TestStand sequence execution.
(Dynamically typed.)
"""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
teststand_support = TestStandSupport(sequence_context)
pin_map_id = teststand_support.get_active_pin_map_id()
pin_map_context = PinMapContext(pin_map_id=pin_map_id, sites=None)
Expand All @@ -41,7 +42,7 @@ def create_nifgen_sessions(sequence_context: Any) -> None:

def destroy_nifgen_sessions() -> None:
"""Destroy and unregister all NI-FGEN sessions."""
with GrpcChannelPoolHelper() as grpc_channel_pool:
with GrpcChannelPool() as grpc_channel_pool:
discovery_client = DiscoveryClient(grpc_channel_pool=grpc_channel_pool)
session_management_client = SessionManagementClient(
discovery_client=discovery_client, grpc_channel_pool=grpc_channel_pool
Expand Down
Loading

0 comments on commit 6e9b30c

Please sign in to comment.