From 045958979d84d1324d04037edbe6e1ea05876027 Mon Sep 17 00:00:00 2001 From: Pierre Fayolle Date: Tue, 16 Jan 2024 10:51:37 +0100 Subject: [PATCH] Try relative imports of tahu files if global import fails Removes the need to add tahu to the PYTHONPATH --- enki.py | 5 ++++- shell.py | 10 ++++++++-- sp_helpers.py | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/enki.py b/enki.py index f6cd36c..55724d7 100755 --- a/enki.py +++ b/enki.py @@ -5,7 +5,10 @@ import argparse import signal -from sparkplug_b_pb2 import Payload +try: + from sparkplug_b_pb2 import Payload +except ImportError: + from tahu.python.core.sparkplug_b_pb2 import Payload from mqtt_if import MQTTInterface from sp_topic import SPTopic diff --git a/shell.py b/shell.py index 0111104..96d79c5 100644 --- a/shell.py +++ b/shell.py @@ -5,8 +5,14 @@ import cmd2 -import sparkplug_b_pb2 -from sparkplug_b import MetricDataType, addMetric, addNullMetric, initDatasetMetric +try: + import sparkplug_b_pb2 + from sparkplug_b import MetricDataType, addMetric + from sparkplug_b import addNullMetric, initDatasetMetric +except ImportError: + import tahu.python.core.sparkplug_b_pb2 + from tahu.python.core.sparkplug_b import MetricDataType, addMetric + from tahu.python.core.sparkplug_b import addNullMetric, initDatasetMetric import sp_helpers from sp_helpers import MsgType diff --git a/sp_helpers.py b/sp_helpers.py index 9e588bb..3eb15b3 100644 --- a/sp_helpers.py +++ b/sp_helpers.py @@ -4,7 +4,10 @@ from typing import Optional from enum import Enum -from sparkplug_b import MetricDataType +try: + from sparkplug_b import MetricDataType +except ImportError: + from tahu.python.core.sparkplug_b import MetricDataType # Sparkplug namespace used