From 14b557a400cc8b0351d29d8657d99f1b0f47967e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20L=C3=BCthi?= Date: Mon, 30 Sep 2024 18:20:10 +0200 Subject: [PATCH 1/8] Add editorconfig to define consistent formatting --- .editorconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..c1e2c6435 --- /dev/null +++ b/.editorconfig @@ -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 From 7018c857ea66e8ab682c316438289aadf747706c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20L=C3=BCthi?= Date: Mon, 30 Sep 2024 18:22:43 +0200 Subject: [PATCH 2/8] Add VS Code Development environment --- .vscode/extensions.json | 13 +++++++++ .vscode/launch.json | 21 +++++++++++++++ .vscode/settings.json | 4 +++ .vscode/tasks.json | 58 +++++++++++++++++++++++++++++++++++++++++ README.md | 25 ++++++++++++++++++ project/pg_service.conf | 7 +++++ 6 files changed, 128 insertions(+) create mode 100644 .vscode/extensions.json create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json create mode 100644 project/pg_service.conf diff --git a/.vscode/extensions.json b/.vscode/extensions.json new file mode 100644 index 000000000..75e60f9b2 --- /dev/null +++ b/.vscode/extensions.json @@ -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": [ + + ] +} diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..655be32b6 --- /dev/null +++ b/.vscode/launch.json @@ -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 + }, + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..2a12df40f --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "qgis.installationRoot": "C:\\Program Files\\QGIS 3.34.10", + "qgis.executable": "${config:qgis.installationRoot}\\bin\\qgis-ltr-bin.exe", +} diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..82fbbd75a --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,58 @@ +{ + // 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\"", + "options": { + "shell": { + "executable": "${config:qgis.installationRoot}\\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", + "command": "${config:qgis.executable}", + "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" + } + } + } + ] +} diff --git a/README.md b/README.md index 5d7ff6c0d..f811f1f7c 100644 --- a/README.md +++ b/README.md @@ -17,3 +17,28 @@ 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. + +## 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 in Version 3.34.10 or adapt `qgis.installationRoot` in ['.vscode/settings.json'.](.vscode/settings.json) +4. Install Docker +5. Install debugpy by running Task `Install dependencies` or run `pip install debugpy` in the OSGeo4W Shell. +6. Launch QGIS with Task `Launch QGIS`. +7. Wait for QGIS to start and open the plugin in QGIS. +8. Attach the debugger with Debug: Start Debugging (F5) with configuration `Python: Remote Attach` diff --git a/project/pg_service.conf b/project/pg_service.conf new file mode 100644 index 000000000..ad5100318 --- /dev/null +++ b/project/pg_service.conf @@ -0,0 +1,7 @@ +[pg_tww] +# Konfiguration für TEKSI-Entwicklungsdatenbank in docker +host=localhost +port=5432 +user=postgres +password=postgres +dbname=tww From 6b2baa88c5e7ace399fffb768b07c42134e2d2d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20L=C3=BCthi?= Date: Wed, 2 Oct 2024 15:31:59 +0200 Subject: [PATCH 3/8] Use english for comments Co-authored-by: Arnaud Poncet-Montanges --- project/pg_service.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/pg_service.conf b/project/pg_service.conf index ad5100318..0b96cb73c 100644 --- a/project/pg_service.conf +++ b/project/pg_service.conf @@ -1,5 +1,5 @@ [pg_tww] -# Konfiguration für TEKSI-Entwicklungsdatenbank in docker +# Configuration for TEKSI development database in docker host=localhost port=5432 user=postgres From fa8850c701579723cb9d278dc067dc110819184b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20L=C3=BCthi?= Date: Wed, 2 Oct 2024 15:54:44 +0200 Subject: [PATCH 4/8] Start debugpy debug server --- plugin/teksi_wastewater/teksi_wastewater_plugin.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugin/teksi_wastewater/teksi_wastewater_plugin.py b/plugin/teksi_wastewater/teksi_wastewater_plugin.py index 8a33cbc08..ea95064a2 100644 --- a/plugin/teksi_wastewater/teksi_wastewater_plugin.py +++ b/plugin/teksi_wastewater/teksi_wastewater_plugin.py @@ -26,6 +26,7 @@ import logging import os +import shutil from qgis.core import Qgis, QgsApplication from qgis.PyQt.QtCore import QLocale, QSettings, Qt @@ -82,6 +83,17 @@ class TeksiWastewaterPlugin: profile = None def __init__(self, iface): + if os.environ.get("QGIS_DEBUGPY_HAS_LOADED") is None: + 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 From b989b5f7fcde9472acfdf106ab828df052310fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20L=C3=BCthi?= Date: Tue, 15 Oct 2024 19:19:17 +0200 Subject: [PATCH 5/8] Remove settings.json and define OS specific executables --- .vscode/settings.json | 4 ---- .vscode/tasks.json | 15 +++++++++++---- README.md | 6 +++--- 3 files changed, 14 insertions(+), 11 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 2a12df40f..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "qgis.installationRoot": "C:\\Program Files\\QGIS 3.34.10", - "qgis.executable": "${config:qgis.installationRoot}\\bin\\qgis-ltr-bin.exe", -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 82fbbd75a..4bc189dd9 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -7,9 +7,11 @@ "label": "Install dependencies", "type": "shell", "command": "pip install debugpy \"sqlalchemy~=1.3.22\" \"geoalchemy2>=0.9.0\"", - "options": { - "shell": { - "executable": "${config:qgis.installationRoot}\\OSGeo4W.bat" + "windows": { + "options": { + "shell": { + "executable": "C:\\OSGeo4W\\OSGeo4W.bat" + } } }, "problemMatcher": [] @@ -33,7 +35,6 @@ { "label": "Launch QGIS", "type": "process", - "command": "${config:qgis.executable}", "args": [ "--project", "${workspaceFolder}\\project\\teksi_wastewater.qgs" @@ -52,6 +53,12 @@ "QGIS_PLUGIN_USE_DEBUGGER": "debugpy", "PGSERVICEFILE": "${workspaceFolder}\\project\\pg_service.conf" } + }, + "windows": { + "command": "C:\\OSGeo4W\\bin\\qgis-ltr-bin.exe" + }, + "linux": { + "command": "qgis-ltr" } } ] diff --git a/README.md b/README.md index f811f1f7c..04632555b 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ Migration path from QGEP to TEKSI Wastewater is due to end of summer 2024.