Skip to content

Commit 00b73df

Browse files
committed
Add further docstring for interrogate checks
1 parent acb00d7 commit 00b73df

File tree

9 files changed

+65
-6
lines changed

9 files changed

+65
-6
lines changed

src/fourc_webviewer/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Module to initialize and run the webviewer application."""

src/fourc_webviewer/fourc_webserver.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""This module defines the FourCWebServer class, which manages the application
2+
state, synchronizes server variables, and handles PyVista rendering for the 4C
3+
web viewer."""
4+
15
import copy
26
import re
37
import tempfile
@@ -109,11 +113,14 @@ def __init__(self, page_title, fourc_yaml_file):
109113

110114
@property
111115
def state(self):
116+
"""Get state."""
117+
112118
# self.state contains all the state variables to be shared between server and client
113119
return self.server.state
114120

115121
@property
116122
def ctrl(self):
123+
"""Get controller."""
117124
# self.ctrl contains all the control functions callable on both the Javascript client-side and the Python server (running on the Python server)
118125
return self.server.controller
119126

@@ -773,6 +780,8 @@ def sync_funct_section_from_state(self):
773780
)
774781

775782
def init_mode_state_vars(self):
783+
"""Initialize state variables related to mode changes (edit mode, view
784+
mode) and statuses (e.g. read-in status)."""
776785
# initialize the read-in status and its possible choices
777786
self.state.all_read_in_statuses = {
778787
"success": "SUCCESS", # successful read-in of the file
@@ -821,6 +830,8 @@ def init_mode_state_vars(self):
821830
################################################
822831
@change("fourc_yaml_file")
823832
def change_fourc_yaml_file(self, fourc_yaml_file, **kwargs):
833+
"""Reaction to change of state.fourc_yaml_file."""
834+
824835
# create temporary fourc yaml file from the content of the given file
825836
temp_fourc_yaml_file = Path(
826837
self._server_vars["temp_dir_object"].name, fourc_yaml_file["name"]
@@ -848,6 +859,7 @@ def change_fourc_yaml_file(self, fourc_yaml_file, **kwargs):
848859

849860
@change("export_fourc_yaml_path")
850861
def change_export_fourc_yaml_path(self, export_fourc_yaml_path, **kwargs):
862+
"""Reaction to change of state.export_fourc_yaml_path."""
851863
# set the export status to info
852864
self.state.export_status = self.state.all_export_statuses["info"]
853865

@@ -856,6 +868,7 @@ def change_export_fourc_yaml_path(self, export_fourc_yaml_path, **kwargs):
856868
################################################
857869
@change("selected_main_section_name")
858870
def change_selected_main_section_name(self, selected_main_section_name, **kwargs):
871+
"""Reaction to change of state.selected_main_section_name."""
859872
# set selected section name to the first one within the selected
860873
# main section
861874
self.state.selected_section_name = self.state.section_names[
@@ -864,6 +877,7 @@ def change_selected_main_section_name(self, selected_main_section_name, **kwargs
864877

865878
@change("selected_material")
866879
def change_selected_material(self, selected_material, **kwargs):
880+
"""Reaction to change of state.selected_material."""
867881
# we need to select the material region based on the newly selected
868882
# material (if we are not in an initial rendering scenario)
869883
if self._server_vars["render_count"]["change_selected_material"] > 0:
@@ -888,6 +902,7 @@ def change_selected_material(self, selected_material, **kwargs):
888902

889903
@change("selected_dc_geometry_type")
890904
def change_selected_dc_geometry_type(self, selected_dc_geometry_type, **kwargs):
905+
"""Reaction to change of state.selected_dc_geometry_type."""
891906
# change entity to the first of the selected geometry
892907
self.state.selected_dc_entity = next(
893908
iter(self.state.dc_sections[selected_dc_geometry_type])
@@ -910,6 +925,7 @@ def change_selected_dc_geometry_type(self, selected_dc_geometry_type, **kwargs):
910925

911926
@change("selected_dc_entity")
912927
def change_selected_dc_entity(self, selected_dc_entity, **kwargs):
928+
"""Reaction to change of state.selected_dc_entity."""
913929
# change selected condition for the geometry-entity combination
914930
self.state.selected_dc_condition = next(
915931
iter(
@@ -929,6 +945,7 @@ def change_selected_dc_entity(self, selected_dc_entity, **kwargs):
929945
def change_selected_result_description_id(
930946
self, selected_result_description_id, **kwargs
931947
):
948+
"""Reaction to change of state.selected_result_description_id."""
932949
# update plotter / render objects
933950
self.update_pyvista_render_objects()
934951

@@ -937,6 +954,7 @@ def change_selected_result_description_id(
937954

938955
@change("selected_funct")
939956
def change_selected_funct(self, selected_funct, **kwargs):
957+
"""Reaction to change of state.selected_funct."""
940958
# set the selected funct item to the first within the newly
941959
# selected funct
942960
self.state.selected_funct_item = next(
@@ -951,6 +969,7 @@ def change_selected_funct(self, selected_funct, **kwargs):
951969

952970
@change("selected_funct_item")
953971
def change_selected_funct_item(self, selected_funct_item, **kwargs):
972+
"""Reaction to change of state.selected_funct_item."""
954973
# update plotly figure
955974
if self.state.funct_section[self.state.selected_funct][
956975
self.state.selected_funct_item
@@ -962,6 +981,7 @@ def change_selected_funct_item(self, selected_funct_item, **kwargs):
962981
################################################
963982
@change("funct_plot")
964983
def change_funct_plot(self, funct_plot, **kwargs):
984+
"""Reaction to change of state.funct_plot."""
965985
# update plotly figure
966986
if self.state.funct_section[self.state.selected_funct][
967987
self.state.selected_funct_item
@@ -970,6 +990,7 @@ def change_funct_plot(self, funct_plot, **kwargs):
970990

971991
@change("funct_section")
972992
def change_funct_section(self, funct_section, **kwargs):
993+
"""Reaction to change of state.funct_section."""
973994
# update plotly figure
974995
if self.state.funct_section[self.state.selected_funct][
975996
self.state.selected_funct_item
@@ -980,7 +1001,8 @@ def change_funct_section(self, funct_section, **kwargs):
9801001
# MODE CHANGES #################################
9811002
################################################
9821003
@change("edit_mode")
983-
def on_edit_mode_changed(self, edit_mode, **kwargs):
1004+
def change_edit_mode(self, edit_mode, **kwargs):
1005+
"""Reaction to change of state.edit_mode."""
9841006
# cast entered string values from VTextField (edit mode) to
9851007
# numbers
9861008
if (
@@ -1004,7 +1026,8 @@ def on_edit_mode_changed(self, edit_mode, **kwargs):
10041026
# self.state.funct_section = convert_string2number(self.state.funct_section)
10051027

10061028
@change("export_mode")
1007-
def on_export_mode_changed(self, export_mode, **kwargs):
1029+
def change_export_mode(self, export_mode, **kwargs):
1030+
"""Reaction to change of state.export_mode."""
10081031
# revert export status to "INFO"
10091032
self.state.export_status = self.state.all_export_statuses["info"]
10101033

@@ -1126,4 +1149,5 @@ def determine_master_mat_ind_for_current_selection(self):
11261149
return master_mat_id
11271150

11281151
def cleanup(self):
1152+
"""Perform cleanup tasks for the webserver."""
11291153
self._server_vars["temp_dir_object"].cleanup()

src/fourc_webviewer/gui_utils.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Specifies the GUI layout."""
2+
13
import plotly
24
from pyvista.trame.ui import plotter_ui
35

@@ -22,6 +24,7 @@ class VFileInput(HtmlElement):
2224
currently support all relevant attributes, such as e.g. 'accept'."""
2325

2426
def __init__(self, children=None, **kwargs):
27+
"""Initialize custom VFileInput element."""
2528
super().__init__("v-file-input", children, **kwargs)
2629
self._attr_names += [
2730
"accept",
@@ -101,6 +104,7 @@ def __init__(self, children=None, **kwargs):
101104

102105

103106
def _toolbar(server_controller):
107+
"""Toolbar layout."""
104108
VFileInput(
105109
label="Input file",
106110
v_model=("fourc_yaml_file",),
@@ -131,6 +135,7 @@ def _toolbar(server_controller):
131135

132136

133137
def _bottom_sheet_info():
138+
"""Bottom sheet layout (INFO mode)."""
134139
with vuetify.VBottomSheet(v_model=("info_mode",), inset=True):
135140
with vuetify.VCard(
136141
classes="text-center",
@@ -169,6 +174,7 @@ def _bottom_sheet_info():
169174

170175

171176
def _bottom_sheet_export(server_controller):
177+
"""Bottom sheet layout (EXPORT mode)."""
172178
with vuetify.VBottomSheet(v_model=("export_mode",), inset=True):
173179
with vuetify.VCard(classes="text-center", height=250, title="Export"):
174180
with vuetify.VCardText():
@@ -202,6 +208,7 @@ def _bottom_sheet_export(server_controller):
202208

203209

204210
def _sections_dropdown():
211+
"""Section dropdown layout."""
205212
vuetify.VSelect(
206213
v_model=("selected_main_section_name",),
207214
items=("Object.keys(section_names)",),
@@ -214,6 +221,7 @@ def _sections_dropdown():
214221

215222

216223
def _functions_panel(server):
224+
"""Functions panel layout."""
217225
with html.Div(
218226
v_if=(
219227
"section_names[selected_main_section_name]['content_mode'] == all_content_modes['funct_section']"
@@ -395,6 +403,7 @@ def _functions_panel(server):
395403

396404

397405
def _prop_value_table():
406+
"""Table (property - value) layout (for general sections)."""
398407
with vuetify.VTable(
399408
v_if=(
400409
"section_names[selected_main_section_name]['content_mode'] == all_content_modes['general_section']",
@@ -443,6 +452,7 @@ def _prop_value_table():
443452

444453

445454
def _materials_panel():
455+
"""Materials panel layout."""
446456
with html.Div(
447457
v_if=(
448458
"section_names[selected_main_section_name]['content_mode'] == all_content_modes['materials_section']"
@@ -696,6 +706,7 @@ def _materials_panel():
696706

697707

698708
def _design_conditions_panel():
709+
"""Layout for the design conditions panel."""
699710
with html.Div(
700711
v_if=(
701712
"section_names[selected_main_section_name]['content_mode'] == all_content_modes['design_conditions_section']"
@@ -831,6 +842,7 @@ def _design_conditions_panel():
831842

832843

833844
def _result_description_panel():
845+
"""Layout for the result description panel."""
834846
with html.Div(
835847
v_if=(
836848
"section_names[selected_main_section_name]['content_mode'] == all_content_modes['result_description_section']",
@@ -1007,6 +1019,8 @@ def _result_description_panel():
10071019

10081020

10091021
def create_gui(server, render_window):
1022+
"""Creates the graphical user interface based on the defined layout
1023+
elements."""
10101024
with SinglePageWithDrawerLayout(server) as layout:
10111025
layout.title.set_text("4C Webviewer")
10121026

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Module for handling and managing input files."""

src/fourc_webviewer/input_file_utils/fourc_yaml_file_visualization.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ def return_function_from_funct_string(funct_string):
131131
"""
132132

133133
def funct_using_eval(x, y, z, t):
134+
"""Evaluate function expression for given positional x, y, z
135+
coordinates and time t values.
136+
137+
Args:
138+
x (double): x-coordinate
139+
y (double): y-coordinate
140+
z (double): z-coordinate
141+
t (double): time t
142+
143+
Returns:
144+
parsed object using ast.literal_eval
145+
"""
134146
# defined functions to be replaced: <def_funct> becomes <np.funct>
135147
def_funct = ["exp", "sqrt", "log", "sin", "cos", "tan", "heaviside"]
136148

src/fourc_webviewer/input_file_utils/io_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def write_fourc_yaml_file(fourc_yaml_content, new_fourc_yaml_file):
9292

9393

9494
def add_fourc_yaml_file_data_to_dis(dis):
95+
"""Adds further data contained within the yaml file (e.g. material id) to
96+
the discretization from lnmmeshio."""
9597
dis.compute_ids(zero_based=False)
9698

9799
# write node data

src/fourc_webviewer/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Main entry point for launching the webviewer."""
2+
13
from fourc_webviewer.cli_utils import main
24

35
if __name__ == "__main__":

src/fourc_webviewer/run_webserver.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# ------------------------------------------------------------------------------#
2-
# IMPORT SECTION #
3-
# ------------------------------------------------------------------------------#
1+
"""Utility to run the webserver on a defined port."""
42

5-
from fourc_webviewer.fourc_webserver import FourCWebServer
63
from fourc_webviewer_default_files import (
74
DEFAULT_INPUT_FILE,
85
)
@@ -12,6 +9,9 @@
129

1310

1411
def run_webviewer(fourc_yaml_file=None):
12+
"""Runs the webviewer by creating a dedicated webserver object, starting it
13+
and cleaning up afterwards."""
14+
1515
if fourc_yaml_file is None:
1616
fourc_yaml_file = str(DEFAULT_INPUT_FILE)
1717

test/test_pyvista.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Tests related to pyvista plotting."""
2+
13
import tempfile
24
from pathlib import Path
35

@@ -18,6 +20,7 @@
1820

1921
@server.state.change("file_exchange")
2022
def handle(file_exchange, **kwargs) -> None:
23+
"""Reaction to file exchange."""
2124
if file_exchange:
2225
file = ClientFile(file_exchange[0])
2326
if file.content:

0 commit comments

Comments
 (0)