Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add VS Code development environment #432

Merged
merged 8 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
},
]
}
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"qgis.installationRoot": "C:\\Program Files\\QGIS 3.34.10",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using OSGEO4W installer which is recommended by TEKSI, the path will be different.
eg : C:\OSGeo4W\bin\qgis-ltr-bin.exe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Should this recommendation be placed within the README.md as well?
The settings.json was intended as a template. User can overwrite the settings in vscode. See also comment in README.md:

  1. Install QGIS in Version 3.34.10 or adapt qgis.installationRoot in '.vscode/settings.json'.

If QGIS & Shell would be found on PATH on all Plattform, the configuration would be much simpler. Alternatively, if the required version / distribution of QGIS could be specified we would have the option to write a platform aware launch.json without using the "hacky" settings.json.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we adapt .vscode/settings.json will it not always show as modified in git status?

If QGIS & Shell would be found on PATH on all Plattform, the configuration would be much simpler.

Maybe the needed path could be defined in system variables. If not set, just use the most common variant (porbably windows/OSGeo4w ?).
Or providing the file as a settings.json.default to be renamed?

But I am not used to this kind of vscode configuration I don't now what's the best way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to use OSGeo4w as default in settings.json and adapting it to qgis.installationRoot.windows. If we run int in vscode the value either is correct, or the developer will get a message like "C:\OSGeo4w\qgis.bar was not found." I assume every developer will get a hint of what to do. OSGeo4w, in the optimal case, defines a link for the lates installed QGIS version to use. Corresponding linux variant can then be added as well.

The approuch should not depend on any environment variables defined from outside of VSCode as this break the whole concept of "no setup needed launch configuration".

"qgis.executable": "${config:qgis.installationRoot}\\bin\\qgis-ltr-bin.exe",
}
58 changes: 58 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
]
}
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <!--- // 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 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`
12 changes: 12 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,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
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