Skip to content

Commit

Permalink
Enforce 3.8 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dmarteau committed Oct 3, 2024
1 parent 1d0276f commit ec7a4f3
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ install-doc:
install-dev: install-tests install-doc

lint:
@ruff check $(PYTHON_PKG) $(TESTDIR)
@ruff check --output-format=concise $(PYTHON_PKG) $(TESTDIR)

lint-preview:
@ruff check --preview $(PYTHON_PKG) $(TESTDIR)
Expand Down
2 changes: 1 addition & 1 deletion examples/test-lizmap-server-plugin/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
map:
image: 3liz/qgis-map-server:3.34
image: 3liz/qgis-map-server:3.38-dev
environment:
QGSRV_LOGGING_LEVEL: debug
QGSRV_SERVER_PLUGINPATH: /srv/lizmap-plugin-server
Expand Down
9 changes: 5 additions & 4 deletions pyqgisserver/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
Literal,
Tuple,
TypeAlias,
Union,
)

from pyqgisservercontrib.core import componentmanager

ConfigValue: TypeAlias = str | bool | int | float
ConfigValue: TypeAlias = Union[str, bool, int, float]


getenv = os.getenv
Expand Down Expand Up @@ -274,11 +275,11 @@ def qgis_api_endpoints(enabled_only: bool = True) -> Iterator[Tuple[str, str]]:
if TYPE_CHECKING:
from mypy_extensions import DefaultNamedArg
ConfigValueGetter = Callable[
[str, str, DefaultNamedArg(str | NO_DEFAULT_TYPE, 'fallback')],
[str, str, DefaultNamedArg(Union[str, NO_DEFAULT_TYPE], 'fallback')],
ConfigValue,
]
else:
ConfigValueGetter = Callable[[str, str, str | NO_DEFAULT_TYPE], ConfigValue]
ConfigValueGetter = Callable[[str, str, Union[str, NO_DEFAULT_TYPE]], ConfigValue]


@componentmanager.register_factory('@3liz.org/config-service;1')
Expand All @@ -294,7 +295,7 @@ def __get_impl(
_get_fun: ConfigValueGetter,
section: str,
option: str,
fallback: ConfigValue | NO_DEFAULT_TYPE = NO_DEFAULT,
fallback: Union[ConfigValue, NO_DEFAULT_TYPE] = NO_DEFAULT,
) -> ConfigValue:
"""
"""
Expand Down
6 changes: 3 additions & 3 deletions pyqgisserver/handlers/asynchandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging

from time import time
from typing import Any, Dict, List, Optional, cast
from typing import Any, Dict, List, Optional, Union, cast
from urllib.parse import urlencode

