Skip to content

Commit

Permalink
Remove unneeded code
Browse files Browse the repository at this point in the history
  • Loading branch information
azvoleff committed Nov 6, 2022
1 parent 7e79ca7 commit b32cb51
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 46 deletions.
10 changes: 10 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[flake8]
max-line-length = 88
extend-ignore = E203

exclude =
.tx,
build,
docker,
LDMP/ext-libs,
*.ipynb_checkpoints*
46 changes: 22 additions & 24 deletions LDMP/lc_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
email : [email protected]
***************************************************************************/
"""
from __future__ import annotations

import json
import os
import re
import typing
from copy import deepcopy
from enum import Enum
from pathlib import Path

from marshmallow.exceptions import ValidationError
Expand All @@ -25,7 +26,6 @@
from qgis.PyQt import QtGui
from qgis.PyQt import QtWidgets
from qgis.PyQt import uic
from qgis.utils import iface
from te_schemas.land_cover import LCClass
from te_schemas.land_cover import LCLegend
from te_schemas.land_cover import LCLegendNesting
Expand Down Expand Up @@ -1425,10 +1425,10 @@ class LandCoverSetupRemoteExecutionWidget(
def __init__(
self,
parent=None,
hide_min_year: typing.Optional[bool] = False,
hide_max_year: typing.Optional[bool] = False,
selected_min_year: typing.Optional[int] = 2001,
selected_max_year: typing.Optional[int] = 2015,
hide_min_year: bool | None = False,
hide_max_year: bool | None = False,
selected_min_year: int | None = 2001,
selected_max_year: int | None = 2015,
):
super().__init__(parent)
self.setupUi(self)
Expand Down Expand Up @@ -1480,9 +1480,7 @@ class LccInfoUtils:
CUSTOM_LEGEND_NAME = "Custom Land Cover"

@staticmethod
def save_settings(
lcc_infos: typing.List["LCClassInfo"] = [], restore_default=True
) -> bool:
def save_settings(lcc_infos: list[LCClassInfo] = [], restore_default=True) -> bool:
"""
Saves list of LCClassInfo objects to settings but if settings is
empty and 'restore_default' is True then it will restore the default
Expand All @@ -1504,9 +1502,9 @@ def save_settings(
lcc_str = LCClassInfo.Schema().dumps(lcc)
infos.append(lcc_str)
conf.settings_manager.write_value(conf.Setting.LC_CLASSES, infos)
except ValidationError as ve:
except ValidationError:
status = False
except Exception as exc:
except Exception:
status = False

# Update transition matrix and land cover nesting with our new custom
Expand All @@ -1522,7 +1520,7 @@ def save_settings(
return status

@staticmethod
def load_settings() -> typing.Tuple[bool, typing.List["LCClassInfo"]]:
def load_settings() -> tuple[bool, list[LCClassInfo]]:
"""
Loads LCCInfo objects from the settings.
"""
Expand All @@ -1535,26 +1533,26 @@ def load_settings() -> typing.Tuple[bool, typing.List["LCClassInfo"]]:
lcc_info = LCClassInfo.Schema().loads(lcc_info_str)
lcc_infos.append(lcc_info)

except ValidationError as ve:
except ValidationError:
status = False

except Exception as exc:
except Exception:
status = False

return status, lcc_infos

@staticmethod
def save_file(file_path: str, lcc_infos: typing.List["LCClassInfo"]) -> bool:
def save_file(file_path: str, lcc_infos: list[LCClassInfo]) -> bool:
# Saves the LC classes to JSON file.
lc_cls_infos = []
status = True
try:
for lcc in lcc_infos:
lcc_dict = LCClassInfo.Schema().dump(lcc)
lc_cls_infos.append(lcc_dict)
except ValidationError as ve:
except ValidationError:
status = False
except Exception as exc:
except Exception:
status = False

if not status:
Expand All @@ -1577,7 +1575,7 @@ def save_file(file_path: str, lcc_infos: typing.List["LCClassInfo"]) -> bool:
return True

@staticmethod
def load_file(file_path: str) -> typing.Tuple[bool, typing.List["LCClassInfo"]]:
def load_file(file_path: str) -> tuple[bool, list[LCClassInfo]]:
# Load classes from file.
fi = QtCore.QFileInfo(file_path)
cls_dir = fi.dir().path()
Expand Down Expand Up @@ -1608,8 +1606,8 @@ def load_file(file_path: str) -> typing.Tuple[bool, typing.List["LCClassInfo"]]:

@staticmethod
def lcc_in_infos(
lcc: LCClass, lcc_infos: typing.List["LCClassInfo"]
) -> typing.Tuple[bool, "LCClassInfo"]:
lcc: LCClass, lcc_infos: list[LCClassInfo]
) -> tuple[bool, LCClassInfo]:
"""
Checks if the given lc class is in the collection using
code to compare.
Expand All @@ -1632,7 +1630,7 @@ def lc_nesting() -> LCLegendNesting:
return nesting

@staticmethod
def sync_trans_matrix(ref_lcc_infos: typing.List["LCClassInfo"]):
def sync_trans_matrix(ref_lcc_infos: list[LCClassInfo]):
"""
Update transition matrix in settings with custom classes in the
reference list.
Expand Down Expand Up @@ -1713,7 +1711,7 @@ def sync_trans_matrix(ref_lcc_infos: typing.List["LCClassInfo"]):
)

