Skip to content

Commit

Permalink
Merge pull request #432 from wapaAdmin/add-local-development-settings
Browse files Browse the repository at this point in the history
Add VS Code development environment
  • Loading branch information
ponceta authored Oct 25, 2024
2 parents 0af9641 + fb8dafb commit e1e6cca
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [
"ms-python.python",
],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
}
21 changes: 21 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "debugpy",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "${workspaceFolder}"
}
],
"justMyCode": false
},
]
}
65 changes: 65 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Install dependencies",
"type": "shell",
"command": "pip install debugpy \"sqlalchemy~=1.3.22\" \"geoalchemy2>=0.9.0\"",
"windows": {
"options": {
"shell": {
"executable": "C:\\OSGeo4W\\OSGeo4W.bat"
}
}
},
"problemMatcher": []
},
{
"label": "docker-db",
"type": "docker-compose",
"dockerCompose": {
"up": {
"detached": true,
"build": false,
"services": [
"db"
]
},
"files": [
"${workspaceFolder}/docker-compose.yml"
]
}
},
{
"label": "Launch QGIS",
"type": "process",
"args": [
"--project",
"${workspaceFolder}\\project\\teksi_wastewater.qgs"
],
"runOptions": {
"instanceLimit": 1,
"reevaluateOnRerun": false
},
"dependsOn": [
"docker-db"
],
"problemMatcher": [],
"options": {
"env": {
"QGIS_PLUGINPATH": "${workspaceFolder}\\plugin",
"QGIS_PLUGIN_USE_DEBUGGER": "debugpy",
"PGSERVICEFILE": "${workspaceFolder}\\project\\pg_service.conf"
}
},
"windows": {
"command": "C:\\OSGeo4W\\bin\\qgis-ltr-bin.exe"
},
"linux": {
"command": "qgis"
}
}
]
}
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,29 @@ How to start [testing](https://github.com/teksi/wastewater/discussions/72)
Upcoming first version TEKSI Wastewater 2024.0 is due to end of march 2024.

Migration path from QGEP to TEKSI Wastewater is due to end of summer 2024. <!--- // skip-keyword-check -->

## Local development

1. Open OSGeo4W Shell and run `pip install debugpy`.
2. Clone this repository to your local machine.
3. Open QGIS, go to the _Environment_ section in `Settings > Options - System` and add the following custom variables:

| Apply | Variable | Value |
| :----- | :----------------------- | :---------------------- |
| APPEND | QGIS_PLUGINPATH | {repositoryPath}/plugin |
| APPEND | QGIS_PLUGIN_USE_DEBUGGER | debugpy |

4. Install QGIS plugin _Plugin Reloader_. This will allow you to reload the plugin without restarting QGIS.
5. Follow the _prerequisites_ and _Usage (GUI)_ from https://github.com/wapaAdmin/tww2ag6496/blob/main/docs/en/admin-guide/interlis-io/index.rst

## Local development with VS Code

1. Ensure prerequisites are met according to the [admin guide](docs/en/admin-guide/interlis-io/index.rst).
2. Install [Visual Studio Code](https://code.visualstudio.com/) and the [Python extension](https://marketplace.visualstudio.com/items?itemName=ms-python.python).
3. Install QGIS LTR
4. Install Docker
5. Install debugpy by running task `Install dependencies` or run `pip install debugpy` in the OSGeo4W Shell on Windows or your python env for qgis.
6. Launch QGIS with task `Launch QGIS`.
7. Wait for QGIS to start and open the plugin in QGIS.
7. Ensure __Developer mode__ is enabled in the plugin settings. This will start the debug server.
8. Attach the debugger with Debug: Start Debugging (F5) with configuration `Python: Remote Attach`
14 changes: 14 additions & 0 deletions plugin/teksi_wastewater/teksi_wastewater_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import logging
import os
import shutil

from qgis.core import Qgis, QgsApplication
from qgis.PyQt.QtCore import QLocale, QSettings, Qt
Expand Down Expand Up @@ -82,6 +83,19 @@ class TeksiWastewaterPlugin:
profile = None

def __init__(self, iface):
if os.environ.get("QGIS_DEBUGPY_HAS_LOADED") is None and QSettings().value(
"/TWW/DeveloperMode", False, type=bool
):
try:
import debugpy

debugpy.configure(python=shutil.which("python"))
debugpy.listen(("localhost", 5678))
except Exception as e:
print(f"Unable to create debugpy debugger: {e}")
else:
os.environ["QGIS_DEBUGPY_HAS_LOADED"] = "1"

self.iface = iface
self.canvas = iface.mapCanvas()
self.nodes = None
Expand Down
7 changes: 7 additions & 0 deletions project/pg_service.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[pg_tww]
# Configuration for TEKSI development database in docker
host=localhost
port=5432
user=postgres
password=postgres
dbname=tww

0 comments on commit e1e6cca

Please sign in to comment.