from ..logger import log_rrequest
Expand Down Expand Up @@ -46,7 +46,7 @@ def initialize( # type: ignore [override]
self._stats = self.application.stats # type: ignore [attr-defined]
self._allowed_hdrs = allowed_hdrs

self.ogc_scheme: str | None = None
self.ogc_scheme: Union[str, None] = None

def encode_arguments(self) -> str:
return '?' + urlencode({k: v[0] for k, v in self.request.arguments.items()})
Expand Down Expand Up @@ -89,7 +89,7 @@ async def handle_request(self, method: str):

headers = {}
proxy_url = self.proxy_url()
req_url: str | None
req_url: Union[str, None]
if proxy_url:
# Send the full path to Qgis
req_url = f"{proxy_url}{self.request.path.lstrip('/')}"
Expand Down
4 changes: 2 additions & 2 deletions pyqgisserver/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import traceback

from pathlib import Path
from typing import Dict, Generator, TypeVar
from typing import Dict, Generator, TypeVar, Union

from .config import confservice

Expand Down Expand Up @@ -156,7 +156,7 @@ def plugin_metadata(plugin: str) -> Dict:
cp = configparser.ConfigParser()
cp.read_file(f)

metadata: Dict[str, str | Dict[str, str]] = {s: dict(p.items()) for s, p in cp.items()}
metadata: Dict[str, Union[str, Dict[str, str]]] = {s: dict(p.items()) for s, p in cp.items()}
metadata.pop('DEFAULT', None)
metadata.update(path=str(path))
return metadata
Expand Down
4 changes: 2 additions & 2 deletions pyqgisserver/qgscache/observers/ban.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import logging

from datetime import datetime
from typing import cast
from typing import Union, cast

from tornado.httpclient import AsyncHTTPClient, HTTPRequest

Expand All @@ -21,7 +21,7 @@
LOGGER = logging.getLogger('SRVLOG')

server_address: str
http_client: AsyncHTTPClient | None = None
http_client: Union[AsyncHTTPClient, None] = None


def init() -> None:
Expand Down
6 changes: 3 additions & 3 deletions pyqgisserver/qgspool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from glob import glob
from multiprocessing import Process
from multiprocessing.util import Finalize
from typing import Awaitable, Callable, Dict, List, cast
from typing import Awaitable, Callable, Dict, List, Union, cast

import psutil
import zmq
Expand All @@ -38,7 +38,7 @@
class _RestartHandler:

def __init__(self) -> None:
self._restart: None | Scheduler = None
self._restart: Union[None, Scheduler] = None
self._watch_files: List[str] = []

def update_files(self) -> None:
Expand Down Expand Up @@ -102,7 +102,7 @@ def __init__(

LOGGER.debug("Started pool server")
self._pool = pool
self._supervisor: Supervisor | None = None
self._supervisor: Union[Supervisor, None] = None
self._healthcheck = None

self._restart_handler = _RestartHandler()
Expand Down
20 changes: 13 additions & 7 deletions pyqgisserver/runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,19 @@ async def _main():
exit_code = 15
except SystemExit as exc:
print("Exiting with code:", exc.code, flush=True) # noqa: T201
match exc.code:
case int(code):
exit_code = code
case None:
exit_code = 0
case _:
exit_code = 1
# match exc.code:
# case int(code):
# exit_code = code
# case None:
# exit_code = 0
# case _:
# exit_code = 1
if exc.code is None:
exit_code = 0
elif isinstance(exc.code, int):
exit_code = exc.code
else:
exit_code = 1
else:
exit_code = 0

Expand Down
7 changes: 4 additions & 3 deletions pyqgisserver/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Dict,
Optional,
Self,
Union,
cast,
)

Expand Down Expand Up @@ -101,7 +102,7 @@ def __init__(self, http_response: HTTPResponse):
self.xml = lxml.etree.fromstring(self.content)

@property
def content(self) -> bytes | str:
def content(self) -> Union[bytes, str]:
return self.http_response.body

@property
Expand All @@ -123,7 +124,7 @@ def __init__(self, testcase: HTTPTestCase) -> None:

def post(
self,
data: bytes | str,
data: Union[bytes, str],
headers: Optional[Dict] = None,
path: str = '/ows/',
) -> HTTPTestResponse:
Expand Down Expand Up @@ -151,7 +152,7 @@ def get(
)

def put(self,
data: bytes | str,
data: Union[bytes, str],
headers: Optional[Dict] = None,
path: str = '/ows/',
) -> HTTPTestResponse:
Expand Down
3 changes: 2 additions & 1 deletion pyqgisserver/zeromq/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
Dict,
NamedTuple,
Optional,
Union,
)

import zmq
Expand Down Expand Up @@ -60,7 +61,7 @@ def __init__(self):
self._pid = os.getpid()
self._busy = False

def _send(self, data: bytes | _Report):
def _send(self, data: Union[bytes, _Report]):
if not self._sock:
return
try:
Expand Down
3 changes: 2 additions & 1 deletion pyqgisserver/zeromq/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Optional,
Protocol,
Type,
Union,
)

import zmq
Expand Down Expand Up @@ -115,7 +116,7 @@ def msgid(self):
return self._correlation_id

@property
def identity(self) -> bytes | str | int:
def identity(self) -> Union[bytes, str, int]:
return self._socket.identity

def handle_message(self):
Expand Down
20 changes: 15 additions & 5 deletions pyqgisservercontrib/core/componentmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"""

import logging
import sys

from collections import namedtuple
from importlib import metadata
Expand Down Expand Up @@ -46,12 +47,21 @@ class EntryPointNotFoundError(ComponentManagerError):
def _entry_points(group: str, name: Optional[str] = None) -> Sequence[metadata.EntryPoint]:
""" Return entry points
"""
# See https://docs.python.org/3.10/library/importlib.metadata.html
entry_points = metadata.entry_points()
if name:
return entry_points.select(group=group, name=name)
ver = sys.version_info[:2]
if ver >= (3, 10):
# See https://docs.python.org/3.10/library/importlib.metadata.html
entry_points = metadata.entry_points()
if name:
return entry_points.select(group=group, name=name)
else:
return entry_points.select(group=group)
else:
return entry_points.select(group=group)
# Return a dict
# see https://docs.python.org/3.8/library/importlib.metadata.html
eps = metadata.entry_points().get(group, []) # type: ignore [var-annotated]
if name:
eps = [ep for ep in eps if ep.name == name]
return eps


class ComponentManager:
Expand Down
3 changes: 3 additions & 0 deletions tests/setup_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SRCDIR=$(pwd) source tests/tests.env
export $(cut -d= -f1 tests/tests.env)
qgisserver

0 comments on commit ec7a4f3

Please sign in to comment.