Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
check_nims:
name: Check NIMS
uses: ./.github/workflows/check_nims.yml
check_nims_docs:
name: Check NIMS docs
uses: ./.github/workflows/check_nims_docs.yml
check_nimg:
name: Check NIMG
uses: ./.github/workflows/check_nimg.yml
Expand Down
32 changes: 16 additions & 16 deletions .github/workflows/check_nimg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ on:
jobs:
check_nimg:
name: Check NIMG
runs-on: ubuntu-latest
env:
oldest-python-version: '3.9'
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: [3.9, 3.13]
fail-fast: false
runs-on: ${{ matrix.os }}
defaults:
run:
# Set the working-directory for all steps in this job.
Expand All @@ -18,33 +25,26 @@ jobs:
- name: Set up Python
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
id: setup-python
with:
python-version: ${{ matrix.python-version }}
- name: Set up Poetry
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
- name: Check for lock changes (ni-measurement-plugin-sdk-generator)
run: poetry check --lock
- name: Cache virtualenv (ni-measurement-plugin-sdk-generator)
uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
id: cache
- name: Analyze generator
uses: ni/python-actions/analyze-project@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
with:
path: packages/generator/.venv
key: ni-measurement-plugin-sdk-generator-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('packages/generator/poetry.lock') }}
- name: Install ni-measurement-plugin-sdk-generator
run: poetry install -v
- name: Lint ni-measurement-plugin-sdk-generator
run: poetry run ni-python-styleguide lint
- name: Mypy static analysis (ni-measurement-plugin-sdk-generator, Linux)
run: poetry run mypy
- name: Mypy static analysis (ni-measurement-plugin-sdk-generator, Windows)
run: poetry run mypy --platform win32
project-directory: packages/generator
- 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
if: matrix.python-version == env.oldest-python-version
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
if: matrix.python-version == env.oldest-python-version
run: git diff --exit-code
- name: Revert gRPC stubs
if: matrix.python-version == env.oldest-python-version
run: |
git clean -dfx tests/utilities/measurements/non_streaming_data_measurement/_stubs
git restore tests/utilities/measurements/non_streaming_data_measurement/_stubs
64 changes: 17 additions & 47 deletions .github/workflows/check_nims.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ on:
jobs:
check_nims:
name: Check NIMS
runs-on: ubuntu-latest
env:
oldest-python-version: '3.9'
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
python-version: [3.9, 3.13]
fail-fast: false
runs-on: ${{ matrix.os }}
defaults:
run:
# Set the working-directory for all steps in this job.
Expand All @@ -20,64 +27,27 @@ jobs:
- name: Set up Python
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
id: setup-python
with:
python-version: ${{ matrix.python-version }}
- name: Set up Poetry
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
- name: Check for lock changes (ni-measurement-plugin-sdk-service)
run: poetry check --lock

# ni-measurement-plugin-sdk-service, all extras
- name: Restore cached virtualenv (ni-measurement-plugin-sdk-service, all extras)
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
id: restore-nims-all-extras
- name: Analyze generator
uses: ni/python-actions/analyze-project@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
with:
path: packages/service/.venv
key: ni-measurement-plugin-sdk-service-all-extras-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('packages/service/poetry.lock') }}
- name: Install ni-measurement-plugin-sdk-service (all extras)
run: poetry install -v --all-extras
- name: Save cached virtualenv (ni-measurement-plugin-sdk-service, all extras)
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
if: steps.restore-nims-all-extras.outputs.cache-hit != 'true'
with:
path: packages/service/.venv
key: ${{ steps.restore-nims-all-extras.outputs.cache-primary-key }}
- name: Lint ni-measurement-plugin-sdk-service
run: poetry run ni-python-styleguide lint
- name: Mypy static analysis (ni-measurement-plugin-sdk-service, Linux)
run: poetry run mypy
- name: Mypy static analysis (ni-measurement-plugin-sdk-service, Windows)
run: poetry run mypy --platform win32
project-directory: packages/service
install-args: --all-extras
- name: Bandit security checks (ni-measurement-plugin-sdk-service)
run: poetry run bandit -c pyproject.toml -r ni_measurement_plugin_sdk_service

