Skip to content
Open
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: 1 addition & 1 deletion .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
services:
qgis:
user: ${UID}:${GID}
image: ${QGIS_IMAGE_TAG}
user: ${UID}:${GID}
network_mode: host
container_name: qgis-lizmap-tests
environment:
Expand Down
2 changes: 2 additions & 0 deletions .docker/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ python3 -m venv $VENV --system-site-package
echo "Installing requirements..."
$VENV/bin/pip install -q --no-cache -r requirements/tests.txt

export PYTHONPATH="/usr/share/qgis/python/:$PYTHONPATH"

cd tests && $VENV/bin/python -m pytest -v


5 changes: 3 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ jobs:
python-version: "3.12"
architecture: x64
cache: "pip"
cache-dependency-path: "requirements/dev.txt"
cache-dependency-path: "requirements/lint.txt"

- name: Install Python requirements
run: pip install --quiet -r requirements/lint.txt

- name: Run linter
run: ruff check --preview --output-format=concise lizmap
run: ruff check --output-format=concise lizmap

- name: Run security check
run: bandit -r lizmap -ll
Expand All @@ -39,6 +39,7 @@ jobs:
"3.34",
"3.40",
"3.44",
"4.0",
]
steps:

Expand Down
46 changes: 44 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,58 @@ variables:

stages:
- lint
- test
- build
- deploy

# ------------
# Lint
# ------------

lint:
image: $REGISTRY_URI/factory-ci-runner:qgis-ltr
stage: lint
image: ${REGISTRY_URL}/factory-ci-runner:qgis-${QGIS_FLAVOR}
tags:
- factory-plain
stage: lint
script:
# No need since we do not type checking atm
#- pip install --quiet -r requirements/dev.txt
- make lint
parallel:
matrix:
- QGIS_FLAVOR: [ "ltr", "release" ]

# ------------
# Tests
# ------------

.tests:
image: ${REGISTRY_URL}/factory-ci-runner:factory-ci
tags:
- factory-dind
stage: test
script:
- make docker-test QGIS_VERSION=$QGIS_FLAVOR

qgis-tests:
extends: .tests
parallel:
matrix:
- QGIS_FLAVOR: [
"3.34",
"3.40",
"3.44",
"4.0",
]


# NOTE: Following jobs are triggered only on RELEASE_BRANCH == "true"

#
# Packages
#

>>>>>>> 6c46c59 (Fix tests)

build:
image: $REGISTRY_URI/factory-ci-runner:qgis-plugin-ci
Expand Down
83 changes: 57 additions & 26 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ SHELL:=bash

PYTHON_MODULE=lizmap

QGIS_VERSION ?= 3.40

-include .localconfig.mk

Expand All @@ -17,7 +16,7 @@ ifdef VIRTUAL_ENV
# Always prefer active environment
ACTIVE_VENV=--active
endif
UV_RUN=uv run $(ACTIVE_VENV)
UV=uv run $(ACTIVE_VENV)
endif


Expand All @@ -32,13 +31,6 @@ REQUIREMENTS_GROUPS= \

REQUIREMENTS=$(patsubst %, requirements/%.txt, $(REQUIREMENTS_GROUPS))

# Update only packaging dependencies
# Waiting for https://github.com/astral-sh/uv/issues/13705
update-packaging-dependencies::
uv lock -P qgis-plugin-package-ci -P qgis-plugin-transifex-ci

update-packaging-dependencies:: update-requirements

update-requirements: $(REQUIREMENTS)

# Require uv (https://docs.astral.sh/uv/) for extracting
Expand All @@ -56,53 +48,92 @@ requirements/%.txt: uv.lock
# Static analysis
#

LINT_TARGETS=$(PYTHON_MODULE) tests $(EXTRA_LINT_TARGETS)
LINT_TARGETS=$(PYTHON_MODULE) $(EXTRA_LINT_TARGETS)

lint:
@ $(UV_RUN) ruff check --output-format=concise $(LINT_TARGETS)
@ $(UV) ruff check --output-format=concise $(LINT_TARGETS)
@ $(UV) ruff check --output-format=concise --target-version=py310 tests

lint-fix:
@ $(UV_RUN) ruff check --fix $(LINT_TARGETS)
@ $(UV) ruff check --fix $(LINT_TARGETS)
@ $(UV) ruff check --fix --target-version=py310 tests

lint-preview:
@ $(UV) ruff check --preview --output-format=concise $(LINT_TARGETS)

format:
@ $(UV_RUN) ruff format $(LINT_TARGETS)
@ $(UV) ruff format $(LINT_TARGETS)

typecheck:
$(UV_RUN) mypy $(PYTHON_MODULE)
$(UV) mypy $(PYTHON_MODULE)
$(UV) mypy tests --python-version 3.10

scan:
@ $(UV_RUN) bandit -r $(PYTHON_MODULE) $(SCAN_OPTS)
@ $(UV) bandit -r $(PYTHON_MODULE) $(SCAN_OPTS)


check-uv-install:
@which uv > /dev/null || { \
echo "You must install uv (https://docs.astral.sh/uv/)"; \
exit 1; \
}

#
# Tests
#

test:
$(UV_RUN) pytest -v tests/
$(UV) pytest -v tests/

#
# Test using docker image
#
QGIS_IMAGE_REPOSITORY ?= qgis/qgis

ifdef REGISTRY_URL
REGISTRY_PREFIX=$(REGISTRY_URL)/
else
REGISTRY_PREFIX=3liz/
endif

