Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Sep 25, 2024
1 parent eb353b4 commit 1ff33c8
Show file tree
Hide file tree
Showing 30 changed files with 187 additions and 562 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ repos:

ci:
autofix_prs: true
autoupdate_schedule: quarterly
autoupdate_schedule: quarterly
1 change: 0 additions & 1 deletion qgepplugin/gui/dlgabout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------
#
# Profile
Expand Down
4 changes: 1 addition & 3 deletions qgepplugin/gui/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def mapToolDeactivated(tool):
def digitizeDrainageChannel(fid, layerid):
layer = QgsProject.instance().mapLayer(layerid)
layer.startEditing()
tool = QgepMapToolDigitizeDrainageChannel(
qgis.utils.plugins["qgepplugin"].iface, layer
)
tool = QgepMapToolDigitizeDrainageChannel(qgis.utils.plugins["qgepplugin"].iface, layer)
qgis.utils.plugins["qgepplugin"].iface.mapCanvas().setMapTool(tool)
tool.geometryDigitized.connect(lambda: geometryDigitized(fid, layer, tool))
# form.window().hide()
Expand Down
127 changes: 35 additions & 92 deletions qgepplugin/gui/qgepdatamodeldialog.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------
#
# Profile
Expand Down Expand Up @@ -93,15 +92,15 @@
PG_CONFIG_PATH = "~/.pg_service.conf"
else:
PG_CONFIG_PATH_KNOWN = False
PG_CONFIG_PATH = os.path.join(
QgsApplication.qgisSettingsDirPath(), "pg_service.conf"
)
PG_CONFIG_PATH = os.path.join(QgsApplication.qgisSettingsDirPath(), "pg_service.conf")

# Derived urls/paths, may require adaptations if release structure changes
DATAMODEL_URL_TEMPLATE = "https://github.com/QGEP/datamodel/archive/{}.zip"
REQUIREMENTS_PATH_TEMPLATE = os.path.join(TEMP_DIR, "datamodel-{}", "requirements.txt")
DELTAS_PATH_TEMPLATE = os.path.join(TEMP_DIR, "datamodel-{}", "delta")
INIT_SCRIPT_URL_TEMPLATE = "https://github.com/QGEP/datamodel/releases/download/{}/qgep_{}_structure_with_value_lists.sql"
INIT_SCRIPT_URL_TEMPLATE = (
"https://github.com/QGEP/datamodel/releases/download/{}/qgep_{}_structure_with_value_lists.sql"
)
QGEP_PROJECT_PATH_TEMPLATE = os.path.join(TEMP_DIR, "project", "qgep.qgs")


Expand Down Expand Up @@ -129,9 +128,7 @@ def __init__(self, cur_name, cur_config, taken_names):
self.taken_names = taken_names
self.nameLineEdit.textChanged.connect(self.check_name)
self.pgconfigUserCheckBox.toggled.connect(self.pgconfigUserLineEdit.setEnabled)
self.pgconfigPasswordCheckBox.toggled.connect(
self.pgconfigPasswordLineEdit.setEnabled
)
self.pgconfigPasswordCheckBox.toggled.connect(self.pgconfigPasswordLineEdit.setEnabled)

self.nameLineEdit.setText(cur_name)
self.pgconfigHostLineEdit.setText(cur_config.get("host", ""))
Expand All @@ -150,14 +147,10 @@ def __init__(self, cur_name, cur_config, taken_names):
def check_name(self, new_text):
if new_text in self.taken_names:
self.nameCheckLabel.setText("will overwrite")
self.nameCheckLabel.setStyleSheet(
"color: rgb(170, 95, 0);\nfont-weight: bold;"
)
self.nameCheckLabel.setStyleSheet("color: rgb(170, 95, 0);\nfont-weight: bold;")
else:
self.nameCheckLabel.setText("will be created")
self.nameCheckLabel.setStyleSheet(
"color: rgb(0, 170, 0);\nfont-weight: bold;"
)
self.nameCheckLabel.setStyleSheet("color: rgb(0, 170, 0);\nfont-weight: bold;")

def conf_name(self):
return self.nameLineEdit.text()
Expand Down Expand Up @@ -202,9 +195,7 @@ def __init__(self, parent=None):
# Show the pgconfig path
path_label = PG_CONFIG_PATH
if not PG_CONFIG_PATH_KNOWN:
self.pgservicePathLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-style: italic;"
)
self.pgservicePathLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-style: italic;")
path_label += f"<br/>Note: you must create a PGSYSCONFDIR variable for this configuration to work.</span>More info <a href='https://gis.stackexchange.com/a/393494'>here</a>."
self.pgservicePathLabel.setTextFormat(Qt.RichText)
self.pgservicePathLabel.setTextInteractionFlags(Qt.TextBrowserInteraction)
Expand Down Expand Up @@ -256,9 +247,7 @@ def conf(self):

