Skip to content

Commit

Permalink
forgot to commit the new lookfordependency
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristianTremblay committed Sep 8, 2024
1 parent 5f0d4a9 commit 7ff2ef8
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions BAC0/core/utils/lookfordependency.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import importlib.util
from types import ModuleType
from typing import Type


# Function to dynamically import a module
Expand All @@ -21,7 +23,8 @@ def check_dependencies(module_name: list) -> bool:

def rich_if_available():
if not check_dependencies(["rich"]):
return None
_RICH = False
return (_RICH, FakeRich)
try:
rich_spec = importlib.util.find_spec("rich")
if rich_spec is not None:
Expand All @@ -31,12 +34,14 @@ def rich_if_available():
_RICH = False
except ImportError:
_RICH = False
rich = False
return (_RICH, rich)


def influxdb_if_available():
if not check_dependencies(["influxdb_client"]):
return None
_INFLUXDB = False
return (_INFLUXDB, FakeInflux)
try:
influxdb_spec = importlib.util.find_spec("influxdb_client")
if influxdb_spec is not None:
Expand All @@ -46,10 +51,11 @@ def influxdb_if_available():
_INFLUXDB = False
except ImportError:
_INFLUXDB = False
influxdb_client = False
return (_INFLUXDB, influxdb_client)


def pandas_if_available():
def pandas_if_available() -> tuple[bool, Type, ModuleType, ModuleType]:
global _PANDAS
if not check_dependencies(["pandas"]):
return None
Expand All @@ -67,21 +73,32 @@ def pandas_if_available():
Timestamp = import_module("pandas.lib").Timestamp

_PANDAS = True

except ImportError:
_PANDAS = False
pd = FakePandas
sql = FakePandas.sql
Timestamp = FakePandas.Timestamp
return (_PANDAS, pd, sql, Timestamp)


def xlwings_if_available():
if not check_dependencies(["xlwings"]):
class FakePandas:
"Typing in Device requires pandas, but it is not available"

class DataFrame:
id = "fake"

def sql(self):
return None
try:
xlwings_spec = importlib.util.find_spec("xlwings")
if xlwings_spec is not None:
xlwings = import_module("xlwings")
_XLWINGS = True
else:
_XLWINGS = False
except ImportError:
_XLWINGS = False
return (_XLWINGS, xlwings)

def Timestamp(self):
return None


class FakeInflux:
"Typing in Device requires influxdb_client, but it is not available"
pass


class FakeRich:
pass

0 comments on commit 7ff2ef8

Please sign in to comment.