QGIS_VERSION ?= 3.44
QGIS_IMAGE_REPOSITORY ?= ${REGISTRY_PREFIX}qgis-platform
QGIS_IMAGE_TAG ?= $(QGIS_IMAGE_REPOSITORY):$(QGIS_VERSION)

export QGIS_VERSION
export QGIS_IMAGE_TAG
export UID=$(shell id -u)
export GID=$(shell id -g)

docker-test:
cd .docker && docker compose up \
set -e; \
cd .docker; \
docker compose up \
--quiet-pull \
--abort-on-container-exit \
--exit-code-from qgis
cd .docker && docker compose down -v
--exit-code-from qgis; \
docker compose down -v;

#
# Install/sync
#

sync:
@echo "Synchronizing python's environment with frozen dependencies"
uv sync --all-groups --frozen --all-extras

install-dev::
@echo "Creating virtual python environment"
uv venv --system-site-packages --no-managed-python

install-dev:: sync

#
# Coverage
#

# Run tests coverage
covtests:
@echo "Running coverage tests"
@ $(UV) coverage run -m pytest tests/

coverage: covtests
@echo "Building coverage html"
@ $(UV) coverage html


#
# Code managment
Expand Down
11 changes: 4 additions & 7 deletions lizmap/dialogs/dock_html_preview.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""
__copyright__ = 'Copyright 2023, 3Liz'
__license__ = 'GPL version 3'
__email__ = 'info@3liz.org'

import logging

"""
from qgis.core import (
QgsApplication,
QgsExpression,
Expand All @@ -26,10 +25,8 @@
)
from qgis.utils import iface

from lizmap.toolbelt.i18n import tr
from lizmap.toolbelt.resources import resources_path

LOGGER = logging.getLogger('Lizmap')
from ..toolbelt.i18n import tr
from ..toolbelt.resources import resources_path

# Detect available Web widget
WEBKIT_AVAILABLE = False
Expand Down
11 changes: 4 additions & 7 deletions lizmap/dialogs/html_editor.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
"""
__copyright__ = 'Copyright 2023, 3Liz'
__license__ = 'GPL version 3'
__email__ = 'info@3liz.org'

import logging

"""
from qgis.core import QgsVectorLayer
from qgis.PyQt.QtWidgets import QDialog, QDialogButtonBox, QVBoxLayout

from lizmap.toolbelt.i18n import tr
from lizmap.widgets.html_editor import HtmlEditorWidget

LOGGER = logging.getLogger('Lizmap')
from ..toolbelt.i18n import tr
from ..widgets.html_editor import HtmlEditorWidget


class HtmlEditorDialog(QDialog):
Expand Down
37 changes: 16 additions & 21 deletions lizmap/dialogs/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from __future__ import annotations

import logging

from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import Any

from qgis.core import (
Qgis,
Expand All @@ -29,6 +25,7 @@
QPushButton,
QSizePolicy,
QSpacerItem,
QWidget,
)
from qgis.utils import OverrideCursor, iface

Expand Down Expand Up @@ -64,15 +61,17 @@
simplify_provider_side,
use_estimated_metadata,
)
from lizmap.qt_style_sheets import COMPLETE_STYLE_SHEET
from lizmap.saas import fix_ssl, is_lizmap_cloud
from lizmap.table_manager.upload_files import TableFilesManager
from lizmap.toolbelt.i18n import tr
from lizmap.toolbelt.layer import relative_path
from lizmap.toolbelt.resources import load_ui, resources_path
from lizmap.toolbelt.strings import human_size
from lizmap.toolbelt.version import qgis_version_info
from lizmap.widgets.check_project import Checks, Headers, TableCheck

from .. import logger
from ..qt_style_sheets import COMPLETE_STYLE_SHEET
from ..saas import fix_ssl, is_lizmap_cloud
from ..table_manager.upload_files import TableFilesManager
from ..toolbelt.i18n import tr
from ..toolbelt.layer import relative_path
from ..toolbelt.resources import load_ui, resources_path
from ..toolbelt.strings import human_size
from ..toolbelt.version import qgis_version_info
from ..widgets.check_project import Checks, Headers, TableCheck

WEBKIT_AVAILABLE = False
try:
Expand All @@ -94,12 +93,8 @@
WEB_ENGINE = False
WEBKIT_AVAILABLE = False

if TYPE_CHECKING:
from qgis.PyQt.QtWidgets import QWidget


FORM_CLASS = load_ui('ui_lizmap.ui')
LOGGER = logging.getLogger("Lizmap")


class LizmapDialog(QDialog, FORM_CLASS):
Expand Down Expand Up @@ -734,7 +729,7 @@ def check_qgis_version(self, message_bar: bool = False, widget: bool = False) ->
return False

title = tr('QGIS server version is lower than QGIS desktop version')
LOGGER.error(title)
logger.error(title)

description = tr('Your QGIS desktop is writing QGS project in the future compare to QGIS server.')

Expand Down Expand Up @@ -1373,7 +1368,7 @@ def select_unknown_features_group(self):
")"
)
layer.removeSelection()
LOGGER.debug("Expression used for checking groups not on the server :\n" + expression)
logger.debug("Expression used for checking groups not on the server :\n" + expression)
layer.selectByExpression(expression)
count = layer.selectedFeatureCount()
self.display_message_bar(
Expand Down Expand Up @@ -1429,5 +1424,5 @@ def activateWindow(self):
""" When the dialog displayed, to trigger functions in the plugin when the dialog is opening. """
self.check_project_thumbnail()
self.check_action_file_exists()
LOGGER.info("Opening the Lizmap dialog.")
logger.info("Opening the Lizmap dialog.")
super().activateWindow()
Loading
Loading