# ni-measurement-plugin-sdk-service, all extras, docs
- name: Restore cached virtualenv (ni-measurement-plugin-sdk-service, all extras, docs)
uses: actions/cache/restore@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
id: restore-nims-all-extras-docs
with:
path: packages/service/.venv
key: ni-measurement-plugin-sdk-service-all-extras-docs-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('packages/service/poetry.lock') }}
- name: Install ni-measurement-plugin-sdk-service (all extras, docs)
run: poetry install -v --all-extras --with docs
- name: Save cached virtualenv (ni-measurement-plugin-sdk-service, all extras, docs)
uses: actions/cache/save@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
if: steps.restore-nims-all-extras-docs.outputs.cache-hit != 'true'
with:
path: packages/service/.venv
key: ${{ steps.restore-nims-all-extras-docs.outputs.cache-primary-key }}
- name: Build docs and check for errors/warnings
run: |
rm -rf docs
mkdir -p docs
poetry run sphinx-build _docs_source docs -b html -W
- name: Revert docs
run: rm -rf docs
- name: Generate gRPC stubs
if: matrix.python-version == env.oldest-python-version
run: |
find tests/utilities/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
if: matrix.python-version == env.oldest-python-version
run: git diff --exit-code
- name: Revert gRPC stubs
if: matrix.python-version == env.oldest-python-version
run: |
git clean -dfx tests/utilities/stubs/
git restore tests/utilities/stubs/
33 changes: 33 additions & 0 deletions .github/workflows/check_nims_docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Check NIMS Docs

on:
workflow_call:
workflow_dispatch:

jobs:
check_nims:
name: Check NIMS Docs
runs-on: ubuntu-latest
defaults:
run:
# Set the working-directory for all steps in this job.
working-directory: ./packages/service
steps:
- name: Check out repo
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
submodules: true
- name: Set up Python
uses: ni/python-actions/setup-python@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
id: setup-python
- name: Set up Poetry
uses: ni/python-actions/setup-poetry@9768589f3e50672173dad75a6fc181e4a85d33fa # v0.7.0
- name: Install ni-measurement-plugin-sdk-service (all extras, docs)
run: poetry install -v --all-extras --with docs
- name: Build docs and check for errors/warnings
run: |
rm -rf docs
mkdir -p docs
poetry run sphinx-build _docs_source docs -b html -W
- name: Revert docs
run: rm -rf docs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@

_PREFIX = "MEASUREMENT_PLUGIN"

_config = AutoConfig(str(get_dotenv_search_path()))
# Work around decouple's lack of type hints.
_T = TypeVar("_T")

if TYPE_CHECKING:
# Work around decouple's lack of type hints.
_T = TypeVar("_T")

def _config(
option: str,
default: _T | Undefined = undefined,
cast: Callable[[str], _T] | Undefined = undefined,
) -> _T: ...
) -> _T:
"""Get configuration value from environment or config file."""
...

else:
_config = AutoConfig(str(get_dotenv_search_path()))

__all__ = ["_PREFIX", "_config"]


# ----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@
import ctypes
import sys
import uuid
from typing import TYPE_CHECKING
from typing import Any

if sys.platform == "win32":
try:
import traceloggingdynamic
import traceloggingdynamic

_event_provider: traceloggingdynamic.Provider | None = traceloggingdynamic.Provider(
b"NI-Measurement-Plug-In-Python"
)
except ImportError:
_event_provider = None
else:
if TYPE_CHECKING:
import traceloggingdynamic
_event_provider = traceloggingdynamic.Provider(b"NI-Measurement-Plug-In-Python")

def _create_event_builder() -> traceloggingdynamic.EventBuilder:
return traceloggingdynamic.EventBuilder()

else:
_event_provider = None

def _create_event_builder() -> Any:
raise RuntimeError(f"ETW logging is not supported on {sys.platform}")


