Skip to content

Commit

Permalink
Kate/mac builder (#178)
Browse files Browse the repository at this point in the history
* all corrected

* redirect to mac_requirements

* ignore Windows/linux requirements

* debugger off

* readme debugging

* redundant module
  • Loading branch information
KatKatKateryna authored Nov 27, 2023
1 parent b1539f2 commit 83d9492
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 67 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ zip-build*

/typings/*
*.csv
*.json
*/PyQt-UI*
specklepy_qt_ui*
*requirements.txt
plugin_utils/requirements.txt
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 2 additions & 16 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
72 changes: 30 additions & 42 deletions plugin_utils/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"])
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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"))
Expand Down
11 changes: 11 additions & 0 deletions plugin_utils/requirements_mac.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion speckle_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 83d9492

Please sign in to comment.