Skip to content

Commit

Permalink
Try relative imports of tahu files if global import fails
Browse files Browse the repository at this point in the history
Removes the need to add tahu to the PYTHONPATH
  • Loading branch information
pfayolle committed Jan 16, 2024
1 parent bc4d8d6 commit 0459589
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 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
10 changes: 8 additions & 2 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:
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
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 0459589

Please sign in to comment.