Skip to content

Commit 7783eeb

Browse files
committed
docs: update docstrings to improve clarity and consistency across the codebase
1 parent ef6ad1b commit 7783eeb

File tree

11 files changed

+126
-34
lines changed

11 files changed

+126
-34
lines changed

loopstructural/__about__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#! python3
22

3-
"""Metadata about the package to easily retrieve informations about it.
4-
See: https://packaging.python.org/guides/single-sourcing-package-version/
3+
"""Package metadata.
4+
5+
Contains package metadata constants used by the plugin (title, icon, etc.).
56
"""
67

78
# ############################################################################
@@ -36,13 +37,17 @@
3637
# ########## Functions #############
3738
# ##################################
3839
def plugin_metadata_as_dict() -> dict:
39-
"""Read plugin metadata.txt and returns it as a Python dict.
40+
"""Read plugin metadata.txt and return it as a Python dict.
4041
41-
Raises:
42-
IOError: if metadata.txt is not found
42+
Raises
43+
------
44+
IOError
45+
If metadata.txt is not found.
4346
44-
Returns:
45-
dict: dict of dicts.
47+
Returns
48+
-------
49+
dict
50+
Metadata sections as nested dictionaries.
4651
4752
"""
4853
config = ConfigParser()

loopstructural/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#! python3
22

3+
"""LoopStructural QGIS plugin package.
4+
5+
Utilities and metadata for the LoopStructural QGIS plugin.
6+
"""
7+
38
# ----------------------------------------------------------
49
# Copyright (C) 2015 Martin Dobias
510
# ----------------------------------------------------------

loopstructural/gui/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#! python3
2+
"""GUI package for the LoopStructural QGIS plugin.
3+
4+
Contains widgets, dialogs and visualisation helpers used by the plugin UI.
5+
"""
6+
7+
# Re-export commonly used GUI classes if needed

loopstructural/gui/dlg_settings.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,23 @@ def reset_settings(self):
127127
class PlgOptionsFactory(QgsOptionsWidgetFactory):
128128
"""Factory for options widget."""
129129

130-
def __init__(self):
131-
"""Constructor."""
130+
def __init__(self, *args, **kwargs):
131+
"""Initialize the options factory.
132+
133+
Parameters
134+
----------
135+
*args, **kwargs
136+
Forwarded to base factory initializer.
137+
"""
132138
super().__init__()
133139

