Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Black code linter ci #243

Merged
merged 2 commits into from
Sep 12, 2024
Merged
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
20 changes: 20 additions & 0 deletions .github/workflows/black-python-code-linter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Black Python Code Linter

on:
push:
branches:
- main

paths:
- "**.py"

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: psf/black@stable
with:
options: "--check --verbose"
src: "./src/qgis_gender_indicator_tool"
18 changes: 9 additions & 9 deletions admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def generate_zip(
:type context: Path
"""
build_dir = build(context)
metadata = _get_metadata()['general']
metadata = _get_metadata()["general"]
plugin_version = metadata["version"] if version is None else version
output_directory.mkdir(parents=True, exist_ok=True)
zip_path = output_directory / f"{SRC_NAME}.{plugin_version}.zip"
Expand Down Expand Up @@ -217,7 +217,7 @@ def copy_icon(
:rtype: Path
"""

metadata = _get_metadata()['general']
metadata = _get_metadata()["general"]
icon_path = LOCAL_ROOT_DIR / "resources" / metadata["icon"]
if icon_path.is_file():
target_path = output_directory / icon_path.name
Expand Down Expand Up @@ -277,16 +277,18 @@ def compile_resources(
_log(f"compile_resources target_path: {target_path}", context=context)
subprocess.run(shlex.split(f"pyrcc5 -o {target_path} {resources_path}"))


@app.command()
def add_requirements_file(
context: typer.Context,
output_directory: typing.Optional[Path] = LOCAL_ROOT_DIR / "build/temp",
context: typer.Context,
output_directory: typing.Optional[Path] = LOCAL_ROOT_DIR / "build/temp",
):
resources_path = LOCAL_ROOT_DIR / "requirements-dev.txt"
target_path = output_directory / "requirements-dev.txt"

shutil.copy(str(resources_path.resolve()), str(target_path))


@app.command()
def generate_metadata(
context: typer.Context,
Expand All @@ -309,7 +311,7 @@ def generate_metadata(
# do not modify case of parameters, as per
# https://docs.python.org/3/library/configparser.html#customizing-parser-behaviour
config.optionxform = lambda option: option
config["general"] = metadata['general']
config["general"] = metadata["general"]
with target_path.open(mode="w") as fh:
config.write(fh)

Expand All @@ -326,7 +328,7 @@ def generate_plugin_repo_xml(
"""
repo_base_dir = LOCAL_ROOT_DIR / "docs" / "repository"
repo_base_dir.mkdir(parents=True, exist_ok=True)
metadata = _get_metadata()['general']
metadata = _get_metadata()["general"]
fragment_template = """
<pyqgis_plugin name="{name}" version="{version}">
<description><![CDATA[{description}]]></description>
Expand Down Expand Up @@ -402,9 +404,7 @@ def _get_metadata() -> typing.Dict:
}
)

metadata = {
'general': general_metadata
}
metadata = {"general": general_metadata}

return metadata

Expand Down
24 changes: 17 additions & 7 deletions geest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,24 @@
See the LICENSE file in the project root for more information.
"""

from PyQt5.QtWidgets import QDockWidget, QTreeView, QDialog, QVBoxLayout, QScrollArea, QPushButton, QWidget, QLabel, QProgressBar
from PyQt5.QtWidgets import (
QDockWidget,
QTreeView,
QDialog,
QVBoxLayout,
QScrollArea,
QPushButton,
QWidget,
QLabel,
QProgressBar,
)
from PyQt5.QtCore import Qt
from PyQt5 import uic
from qgis.core import QgsApplication
from .tree_view_model import TreeViewModel
from .queue_manager import QueueManager


class GEEST:
"""
The main plugin class for GEEST.
Expand Down Expand Up @@ -84,10 +95,10 @@ def initGui(self):
schema_files = {
"group": "path/to/group_schema.json",
"factor": "path/to/factor_schema.json",
"sub-factor": "path/to/sub_factor_schema.json"
"sub-factor": "path/to/sub_factor_schema.json",
}

self.model = TreeViewModel('path/to/your/json_file.json', schema_files)
self.model = TreeViewModel("path/to/your/json_file.json", schema_files)
self.tree_view.setModel(self.model)

self.model.layoutChanged.connect(self.update_action_button_state)
Expand All @@ -100,10 +111,10 @@ def show_config_dialog(self, node_name):
node_name (str): The name of the node for which the dialog is shown.
"""
self.config_dialog = QDialog(self.iface.mainWindow())
uic.loadUi('path/to/config_dialog.ui', self.config_dialog)
uic.loadUi("path/to/config_dialog.ui", self.config_dialog)

# Set the banner text
banner_label = self.config_dialog.findChild(QLabel, 'bannerLabel')
banner_label = self.config_dialog.findChild(QLabel, "bannerLabel")
if banner_label:
banner_label.setText(f"{node_name} Configuration")

Expand Down Expand Up @@ -174,4 +185,3 @@ def unload(self):
Unloads the plugin from QGIS.
"""
self.iface.removeDockWidget(self.dock_widget)

10 changes: 5 additions & 5 deletions queue_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from qgis.core import QgsApplication
from .task import GEESTTask


class QueueManager:
"""
Manages the queue of tasks for processing GEEST nodes.
Expand All @@ -34,23 +35,22 @@ def generate_tasks(self):
def process_tasks(self):
self.generate_tasks()
for task in self.tasks:
self.model.update_node_status(task.node, 'running')
self.model.update_node_status(task.node, "running")
QgsApplication.taskManager().addTask(task)

def cancel_tasks(self):
for task in self.tasks:
if not task.isCanceled():
task.cancel()
self.model.update_node_status(task.node, 'idle')
self.model.update_node_status(task.node, "idle")

def on_task_finished(self, result):
self.completed_tasks += 1
status = 'success' if result else 'error'
status = "success" if result else "error"
self.model.update_node_status(self.sender().node, status)
self.progress_callback(self.completed_tasks, len(self.tasks))

def on_task_error(self):
self.completed_tasks += 1
self.model.update_node_status(self.sender().node, 'error')
self.model.update_node_status(self.sender().node, "error")
self.progress_callback(self.completed_tasks, len(self.tasks))

13 changes: 10 additions & 3 deletions resources/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,25 @@
\x00\x00\x01\x89\x77\xc6\x6c\xc0\
"

qt_version = [int(v) for v in QtCore.qVersion().split('.')]
qt_version = [int(v) for v in QtCore.qVersion().split(".")]
if qt_version < [5, 8, 0]:
rcc_version = 1
qt_resource_struct = qt_resource_struct_v1
else:
rcc_version = 2
qt_resource_struct = qt_resource_struct_v2


def qInitResources():
QtCore.qRegisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)
QtCore.qRegisterResourceData(
rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data
)


def qCleanupResources():
QtCore.qUnregisterResourceData(rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data)
QtCore.qUnregisterResourceData(
rcc_version, qt_resource_struct, qt_resource_name, qt_resource_data
)


qInitResources()
3 changes: 2 additions & 1 deletion src/qgis_gender_indicator_tool/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
This script initializes the plugin, making it known to QGIS.
"""


# noinspection PyPep8Naming
def classFactory(iface): # pylint: disable=invalid-name
"""Load GenderIndicatorTool class from file GenderIndicatorTool.
Expand All @@ -33,4 +34,4 @@ def classFactory(iface): # pylint: disable=invalid-name
#
from .main import GenderIndicatorTool

return GenderIndicatorTool(iface)
return GenderIndicatorTool(iface)
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@

import os
from qgis.core import QgsMessageLog, Qgis

try:
import geopandas as gpd
import rasterio
from rasterio.features import rasterize
from rasterio.transform import from_origin
except Exception:
QgsMessageLog.logMessage("Problem importing packages in a dialog...", 'GEEST', level=Qgis.Info)
QgsMessageLog.logMessage(
"Problem importing packages in a dialog...", "GEEST", level=Qgis.Info
)

from qgis.PyQt import uic
from qgis.PyQt import QtWidgets
Expand All @@ -39,9 +42,12 @@

# This loads your .ui file so that PyQt can populate your plugin with the elements from Qt Designer
FORM_CLASS, _ = uic.loadUiType(
os.path.join(os.path.dirname(__file__), "../ui/gender_indicator_tool_dialog_base.ui")
os.path.join(
os.path.dirname(__file__), "../ui/gender_indicator_tool_dialog_base.ui"
)
)


class GenderIndicatorToolDialog(QtWidgets.QDialog, FORM_CLASS):
def __init__(self, parent=None):
"""Constructor."""
Expand Down
3 changes: 0 additions & 3 deletions src/qgis_gender_indicator_tool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,3 @@ def run(self):

# show the dialog
self.dlg.show()



35 changes: 24 additions & 11 deletions task.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
from PyQt5.QtCore import pyqtSignal
import os


class GEESTTask(QgsTask):
"""
Custom task for running GEEST plugin operations as a background job.
"""

finished = pyqtSignal(bool)
error = pyqtSignal()

Expand All @@ -29,36 +31,47 @@ def run(self):
Executes the task. This is the main work method that performs the background operation.
"""
try:
output_path = self.node['output_path']
if self.node.get('processed', False) and os.path.exists(output_path):
QgsMessageLog.logMessage(f"{self.node['name']} already processed", "GEEST", QgsMessageLog.INFO)
output_path = self.node["output_path"]
if self.node.get("processed", False) and os.path.exists(output_path):
QgsMessageLog.logMessage(
f"{self.node['name']} already processed",
"GEEST",
QgsMessageLog.INFO,
)
self.finished.emit(True)
return True

# Simulate processing
self.process_node()
self.node['processed'] = True
QgsMessageLog.logMessage(f"Processed {self.node['name']}", "GEEST", QgsMessageLog.INFO)
self.node["processed"] = True
QgsMessageLog.logMessage(
f"Processed {self.node['name']}", "GEEST", QgsMessageLog.INFO
)
self.finished.emit(True)
return True
except Exception as e:
QgsMessageLog.logMessage(f"Task failed for {self.node['name']}: {str(e)}", "GEEST", QgsMessageLog.CRITICAL)
QgsMessageLog.logMessage(
f"Task failed for {self.node['name']}: {str(e)}",
"GEEST",
QgsMessageLog.CRITICAL,
)
self.error.emit()
return False

def process_node(self):
"""
Simulates the processing of the node.
"""
output_path = self.node['output_path']
output_path = self.node["output_path"]
os.makedirs(os.path.dirname(output_path), exist_ok=True)
with open(output_path, 'w') as f:
with open(output_path, "w") as f:
f.write(f"Processed output for {self.node['name']}")

def cancel(self):
"""
Handles task cancellation.
"""
QgsMessageLog.logMessage(f"{self.node['name']} task was cancelled", "GEEST", QgsMessageLog.INFO)
QgsMessageLog.logMessage(
f"{self.node['name']} task was cancelled", "GEEST", QgsMessageLog.INFO
)
super().cancel()

2 changes: 1 addition & 1 deletion test/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__author__ = 'timlinux'
__author__ = "timlinux"
Loading
Loading