diff --git a/.gitignore b/.gitignore index 99c29415..d34d71b1 100644 --- a/.gitignore +++ b/.gitignore @@ -121,7 +121,6 @@ zip-build* /typings/* *.csv -*.json */PyQt-UI* specklepy_qt_ui* -*requirements.txt +plugin_utils/requirements.txt \ No newline at end of file diff --git a/README.md b/README.md index 7a930db4..b9af3be8 100644 --- a/README.md +++ b/README.md @@ -157,19 +157,14 @@ Though it is not required, we recommend installing these plugins from the QGIS P #### Visual Studio Code -First, you'll need to change the _debug value to True in `plugin_utils/installer.py` file and verify the VS Code Python extension path: +First, you'll need to change the _debug value to True in `plugin_utils/installer.py` file. ```python _debug = True - _vs_code_directory = os.path.expanduser("~\.vscode\extensions\ms-python.python-2023.20.0\pythonFiles\lib\python") ``` This will automatically setup `debugpy` if it's not already installed, and start listening to port `5678`. -In VS Code, you can use the built in python debugger. You'll need to create a debug configuration by creating a `launch.json` file. - -![Create Debug Config](https://user-images.githubusercontent.com/2316535/129895259-3b9ede24-a898-4dbd-86df-0d15f19a2714.png) - Select the "Python" -> "Remote Attach" option. Your `launch.json` should look like this: ```json diff --git a/__init__.py b/__init__.py index 0c376a4f..54851f25 100644 --- a/__init__.py +++ b/__init__.py @@ -7,7 +7,7 @@ if path not in sys.path: sys.path.insert(0, path) -from plugin_utils.installer import ensure_dependencies, startDegugger +from plugin_utils.installer import ensure_dependencies, startDebugger from speckle.utils.panel_logging import logger from qgis.core import Qgis @@ -28,22 +28,8 @@ def classFactory(iface): # pylint: disable=invalid-name # Ensure dependencies are installed in the machine # from speckle.utils import enable_remote_debugging # enable_remote_debugging() + startDebugger() ensure_dependencies("QGIS") - startDegugger() - - try: - import specklepy - import shapefile - from urllib3.contrib import appengine - - except Exception as e: - logger.logToUserWithAction( - "Speckle dependencies were not resolved.", - action_text="More info", - url="https://github.com/specklesystems/speckle-qgis/blob/main/plugin_utils/reporting_issues.md", - level=2, - ) - return EmptyClass(iface) from speckle_qgis import SpeckleQGIS from specklepy.logging import metrics diff --git a/plugin_utils/installer.py b/plugin_utils/installer.py index d132b3de..fcfe4f73 100644 --- a/plugin_utils/installer.py +++ b/plugin_utils/installer.py @@ -7,6 +7,8 @@ from typing import Optional from importlib import import_module, invalidate_caches import pkg_resources +from subprocess import run +import shutil from speckle.utils.utils import get_qgis_python_path @@ -124,8 +126,6 @@ def is_pip_available() -> bool: def ensure_pip() -> None: print("Installing pip... ") - from subprocess import run - print(PYTHON_PATH) completed_process = run([PYTHON_PATH, "-m", "ensurepip"]) @@ -140,6 +140,8 @@ def ensure_pip() -> None: def get_requirements_path() -> Path: # we assume that a requirements.txt exists next to the __init__.py file + if sys.platform.lower().startswith("darwin"): + path = Path(Path(__file__).parent, "requirements_mac.txt") path = Path(Path(__file__).parent, "requirements.txt") assert path.exists(), f"path not found {path}" return path @@ -165,36 +167,11 @@ def install_requirements(host_application: str) -> None: path = str(connector_installation_path(host_application)) print(f"Installing debugpy to {path}") - from subprocess import run - - if _debug is True: - try: - import debugpy - except: - completed_process = run( - [ - PYTHON_PATH, - "-m", - "pip", - "install", - "-t", - str(path), - "debugpy==1.8.0", - ], - shell=True, - capture_output=True, - text=True, - ) - if completed_process.returncode != 0: - m = f"Failed to install debugpy through pip. Disable debug mode or install debugpy manually. Full log: {completed_process}" - raise Exception(completed_process) if _dependencies_installed(requirements, path): return try: - import shutil - shutil.rmtree(path) except PermissionError as e: # from speckle.utils.panel_logging import logger @@ -214,9 +191,7 @@ def install_requirements(host_application: str) -> None: "-r", str(get_requirements_path()), ], - shell=True, capture_output=True, - text=True, ) if completed_process.returncode != 0: @@ -263,22 +238,35 @@ def ensure_dependencies(host_application: str) -> None: ) -def startDegugger() -> None: - try: - # debugger: https://gist.github.com/giohappy/8a30f14678aa7e446f9b694c632d7089 - if _debug is True: +def startDebugger() -> None: + if _debug is True: + try: import debugpy - import shutil + except: + # path = str(connector_installation_path(host_application)) + completed_process = run( + [ + PYTHON_PATH, + "-m", + "pip", + "install", + "debugpy==1.8.0", + ], + capture_output=True, + ) + if completed_process.returncode != 0: + m = f"Failed to install debugpy through pip. Disable debug mode or install debugpy manually. Full log: {completed_process}" + raise Exception(completed_process) + + # debugger: https://gist.github.com/giohappy/8a30f14678aa7e446f9b694c632d7089 + if _debug is True: + import debugpy - sys.path.append(_vs_code_directory) - debugpy.configure(python=shutil.which("python")) + sys.path.append(_vs_code_directory) + debugpy.configure(python=PYTHON_PATH) # shutil.which("python")) - try: - debugpy.listen(("localhost", 5678)) - except: - debugpy.connect(("localhost", 5678)) - except: - pass + debugpy.listen(("localhost", 5678)) + debugpy.wait_for_client() # path = str(connector_installation_path("QGIS")) diff --git a/plugin_utils/requirements_mac.txt b/plugin_utils/requirements_mac.txt new file mode 100644 index 00000000..fe2c9503 --- /dev/null +++ b/plugin_utils/requirements_mac.txt @@ -0,0 +1,11 @@ +geopandas==0.8.1 +geovoronoi==0.4.0 +gql==3.4.1 +pandas==1.3.3 +pyproj==3.2.0 +pyshp==2.3.1 +python-dateutil==2.8.0 +requests-toolbelt==0.10.1 +requests==2.31.0 +specklepy==2.17.12 +urllib3==1.26.16 \ No newline at end of file diff --git a/speckle_qgis.py b/speckle_qgis.py index a7b339ee..48b27fdd 100644 --- a/speckle_qgis.py +++ b/speckle_qgis.py @@ -1063,7 +1063,7 @@ def run(self): import requests # if the standard QGIS libraries are used - if urllib3.__version__ == "1.25.11" and requests.__version__ == "2.24.0": + if (urllib3.__version__ == "1.25.11" and requests.__version__ == "2.24.0") or (urllib3.__version__.startswith("1.24.") and requests.__version__.startswith("2.23.")): logToUser( "Dependencies versioning error.\nClick here for details.", url="dependencies_error",