def _show_progress(self, message):
if self.progress_dialog is None:
self.progress_dialog = QProgressDialog(
self.tr("Starting..."), self.tr("Cancel"), 0, 0
)
self.progress_dialog = QProgressDialog(self.tr("Starting..."), self.tr("Cancel"), 0, 0)
cancel_button = QPushButton(self.tr("Cancel"))
cancel_button.setEnabled(False)
self.progress_dialog.setCancelButton(cancel_button)
Expand Down Expand Up @@ -422,31 +411,21 @@ def enable_buttons_if_ready(self):
# Datamodel

def check_datamodel(self):
requirements_exists = os.path.exists(
REQUIREMENTS_PATH_TEMPLATE.format(self.version)
)
requirements_exists = os.path.exists(REQUIREMENTS_PATH_TEMPLATE.format(self.version))
deltas_exists = os.path.exists(DELTAS_PATH_TEMPLATE.format(self.version))

check = requirements_exists and deltas_exists

if check:
if self.version == "master":
self.releaseCheckLabel.setText(
"DEV RELEASE - DO NOT USE FOR PRODUCTION"
)
self.releaseCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.releaseCheckLabel.setText("DEV RELEASE - DO NOT USE FOR PRODUCTION")
self.releaseCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")
else:
self.releaseCheckLabel.setText("ok")
self.releaseCheckLabel.setStyleSheet(
"color: rgb(0, 170, 0);\nfont-weight: bold;"
)
self.releaseCheckLabel.setStyleSheet("color: rgb(0, 170, 0);\nfont-weight: bold;")
else:
self.releaseCheckLabel.setText("not found")
self.releaseCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.releaseCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")

self.checks["datamodel"] = check
self.enable_buttons_if_ready()
Expand All @@ -462,9 +441,7 @@ def switch_datamodel(self, _=None):
self._show_progress("Downloading the release")

# Download files
datamodel_path = self._download(
AVAILABLE_RELEASES[self.version], "datamodel.zip"
)
datamodel_path = self._download(AVAILABLE_RELEASES[self.version], "datamodel.zip")

# Unzip
datamodel_zip = zipfile.ZipFile(datamodel_path)
Expand Down Expand Up @@ -505,16 +482,10 @@ def check_requirements(self):

if check:
self.pythonCheckLabel.setText("ok")
self.pythonCheckLabel.setStyleSheet(
"color: rgb(0, 170, 0);\nfont-weight: bold;"
)
self.pythonCheckLabel.setStyleSheet("color: rgb(0, 170, 0);\nfont-weight: bold;")
else:
self.pythonCheckLabel.setText(
"\n".join(f"{dep}: {err}" for dep, err in missing)
)
self.pythonCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.pythonCheckLabel.setText("\n".join(f"{dep}: {err}" for dep, err in missing))
self.pythonCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")

self.checks["requirements"] = check
self.enable_buttons_if_ready()
Expand Down Expand Up @@ -546,7 +517,7 @@ def install_requirements(self):
dependencies = " ".join(
[
f'"{l.strip()}"'
for l in open(requirements_file_path, "r").read().splitlines()
for l in open(requirements_file_path).read().splitlines()
if l.strip()
]
)
Expand All @@ -569,14 +540,10 @@ def check_pgconfig(self):
check = bool(self.pgserviceComboBox.currentData())
if check:
self.pgconfigCheckLabel.setText("ok")
self.pgconfigCheckLabel.setStyleSheet(
"color: rgb(0, 170, 0);\nfont-weight: bold;"
)
self.pgconfigCheckLabel.setStyleSheet("color: rgb(0, 170, 0);\nfont-weight: bold;")
else:
self.pgconfigCheckLabel.setText("not set")
self.pgconfigCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.pgconfigCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")

self.checks["pgconfig"] = check
self.enable_buttons_if_ready()
Expand All @@ -596,9 +563,7 @@ def add_pgconfig(self):
conf = add_dialog.conf_dict()
self._write_pgservice_conf(name, conf)
self.update_pgconfig_combobox()
self.pgserviceComboBox.setCurrentIndex(
self.pgserviceComboBox.findData(name)
)
self.pgserviceComboBox.setCurrentIndex(self.pgserviceComboBox.findData(name))
self.select_pgconfig()

def update_pgconfig_combobox(self):
Expand All @@ -614,9 +579,7 @@ def select_pgconfig(self, _=None):
port = config.get(self.conf, "port", fallback="-")
dbname = config.get(self.conf, "dbname", fallback="-")
user = config.get(self.conf, "user", fallback="-")
password = (
len(config.get(self.conf, "password", fallback="")) * "*"
) or "-"
password = (len(config.get(self.conf, "password", fallback="")) * "*") or "-"
self.pgserviceCurrentLabel.setText(
f"host: {host}:{port}\ndbname: {dbname}\nuser: {user}\npassword: {password}"
)
Expand Down Expand Up @@ -658,15 +621,11 @@ def check_version(self, _=None):
pgservice = self.pgserviceComboBox.currentData()
if not pgservice:
self.versionCheckLabel.setText("service not selected")
self.versionCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.versionCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")

