Skip to content

Commit

Permalink
refacto: rm typing_extensions from deps replacing by future.annotatio…
Browse files Browse the repository at this point in the history
…ns (#441)
  • Loading branch information
Guts authored Feb 28, 2024
2 parents f546ab6 + e7b2142 commit b6009b7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 27 deletions.
25 changes: 10 additions & 15 deletions qgis_deployment_toolbelt/plugins/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
# ########## Libraries #############
# ##################################

# special
from __future__ import annotations

# Standard library
import configparser
Expand All @@ -20,7 +22,6 @@
from enum import Enum
from os.path import expanduser, expandvars
from pathlib import Path
from sys import version_info
from urllib.parse import quote, urlsplit, urlunsplit

# 3rd party
Expand All @@ -30,12 +31,6 @@
from qgis_deployment_toolbelt.utils.check_path import check_path
from qgis_deployment_toolbelt.utils.slugger import sluggy

# Imports depending on Python version
if version_info[1] < 11:
from typing_extensions import Self
else:
from typing import Self

# #############################################################################
# ########## Globals ###############
# ##################################
Expand Down Expand Up @@ -80,14 +75,14 @@ class QgisPlugin:
version: str = "latest"

@classmethod
def from_dict(cls, input_dict: dict) -> Self:
def from_dict(cls, input_dict: dict) -> QgisPlugin:
"""Create object from a dictionary.
Args:
input_dict (dict): input dictionary
Returns:
Self: instanciated object
QgisPlugin: instanciated object
"""
# map attributes names
for k, v in cls.ATTR_MAP.items():
Expand Down Expand Up @@ -129,14 +124,14 @@ def from_dict(cls, input_dict: dict) -> Self:
)

@classmethod
def from_plugin_folder(cls, input_plugin_folder: Path) -> Self:
def from_plugin_folder(cls, input_plugin_folder: Path) -> QgisPlugin:
"""Create object from a QGIS plugin folder. Must contain a metadata.txt file.
Args:
input_plugin_folder (Path): path to the folder containgin a QGIS plugin
Returns:
Self: instanciated object
QgisPlugin: instanciated object
"""
# check that input path is a folder
check_path(
Expand Down Expand Up @@ -167,14 +162,14 @@ def from_plugin_folder(cls, input_plugin_folder: Path) -> Self:
return cls.from_dict(plugin_md_as_dict)

@classmethod
def from_zip(cls, input_zip_path: Path) -> Self:
def from_zip(cls, input_zip_path: Path) -> QgisPlugin:
"""Create object from a ZIP file.
Args:
input_zip_path (Path): filepath of the input zip
Returns:
Self: instanciated object
QgisPlugin: instanciated object
"""
with zipfile.ZipFile(file=input_zip_path) as zf:
# find the metadata.txt file
Expand Down Expand Up @@ -254,12 +249,12 @@ def installation_folder_name(self) -> str:
else:
return sluggy(self.name)

def is_older_than(self, version_to_compare: str | Self) -> bool:
def is_older_than(self, version_to_compare: str | QgisPlugin) -> bool:
"""Determine if the actual object version is older than the given version to \
compare.
Args:
version_to_compare (Union[str, Self]): given version to compare with object version
version_to_compare (Union[str, QgisPlugin]): given version to compare with object version
Returns:
bool: True if the given version is newer (more recent)
Expand Down
18 changes: 7 additions & 11 deletions qgis_deployment_toolbelt/profiles/qdt_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,15 @@
# ########## Libraries #############
# ##################################

# special
from __future__ import annotations

# standard
import json
import logging
from pathlib import Path
from sys import version_info
from typing import Literal

# Imports depending on Python version
if version_info[1] < 11:
from typing_extensions import Self
else:
from typing import Self

# 3rd party
from packaging.version import InvalidVersion, Version

Expand Down Expand Up @@ -135,7 +131,7 @@ def __init__(
@classmethod
def from_json(
cls, profile_json_path: Path, profile_folder: Path | None = None
) -> "QdtProfile":
) -> QdtProfile:
"""Load profile from a profile.json file.
Args:
Expand Down Expand Up @@ -301,12 +297,12 @@ def version(self) -> str:
"""
return self._version

def is_older_than(self, version_to_compare: str | Self) -> bool:
def is_older_than(self, version_to_compare: str | QdtProfile) -> bool:
"""Determine if the actual object version is older than the given version to
compare.
Args:
version_to_compare (Union[str, Self]): given version to compare with object
version_to_compare (Union[str, QdtProfile]): given version to compare with object
version
Returns:
Expand Down Expand Up @@ -373,7 +369,7 @@ def status(self) -> Literal["downloaded", "installed", "unknown"]:
return "unknown"

@property
def installed_profile(self) -> "QdtProfile | None":
def installed_profile(self) -> QdtProfile | None:
"""Returns the installed profile object only if the corresponding profiles.json
exists.
Expand Down
1 change: 0 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ packaging>=20,<24
pyyaml>=5.4,<7
pywin32==306 ; sys_platform == 'win32'
requests>=2.31,<3
typing-extensions>=4,<5 ; python_version < '3.11'

0 comments on commit b6009b7

Please sign in to comment.