Skip to content

Commit 45f53e6

Browse files
authored
service: Enable type checking for tracelogging (#1123)
* service: Remove ignore_missing_imports for traceloggingdynamic * service: Update traceloggingdynamic in poetry.lock * service: Fix _tracelogging typing bugs * service: Only try to import traceloggingdynamic on Windows * service: Install traceloggingdynamic as a dev dependency on Linux for type checking * service: Update poetry.lock * Revert "service: Only try to import traceloggingdynamic on Windows" This reverts commit 8215a0e. * service: Try to import traceloggingdynamic on all platforms for type hints, but only create a provider on Windows * service: Import traceloggingdynamic on Windows and when type checking
1 parent fd35ceb commit 45f53e6

3 files changed

Lines changed: 17 additions & 8 deletions

File tree

‎packages/service/ni_measurement_plugin_sdk_service/_tracelogging.py‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,21 @@
33
import ctypes
44
import sys
55
import uuid
6+
from typing import TYPE_CHECKING
67

7-
try:
8-
import traceloggingdynamic
8+
if sys.platform == "win32":
9+
try:
10+
import traceloggingdynamic
11+
12+
_event_provider: traceloggingdynamic.Provider | None = traceloggingdynamic.Provider(
13+
b"NI-Measurement-Plug-In-Python"
14+
)
15+
except ImportError:
16+
_event_provider = None
17+
else:
18+
if TYPE_CHECKING:
19+
import traceloggingdynamic
920

10-
_event_provider = traceloggingdynamic.Provider(b"NI-Measurement-Plug-In-Python")
11-
except ImportError:
1221
_event_provider = None
1322

1423
_LEVEL_LOG_ALWAYS = 0
@@ -72,7 +81,7 @@ def _get_current_thread_activity_id() -> uuid.UUID:
7281

7382
def is_enabled() -> bool:
7483
"""Queries whether the event provider is enabled."""
75-
return _event_provider and _event_provider.is_enabled()
84+
return _event_provider is not None and _event_provider.is_enabled()
7685

7786

7887
def log_grpc_client_call_start(method_name: str) -> uuid.UUID | None:

‎packages/service/poetry.lock‎

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

‎packages/service/pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ numpy = [
8282
{version = ">=1.26", python = "^3.12"},
8383
]
8484
bandit = { version = ">=1.7", extras = ["toml"] }
85+
# Install traceloggingdynamic on Linux for type checking.
86+
traceloggingdynamic = { version = ">=1.0", platform = "linux" }
8587

8688
[tool.poetry.group.docs]
8789
optional = true
@@ -134,8 +136,6 @@ module = [
134136
"grpc.framework.foundation.*",
135137
# https://github.com/ni/hightime/issues/4 - Add type annotations
136138
"hightime.*",
137-
# https://github.com/microsoft/tracelogging/issues/57 - Python traceloggingdynamic package is missing py.typed marker file
138-
"traceloggingdynamic",
139139
# https://github.com/ni/nidaqmx-python/issues/209 - Support type annotations
140140
"nidaqmx",
141141
# https://github.com/ni/nimi-python/issues/1887 - Support type annotations

0 commit comments

Comments
 (0)