Skip to content

Commit

Permalink
wrap main __init to try/except
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Jan 18, 2024
1 parent 7f497ed commit 69e0b77
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 47 deletions.
68 changes: 35 additions & 33 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,49 @@
if path not in sys.path:
sys.path.insert(0, path)

from plugin_utils.installer import ensure_dependencies, startDebugger
from speckle.utils.panel_logging import logger
try:
from plugin_utils.installer import ensure_dependencies, startDebugger
from speckle.utils.panel_logging import logger

from qgis.core import Qgis
from qgis.core import Qgis

# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
"""Load SpeckleQGIS class from file SpeckleQGIS.
# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
"""Load SpeckleQGIS class from file SpeckleQGIS.
:param iface: A QGIS interface instance.
:type iface: QgsInterface
"""

:param iface: A QGIS interface instance.
:type iface: QgsInterface
"""
# Set qgisInterface to enable logToUser notifications
logger.qgisInterface = iface
iface.pluginToolBar().setVisible(True)

# Set qgisInterface to enable logToUser notifications
logger.qgisInterface = iface
iface.pluginToolBar().setVisible(True)
# Ensure dependencies are installed in the machine
startDebugger()
ensure_dependencies("QGIS")

# Ensure dependencies are installed in the machine
startDebugger()
ensure_dependencies("QGIS")
from speckle_qgis import SpeckleQGIS
from specklepy.logging import metrics

from speckle_qgis import SpeckleQGIS
from specklepy.logging import metrics
version = (
Qgis.QGIS_VERSION.encode("iso-8859-1", errors="ignore")
.decode("utf-8")
.split(".")[0]
)
metrics.set_host_app("QGIS", f"QGIS{version}")
return SpeckleQGIS(iface)

version = (
Qgis.QGIS_VERSION.encode("iso-8859-1", errors="ignore")
.decode("utf-8")
.split(".")[0]
)
metrics.set_host_app("QGIS", f"QGIS{version}")
return SpeckleQGIS(iface)
class EmptyClass:
# https://docs.qgis.org/3.28/en/docs/pyqgis_developer_cookbook/plugins/plugins.html#mainplugin-py
def __init__(self, iface):
pass

def initGui(self):
pass

class EmptyClass:
# https://docs.qgis.org/3.28/en/docs/pyqgis_developer_cookbook/plugins/plugins.html#mainplugin-py
def __init__(self, iface):
pass
def unload(self):
pass

def initGui(self):
pass

def unload(self):
pass
except ModuleNotFoundError:
pass
29 changes: 15 additions & 14 deletions tests/unit/geometry_tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
import os
import sys


def test_path():
import speckle

p = os.path.abspath(os.path.dirname(speckle.__file__))
t = os.path.abspath(
os.path.dirname(speckle.__file__).replace(
"speckle-qgis\\speckle", "speckle-qgis\\specklepy_qt_ui"
)
)
assert "1" in sys.path
assert p == "1"
assert t == "1"


from speckle.converter.geometry.utils import (
cross_product,
dot,
Expand Down Expand Up @@ -325,17 +340,3 @@ def test_apply_pt_transform_matrix(data_storage):
data_storage.matrix = matrix
result = apply_pt_transform_matrix(pt, data_storage)
assert isinstance(result, Point)


def test_path():
import speckle

p = os.path.abspath(os.path.dirname(speckle.__file__))
t = os.path.abspath(
os.path.dirname(speckle.__file__).replace(
"speckle-qgis\\speckle", "speckle-qgis\\specklepy_qt_ui"
)
)
assert "1" in sys.path
assert p=="1"
assert t=="1"

0 comments on commit 69e0b77

Please sign in to comment.