_LEVEL_LOG_ALWAYS = 0
_LEVEL_CRITICAL = 1
_LEVEL_ERROR = 3
Expand Down Expand Up @@ -87,7 +87,7 @@ def is_enabled() -> bool:
def log_grpc_client_call_start(method_name: str) -> uuid.UUID | None:
"""Log when starting a gRPC client call."""
if _event_provider and _event_provider.is_enabled(level=_LEVEL_INFO, keyword=_KEYWORD_GRPC):
eb = traceloggingdynamic.EventBuilder()
eb = _create_event_builder()
eb.reset(
b"GrpcClientCall",
level=_LEVEL_INFO,
Expand All @@ -107,7 +107,7 @@ def log_grpc_client_call_start(method_name: str) -> uuid.UUID | None:
def log_grpc_client_call_stop(method_name: str, activity_id: uuid.UUID | None = None) -> None:
"""Log when a gRPC client call has completed."""
if _event_provider and _event_provider.is_enabled(level=_LEVEL_INFO, keyword=_KEYWORD_GRPC):
eb = traceloggingdynamic.EventBuilder()
eb = _create_event_builder()
eb.reset(
b"GrpcClientCall",
level=_LEVEL_INFO,
Expand All @@ -122,7 +122,7 @@ def log_grpc_client_call_stop(method_name: str, activity_id: uuid.UUID | None =
def log_grpc_client_call_streaming_request(method_name: str) -> None:
"""Log when a gRPC client call is sending a client-streaming request."""
if _event_provider and _event_provider.is_enabled(level=_LEVEL_INFO, keyword=_KEYWORD_GRPC):
eb = traceloggingdynamic.EventBuilder()
eb = _create_event_builder()
eb.reset(
b"GrpcClientCallStreamingRequest",
level=_LEVEL_INFO,
Expand All @@ -136,7 +136,7 @@ def log_grpc_client_call_streaming_request(method_name: str) -> None:
def log_grpc_client_call_streaming_response(method_name: str) -> None:
"""Log when a gRPC client call has received a server-streaming response."""
if _event_provider and _event_provider.is_enabled(level=_LEVEL_INFO, keyword=_KEYWORD_GRPC):
eb = traceloggingdynamic.EventBuilder()
eb = _create_event_builder()
eb.reset(
b"GrpcClientCallStreamingResponse",
level=_LEVEL_INFO,
Expand All @@ -150,7 +150,7 @@ def log_grpc_client_call_streaming_response(method_name: str) -> None:
def log_grpc_server_call_start(method_name: str) -> uuid.UUID | None:
"""Log when starting a gRPC server call."""
if _event_provider and _event_provider.is_enabled(level=_LEVEL_INFO, keyword=_KEYWORD_GRPC):
eb = traceloggingdynamic.EventBuilder()
eb = _create_event_builder()
eb.reset(
b"GrpcServerCall",
level=_LEVEL_INFO,
Expand All @@ -170,7 +170,7 @@ def log_grpc_server_call_start(method_name: str) -> uuid.UUID | None:
def log_grpc_server_call_stop(method_name: str, activity_id: uuid.UUID | None = None) -> None:
"""Log when a gRPC server call has completed."""
if _event_provider and _event_provider.is_enabled(level=_LEVEL_INFO, keyword=_KEYWORD_GRPC):
eb = traceloggingdynamic.EventBuilder()
eb = _create_event_builder()
eb.reset(
b"GrpcServerCall",
level=_LEVEL_INFO,
Expand All @@ -185,7 +185,7 @@ def log_grpc_server_call_stop(method_name: str, activity_id: uuid.UUID | None =
def log_grpc_server_call_streaming_request(method_name: str) -> None:
"""Log when a gRPC server call is sending a server-streaming request."""
if _event_provider and _event_provider.is_enabled(level=_LEVEL_INFO, keyword=_KEYWORD_GRPC):
eb = traceloggingdynamic.EventBuilder()
eb = _create_event_builder()
eb.reset(
b"GrpcServerCallStreamingRequest",
level=_LEVEL_INFO,
Expand All @@ -199,7 +199,7 @@ def log_grpc_server_call_streaming_request(method_name: str) -> None:
def log_grpc_server_call_streaming_response(method_name: str) -> None:
"""Log when a gRPC server call has received a server-streaming response."""
if _event_provider and _event_provider.is_enabled(level=_LEVEL_INFO, keyword=_KEYWORD_GRPC):
eb = traceloggingdynamic.EventBuilder()
eb = _create_event_builder()
eb.reset(
b"GrpcServerCallStreamingResponse",
level=_LEVEL_INFO,
Expand Down
Loading