Skip to content

Commit

Permalink
Merge pull request #27 from SiemaApplications/try_import
Browse files Browse the repository at this point in the history
Try relative imports of tahu files if global import fails
  • Loading branch information
pfayolle authored Jan 16, 2024
2 parents bc4d8d6 + 23e3ed0 commit 6dfc8fe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 4 additions & 1 deletion enki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@

import cmd2

import sparkplug_b_pb2
from sparkplug_b import MetricDataType, addMetric, addNullMetric, initDatasetMetric
try:
from sparkplug_b_pb2 import Payload
from sparkplug_b import MetricDataType, addMetric
from sparkplug_b import addNullMetric, initDatasetMetric
except ImportError:
from tahu.python.core.sparkplug_b_pb2 import Payload
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
Expand Down Expand Up @@ -433,7 +439,7 @@ def do_send(self, args):

msg_type = MsgType.CMD if args.msg_type == "CMD" else MsgType.DATA
topic = sp_dev.get_msg_topic(msg_type)
payload = sparkplug_b_pb2.Payload()
payload = Payload()
new_metric = True
while new_metric:
metric = self.choose_metric(sp_dev)
Expand Down
5 changes: 4 additions & 1 deletion sp_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6dfc8fe

Please sign in to comment.