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

Plugin #23

Merged
merged 18 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Define POSTGRES PORT for Docker when calling datamodel/scripts/run-docker.sh
TWW_PG_PORT=5432

QGIS_TEST_VERSION

# fix access rights for schemaspy
UID=1000
GID=1001
54 changes: 54 additions & 0 deletions .github/workflows/plugin-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: 🔌 Plugin | Package and release

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches:
- main
pull_request:
branches:
- main
paths:
- plugin/**
- '.github/workflows/datamodel-create-dumps.yml'
workflow_dispatch:


jobs:
plugin-package:
name: Packages and releases plugin
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'

- name: Install qgis-plugin-ci
run: pip install qgis-plugin-ci>=2.8.6

- name: Package PyPI Packages
run: ./plugin/scripts/package-pip-packages.sh

- name: Download Interlis libs
run: ./plugin/scripts/download-interlis-libs.sh

- name: Package
run: |
VERSION=0.0.0
qgis-plugin-ci -v package ${VERSION} \
--allow-uncommitted-changes \
--asset-path plugin/teksi_wastewater/libs \
--asset-path plugin/teksi_wastewater/interlis/bin

- uses: actions/upload-artifact@v3
with:
name: teksi_wastewater_plugin_dev
path: plugin/teksi_wastewater.0.0.0.zip
if-no-files-found: error
57 changes: 57 additions & 0 deletions .github/workflows/plugin-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: 🪲 Plugin | Tests

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

on:
push:
branches:
- main
paths:
- datamodel/**
- plugin/**
- '.github/workflows/plugin-test.yml'
pull_request:
branches:
- main
paths:
- datamodel/**
- plugin/**
- '.github/workflows/plugin-test.yml'
workflow_dispatch:


jobs:
plugin-tests:
name: Run unit tests on plugin
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
qgis_version: [3.28-jammy, latest]
env:
QGIS_TEST_VERSION: ${{ matrix.qgis_version }}
COMPOSE_PROFILES: qgis

steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive

- name: Package PyPI Packages
run: sudo ./plugin/scripts/package-pip-packages.sh

- name: Download Interlis libs
run: sudo ./plugin/scripts/download-interlis-libs.sh

- name: Docker build
run: docker compose up -d --build

- name: Test on QGIS
run: docker-compose run qgis /usr/src/.docker/run-docker-tests.sh
domi4484 marked this conversation as resolved.
Show resolved Hide resolved

- name: docker logs
#if: failure()
run: docker compose logs db
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ datamodel/artifacts
project/*attachments.zip
project/*.qgs~

plugin/teksi_wastewater/libs/
plugin/teksi_wastewater/interlis/bin
plugin*.zip
plugin*.tar.gz

.idea
.pycache
__pycache__
.DS_Store
3 changes: 3 additions & 0 deletions .qgis-plugin-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugin_path: plugin/teksi_wastewater
github_organization_slug: TEKSI
project_slug: wastewater
14 changes: 14 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ services:
# making the postgres database accessible for debugging
- ${TWW_PG_PORT:-5432}:${TWW_PG_PORT:-5432}

qgis:
build:
context: .
dockerfile: plugin/.docker/Dockerfile
args:
QGIS_TEST_VERSION: ${QGIS_TEST_VERSION:-latest}
tty: true
volumes:
- ./plugin:/usr/src
links:
- db
profiles:
- qgis

schemaspy:
image: schemaspy/schemaspy
volumes:
Expand Down
14 changes: 14 additions & 0 deletions plugin/.docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG QGIS_TEST_VERSION=latest
FROM opengisch/qgis:${QGIS_TEST_VERSION}

# remove QGIS apt repo to avoid signing key issues
RUN add-apt-repository -r https://qgis.org/ubuntu && \
add-apt-repository -r https://qgis.org/ubuntu-ltr

RUN apt-get update && \
apt-get -y install openjdk-8-jre curl locales postgresql-client python3-geoalchemy2 \
&& rm -rf /var/lib/apt/lists/*

ENV LANG=C.UTF-8

WORKDIR /
24 changes: 24 additions & 0 deletions plugin/.docker/run-docker-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
#***************************************************************************
# -------------------
# begin : 2017-08-24
# git sha : :%H$
# copyright : (C) 2017 by OPENGIS.ch
# email : [email protected]
#***************************************************************************
#
#***************************************************************************
#* *
#* This program is free software; you can redistribute it and/or modify *
#* it under the terms of the GNU General Public License as published by *
#* the Free Software Foundation; either version 2 of the License, or *
#* (at your option) any later version. *
#* *
#***************************************************************************

set -e

pushd /usr/src
DEFAULT_PARAMS='-v'
xvfb-run pytest-3 ${@:-`echo $DEFAULT_PARAMS`} $1
popd
1 change: 0 additions & 1 deletion plugin/README.md

This file was deleted.

4 changes: 4 additions & 0 deletions plugin/scripts/download-interlis-libs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash

wget https://github.com/teksi/wastewater/archive/refs/tags/plugin-ili-libs-1.tar.gz
tar xvzf plugin-ili-libs-1.tar.gz --strip-components=1
31 changes: 31 additions & 0 deletions plugin/scripts/package-pip-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

LIBS_DIR="plugin/teksi_wastewater/libs"

MODELBAKER_LIBRARY=("modelbaker" "1.6.0")

PACKAGES=(
MODELBAKER_LIBRARY[@]
)

#create lib folder
mkdir -p $LIBS_DIR

for PACKAGE in ${PACKAGES[@]}; do
echo download and unpack ${!PACKAGE:0:1} with version ${!PACKAGE:1:1}
#create temp folder
mkdir -p temp
#download the wheel
pip download -v ${!PACKAGE:0:1}==${!PACKAGE:1:1} --only-binary :all: -d temp/
#unpack all the wheels found (means including dependencies)
unzip -o "temp/*.whl" -d $LIBS_DIR
#remove temp folder
rm -r temp
#set write rights to group (because qgis-plugin-ci needs it)
chmod -R g+w $LIBS_DIR
done

#create the __init__.py in libs folder
cd $LIBS_DIR
touch __init__.py
chmod g+w __init__.py
11 changes: 11 additions & 0 deletions plugin/scripts/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

# Arguments are passed one to one to pytest
#
# Run all tests:
# ./scripts/run-tests.sh # Run all tests
#
# Run all test starting with test_array_
# ./scripts/run-tests.sh -k test_array_

docker-compose run qgis /usr/src/.docker/run-docker-tests.sh $@
29 changes: 29 additions & 0 deletions plugin/teksi_wastewater/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -----------------------------------------------------------
#
# TEKSI Wastewater
# Copyright (C) 2012 Matthias Kuhn
# -----------------------------------------------------------
#
# licensed under the terms of GNU GPL 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# ---------------------------------------------------------------------


def classFactory(iface):
from .teksi_wastewater_plugin import TeksiWastewaterPlugin

return TeksiWastewaterPlugin(iface)
Empty file.
51 changes: 51 additions & 0 deletions plugin/teksi_wastewater/gui/dlgabout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# -----------------------------------------------------------
#
# Profile
# Copyright (C) 2012 Patrice Verchere
# -----------------------------------------------------------
#
# licensed under the terms of GNU GPL 2
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, print to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# ---------------------------------------------------------------------

import os

from qgis.PyQt.QtCore import QSettings
from qgis.PyQt.QtWidgets import QDialog

from ..utils import get_ui_class

DIALOG_UI = get_ui_class("dlgabout.ui")


class DlgAbout(QDialog, DIALOG_UI):
def __init__(self, parent=None):
QDialog.__init__(self, parent)
self.setupUi(self)

fp = os.path.join(
os.path.abspath(os.path.join(os.path.dirname(__file__), "..")),
"metadata.txt",
)

ini_text = QSettings(fp, QSettings.IniFormat)
verno = ini_text.value("version")
name = ini_text.value("name")
description = ini_text.value("description")

self.title.setText(name)
self.description.setText(description + " - " + verno)
26 changes: 26 additions & 0 deletions plugin/teksi_wastewater/gui/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import qgis
from qgis.core import QgsProject

from ..tools.twwmaptooladdfeature import TwwMapToolDigitizeDrainageChannel


def geometryDigitized(fid, layer, tool):
layer.changeGeometry(fid, tool.geometry)
layer.triggerRepaint()
tool.deactivate()


def mapToolDeactivated(tool):
tool.deactivated.disconnect()
qgis.utils.plugins["teksi_wastewater"].iface.mapCanvas().unsetMapTool(tool)
tool.deleteLater()


def digitizeDrainageChannel(fid, layerid):
layer = QgsProject.instance().mapLayer(layerid)
layer.startEditing()
tool = TwwMapToolDigitizeDrainageChannel(qgis.utils.plugins["teksi_wastewater"].iface, layer)
qgis.utils.plugins["teksi_wastewater"].iface.mapCanvas().setMapTool(tool)
tool.geometryDigitized.connect(lambda: geometryDigitized(fid, layer, tool))
# form.window().hide()
tool.deactivated.connect(lambda: mapToolDeactivated(tool))
Loading
Loading