@staticmethod
def save_lc_nesting_ipcc(ref_lcc_infos: typing.List["LCClassInfo"]):
def save_lc_nesting_ipcc(ref_lcc_infos: list[LCClassInfo]):
"""
Save IPCC land cover nesting to settings.
Expand Down Expand Up @@ -1775,7 +1773,7 @@ def save_lc_nesting_ipcc(ref_lcc_infos: typing.List["LCClassInfo"]):
)

@staticmethod
def save_lc_nesting_esa(ref_lcc_infos: typing.List["LCClassInfo"]):
def save_lc_nesting_esa(ref_lcc_infos: list[LCClassInfo]):
"""
Save ESA land cover nesting to settings.
Expand Down Expand Up @@ -1873,7 +1871,7 @@ def save_lc_nesting_esa(ref_lcc_infos: typing.List["LCClassInfo"]):
)

@staticmethod
def sync_lc_nesting(ref_lcc_infos: typing.List["LCClassInfo"]):
def sync_lc_nesting(ref_lcc_infos: list[LCClassInfo]):
"""
Updates both IPCC and ESA land cover nestings in settings.
"""
Expand Down
29 changes: 7 additions & 22 deletions LDMP/worker.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
"""
/***************************************************************************
LDMP - A QGIS plugin
This plugin supports monitoring and reporting of land degradation to the UNCCD
and in support of the SDG Land Degradation Neutrality (LDN) target.
-------------------
begin : 2017-05-23
git sha : $Format:%H$
copyright : (C) 2017 by Conservation International
email : [email protected]
***************************************************************************/
"""
from future import standard_library

standard_library.install_aliases()
import sys
import time

import qgis.gui
from qgis.utils import iface
from qgis.core import Qgis

from qgis.PyQt import QtCore
from qgis.PyQt.QtCore import QThread, Qt, QEventLoop, QCoreApplication
from qgis.PyQt.QtWidgets import QProgressBar, QPushButton
from qgis.PyQt.QtCore import QCoreApplication
from qgis.PyQt.QtCore import QEventLoop
from qgis.PyQt.QtCore import Qt
from qgis.PyQt.QtCore import QThread
from qgis.PyQt.QtWidgets import QProgressBar
from qgis.PyQt.QtWidgets import QPushButton
from qgis.utils import iface

from .logger import log

Expand Down

0 comments on commit b32cb51

Please sign in to comment.