134-
def icon(self) -> QIcon:
135-
"""Returns plugin icon used as tab icon in QGIS options.
140+
def icon(self):
141+
"""Return the icon used for the options page.
136142
137143
Returns
138144
-------
139145
QIcon
140-
Plugin icon instance.
146+
Icon for the options page.
141147
"""
142148
return QIcon(str(__icon_path__))
143149

loopstructural/gui/loop_widget.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
1+
#! python3
2+
"""Main Loop widget used in the plugin dock.
3+
4+
This module exposes `LoopWidget` which provides the primary user
5+
interface for interacting with LoopStructural features inside QGIS.
6+
"""
7+
18
from PyQt5.QtWidgets import QTabWidget, QVBoxLayout, QWidget
29
from .modelling.modelling_widget import ModellingWidget
310
from .visualisation.visualisation_widget import VisualisationWidget
411

512

613
class LoopWidget(QWidget):
14+
"""Main dock widget that contains modelling and visualisation tools.
15+
16+
The widget composes multiple tabs and controls used to construct and
17+
inspect geological models.
18+
"""
19+
720
def __init__(
821
self, parent=None, *, mapCanvas=None, logger=None, data_manager=None, model_manager=None
922
):
23+
"""Initialize the Loop widget.
24+
25+
Parameters
26+
----------
27+
*args, **kwargs
28+
Forwarded to the parent widget constructor.
29+
"""
1030
super().__init__(parent)
1131
self.mapCanvas = mapCanvas
1232
self.logger = logger

loopstructural/plugin_main.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,14 @@
4343

4444

4545
class LoopstructuralPlugin:
46+
"""QGIS plugin entrypoint for LoopStructural.
47+
48+
This class initializes plugin resources, UI elements and data/model managers
49+
required for LoopStructural integration with QGIS.
50+
"""
51+
4652
def __init__(self, iface: QgisInterface):
47-
"""Constructor.
53+
"""Initialize the plugin.
4854
4955
Parameters
5056
----------
@@ -73,6 +79,12 @@ def __init__(self, iface: QgisInterface):
7379
self.data_manager.set_model_manager(self.model_manager)
7480

7581
def injectLogHandler(self):
82+
"""Install LoopStructural logging handler that forwards logs to the plugin logger.
83+
84+
This configures LoopStructural's logging to use the plugin's
85+
PlgLoggerHandler so log records are captured and forwarded to the
86+
plugin's logging infrastructure.
87+
"""
7688
import logging
7789

7890
import LoopStructural
@@ -185,7 +197,7 @@ def tr(self, message: str) -> str:
185197
return QCoreApplication.translate(self.__class__.__name__, message)
186198

187199
def unload(self):
188-
"""Cleans up when plugin is disabled/uninstalled."""
200+
"""Clean up when plugin is disabled or uninstalled."""
189201
# -- Clean up menu
190202
self.iface.removePluginMenu(__title__, self.action_help)
191203
self.iface.removePluginMenu(__title__, self.action_settings)
@@ -203,9 +215,12 @@ def unload(self):
203215
del self.toolbar
204216

205217
def run(self):
206-
"""Main process.
218+
"""Run main process.
207219
208-
:raises Exception: if there is no item in the feed
220+
Raises
221+
------
222+
Exception
223+
If there is no item in the feed.
209224
"""
210225
try:
211226
self.log(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
#! python3
2+
"""Processing provider package for LoopStructural.
3+
4+
Contains provider definitions and registration utilities for the QGIS
5+
processing framework.
6+
"""
27
from .provider import LoopstructuralProvider

loopstructural/processing/provider.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#! python3
22

3-
"""Processing provider module.
4-
"""
3+
"""Processing provider for LoopStructural plugin."""
54

65
# PyQGIS
76
from qgis.core import QgsProcessingProvider
@@ -20,11 +19,11 @@ class LoopstructuralProvider(QgsProcessingProvider):
2019
"""Processing provider class."""
2120

2221
def loadAlgorithms(self):
23-
"""Loads all algorithms belonging to this provider."""
22+
"""Load all algorithms belonging to this provider."""
2423
pass
2524

2625
def id(self) -> str:
27-
"""Unique provider id.
26+
"""Return unique provider id.
2827
2928
Returns
3029
-------
@@ -35,7 +34,7 @@ def id(self) -> str:
3534
return "loopstructural"
3635

3736
def name(self) -> str:
38-
"""Provider name used in the GUI.
37+
"""Return provider name used in the GUI.
3938
4039
Returns
4140
-------
@@ -45,7 +44,7 @@ def name(self) -> str:
4544
return __title__
4645

4746
def longName(self) -> str:
48-
"""Longer provider name (may include version information).
47+
"""Return longer provider name (may include version information).
4948
5049
Returns
5150
-------
@@ -55,7 +54,7 @@ def longName(self) -> str:
5554
return self.tr("{} - Tools".format(__title__))
5655

5756
def icon(self) -> QIcon:
58-
"""Icon used for the provider inside the Processing toolbox menu.
57+
"""Return icon used for the provider inside the Processing toolbox menu.
5958
6059
Returns
6160
-------
@@ -81,7 +80,7 @@ def tr(self, message: str) -> str:
8180
return QCoreApplication.translate(self.__class__.__name__, message)
8281

8382
def versionInfo(self) -> str:
84-
"""Provider version information.
83+
"""Return provider version information.
8584
8685
Returns
8786
-------
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
#! python3
2+
"""Toolbelt utilities for the LoopStructural plugin.
3+
4+
This package contains utility modules used by the plugin such as logging
5+
and preferences management.
6+
"""
7+
28
from .log_handler import PlgLogger
39
from .preferences import PlgOptionsManager

loopstructural/toolbelt/log_handler.py

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
#! python3
1+
#!/usr/bin/env python3
2+
"""Logging helpers that forward Python logging into QGIS messaging systems.
3+
4+
This module provides a convenience `PlgLogger` for emitting user-facing
5+
messages to the QGIS message log and message bar, and `PlgLoggerHandler` that
6+
bridges Python's `logging` into the plugin's logging facilities.
7+
"""
28

39
# standard library
410
import logging
@@ -132,21 +138,24 @@ def log(
132138

133139

134140
class PlgLoggerHandler(logging.Handler):
135-
"""
136-
Standard logging.Handler that forwards logs to PlgLogger.log().
141+
"""Handler that forwards Python log records to the plugin logger.
142+
143+
The handler calls the provided `plg_logger_class.log()` static method to
144+
forward formatted log messages to QGIS messaging systems.
137145
"""
138146

139147
def __init__(self, plg_logger_class, level=logging.NOTSET, push=False, duration=None):
140-
"""
148+
"""Initialize the log handler.
149+
141150
Parameters
142151
----------
143152
plg_logger_class : class
144-
Class providing a static `log()` method (like your PlgLogger).
145-
level : int
146-
The logging level to handle.
147-
push : bool
153+
Class providing a static `log()` method (like PlgLogger).
154+
level : int, optional
155+
The logging level to handle. Defaults to logging.NOTSET.
156+
push : bool, optional
148157
Whether to push messages to the QGIS message bar.
149-
duration : int
158+
duration : int, optional
150159
Optional fixed duration for messages.
151160
"""
152161
super().__init__(level)
@@ -155,6 +164,11 @@ def __init__(self, plg_logger_class, level=logging.NOTSET, push=False, duration=
155164
self.duration = duration
156165

157166
def emit(self, record):
167+
"""Emit a logging record by forwarding it to the plugin logger.
168+
169+
This formats the record, maps the Python logging level to QGIS levels
170+
and calls `plg_logger_class.log()` with the resulting message.
171+
"""
158172
try:
159173
msg = self.format(record)
160174
qgis_level = self._map_log_level(record.levelno)

0 commit comments

Comments
 (0)