elif not available_versions:
self.versionCheckLabel.setText("no delta in datamodel")
self.versionCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.versionCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")

else:

Expand Down Expand Up @@ -703,37 +662,25 @@ def check_version(self, _=None):
if not connection_works:
check = False
self.versionCheckLabel.setText(error)
self.versionCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.versionCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")
elif error is not None:
check = False
self.versionCheckLabel.setText(error)
self.versionCheckLabel.setStyleSheet(
"color: rgb(170, 95, 0);\nfont-weight: bold;"
)
self.versionCheckLabel.setStyleSheet("color: rgb(170, 95, 0);\nfont-weight: bold;")
elif current_version <= target_version:
check = True
self.versionCheckLabel.setText(current_version)
self.versionCheckLabel.setStyleSheet(
"color: rgb(0, 170, 0);\nfont-weight: bold;"
)
self.versionCheckLabel.setStyleSheet("color: rgb(0, 170, 0);\nfont-weight: bold;")
elif current_version > target_version:
check = False
self.versionCheckLabel.setText(f"{current_version} (cannot downgrade)")
self.versionCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.versionCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")
else:
check = False
self.versionCheckLabel.setText(f"{current_version} (invalid version)")
self.versionCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.versionCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")

self.initializeButton.setVisible(
current_version is None and connection_works
)
self.initializeButton.setVisible(current_version is None and connection_works)
self.targetVersionComboBox.setVisible(current_version is not None)
self.versionUpgradeButton.setVisible(current_version is not None)

Expand Down Expand Up @@ -779,7 +726,7 @@ def initialize_version(self):

# Dirty hack to customize SRID in a dump
if srid != "2056":
with open(sql_path, "r") as file:
with open(sql_path) as file:
contents = file.read()
contents = contents.replace("2056", srid)
with open(sql_path, "w") as file:
Expand Down Expand Up @@ -888,14 +835,10 @@ def check_project(self):

if check:
self.projectCheckLabel.setText("ok")
self.projectCheckLabel.setStyleSheet(
"color: rgb(0, 170, 0);\nfont-weight: bold;"
)
self.projectCheckLabel.setStyleSheet("color: rgb(0, 170, 0);\nfont-weight: bold;")
else:
self.projectCheckLabel.setText("version not found")
self.projectCheckLabel.setStyleSheet(
"color: rgb(170, 0, 0);\nfont-weight: bold;"
)
self.projectCheckLabel.setStyleSheet("color: rgb(170, 0, 0);\nfont-weight: bold;")

self.checks["project"] = check
self.enable_buttons_if_ready()
Expand All @@ -916,7 +859,7 @@ def load_project(self):
qgep_zip = zipfile.ZipFile(qgep_path)
qgep_zip.extractall(TEMP_DIR)

with open(QGEP_PROJECT_PATH_TEMPLATE, "r") as original_project:
with open(QGEP_PROJECT_PATH_TEMPLATE) as original_project:
contents = original_project.read()

# replace the service name
Expand Down
11 changes: 3 additions & 8 deletions qgepplugin/gui/qgepplotsvgwidget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# -----------------------------------------------------------
#
# Profile
Expand Down Expand Up @@ -43,7 +42,7 @@ def __init__(self, parent):
QWebPage.__init__(self, parent)

def javaScriptConsoleMessage(self, msg, line, source):
self.logger.debug("{} line {}: {}".format(source, line, msg))
self.logger.debug(f"{source} line {line}: {msg}")


class QgepPlotSVGWidget(QWidget):
Expand Down Expand Up @@ -82,18 +81,14 @@ def __init__(self, parent, network_analyzer: QgepGraphManager, url: str = None):
layout = QVBoxLayout(self)
if url is None:
# Starting with QGIS 3.4, QWebView requires paths with / even on windows.
default_url = (
plugin_root_path().replace("\\", "/") + "/svgprofile/index.html"
)
default_url = plugin_root_path().replace("\\", "/") + "/svgprofile/index.html"
url = settings.value("/QGEP/SvgProfilePath", default_url)
url = "file:///" + url

developer_mode = settings.value("/QGEP/DeveloperMode", False, type=bool)

if developer_mode is True:
self.webView.page().settings().setAttribute(
QWebSettings.DeveloperExtrasEnabled, True
)
self.webView.page().settings().setAttribute(QWebSettings.DeveloperExtrasEnabled, True)
else:
self.webView.setContextMenuPolicy(Qt.NoContextMenu)

Expand Down
Loading

0 comments on commit 1ff33c8

Please sign in to comment.