Skip to content

Commit 6c66f42

Browse files
committed
🎨 module and docstrings, comments splitting and removing unnecessary code
1 parent a808217 commit 6c66f42

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

src/vuegen/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Constants for the Vuegen project."""
2+
13
GITHUB_ORG_URL = "https://github.com/Multiomics-Analytics-Group"
24
ORG = "Multiomics Network Analytics Group (MoNA)"
35
GITHUB_ORG_URL_BRACKETS = "{https://github.com/Multiomics-Analytics-Group}"

src/vuegen/report.py

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Contains all comonent classes and Report related base classes for VueGen."""
2+
13
import logging
24
import os
35
from abc import ABC, abstractmethod
@@ -17,10 +19,14 @@
1719
import requests
1820
from pyvis.network import Network
1921

22+
from vuegen.constants import TIMEOUT
23+
2024
from .utils import cyjs_to_networkx, fetch_file_stream, pyvishtml_to_networkx
2125

2226

2327
class ReportType(StrEnum):
28+
"""Enum representing different types of reports that can be generated."""
29+
2430
STREAMLIT = auto()
2531
HTML = auto()
2632
PDF = auto()
@@ -32,6 +38,8 @@ class ReportType(StrEnum):
3238

3339

3440
class ComponentType(StrEnum):
41+
"""Enum representing different types of components in a report subsection."""
42+
3543
PLOT = auto()
3644
DATAFRAME = auto()
3745
MARKDOWN = auto()
@@ -41,13 +49,17 @@ class ComponentType(StrEnum):
4149

4250

4351
class PlotType(StrEnum):
52+
"""Enum representing different types of plots that can be generated."""
53+
4454
STATIC = auto()
4555
PLOTLY = auto()
4656
ALTAIR = auto()
4757
INTERACTIVE_NETWORK = auto()
4858

4959

5060
class NetworkFormat(StrEnum):
61+
"""Enum representing different formats for network graphs."""
62+
5163
GML = auto()
5264
GRAPHML = auto()
5365
GEXF = auto()
@@ -67,11 +79,15 @@ def value_with_dot(self):
6779

6880

6981
class CSVNetworkFormat(StrEnum):
82+
"""Enum representing different formats for CSV network files."""
83+
7084
EDGELIST = auto()
7185
ADJLIST = auto()
7286

7387

7488
class DataFrameFormat(StrEnum):
89+
"""Enum representing different file formats for data in DataFrame format."""
90+
7591
CSV = auto()
7692
TXT = auto()
7793
PARQUET = auto()
@@ -192,7 +208,8 @@ def read_network(self) -> nx.Graph:
192208
NetworkFormat.CYJS.value_with_dot: cyjs_to_networkx,
193209
}
194210

195-
# Handle .csv and .txt files with custom delimiters based on the text format (edgelist or adjlist)
211+
# Handle .csv and .txt files with custom delimiters based on the text format
212+
# (edgelist or adjlist)
196213
try:
197214
# Fetch the file stream (local or URL) using fetch_file_stream
198215
file_stream = fetch_file_stream(self.file_path)
@@ -211,7 +228,8 @@ def read_network(self) -> nx.Graph:
211228
G = pyvishtml_to_networkx(file_stream)
212229
return (G, self.file_path)
213230

214-
# Handle CSV and TXT files with custom delimiters based on the text format (edgelist or adjlist)
231+
# Handle CSV and TXT files with custom delimiters based on the text format
232+
# (edgelist or adjlist)
215233
if (
216234
file_extension
217235
in [NetworkFormat.CSV.value_with_dot, NetworkFormat.TXT.value_with_dot]
@@ -226,7 +244,8 @@ def read_network(self) -> nx.Graph:
226244
)
227245

228246
if self.csv_network_format == CSVNetworkFormat.EDGELIST:
229-
# Assert that "source" and "target" columns are present in the DataFrame
247+
# Assert that "source" and "target" columns
248+
# are present in the DataFrame
230249
required_columns = {"source", "target"}
231250
if not required_columns.issubset(df_net.columns):
232251
missing_cols = ", ".join(
@@ -236,7 +255,8 @@ def read_network(self) -> nx.Graph:
236255
f"CSV network file must contain 'source' and 'target' columns. Missing columns: {missing_cols}."
237256
)
238257

239-
# Use additional columns as edge attributes, excluding "source" and "target"
258+
# Use additional columns as edge attributes,
259+
# excluding "source" and "target"
240260
edge_attributes = [
241261
col for col in df_net.columns if col not in required_columns
242262
]
@@ -412,7 +432,7 @@ def _add_size_attribute(self, G: nx.Graph) -> nx.Graph:
412432
A NetworkX graph object with the 'size' attribute added to the nodes.
413433
"""
414434
# Clean up edge attributes to avoid conflicts
415-
for u, v, data in G.edges(data=True):
435+
for _, _, data in G.edges(data=True):
416436
data.pop("source", None)
417437
data.pop("target", None)
418438

@@ -612,6 +632,7 @@ def make_api_request(
612632
if self.method in ["POST", "PUT", "PATCH"] and request_body_to_send
613633
else None
614634
),
635+
timeout=TIMEOUT,
615636
)
616637
response.raise_for_status()
617638
self.logger.info(
@@ -710,7 +731,8 @@ def _generate_id(cls) -> int:
710731
return cls._id_counter
711732

712733

713-
# ? Section is a subclass of Subsection (adding subsections). Destinction might not be necessary
734+
# ? Section is a subclass of Subsection (adding subsections).
735+
# ? Distinction might not be necessary
714736
@dataclass
715737
class Section:
716738
"""
@@ -814,7 +836,6 @@ def generate_report(self, output_dir: str = "sections") -> None:
814836
The folder where the generated report files will be saved
815837
(default is 'sections').
816838
"""
817-
pass
818839

819840
@abstractmethod
820841
def run_report(self, output_dir: str = "sections") -> None:
@@ -826,7 +847,6 @@ def run_report(self, output_dir: str = "sections") -> None:
826847
output_dir : str, optional
827848
The folder where the report was generated (default is 'sections').
828849
"""
829-
pass
830850

831851
@abstractmethod
832852
def _generate_component_imports(self, component: Component) -> str:
@@ -847,7 +867,6 @@ def _generate_component_imports(self, component: Component) -> str:
847867
str
848868
A str of import statements for the component.
849869
"""
850-
pass
851870

852871

853872
class WebAppReportView(ReportView):
@@ -877,7 +896,6 @@ def _format_text(self, text: str, type: str, level: int, color: str) -> str:
877896
str
878897
The formatted text string.
879898
"""
880-
pass
881899

882900
@abstractmethod
883901
def _generate_sections(self, output_dir: str) -> None:
@@ -893,7 +911,6 @@ def _generate_sections(self, output_dir: str) -> None:
893911
-----
894912
This method is intended to be used internally by the `generate_report` method.
895913
"""
896-
pass
897914

898915
@abstractmethod
899916
def _generate_subsection(
@@ -915,4 +932,3 @@ def _generate_subsection(
915932
- list of subsection content lines (List[str])
916933
- list of imports for the subsection (List[str])
917934
"""
918-
pass

src/vuegen/utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ def get_completion_message(report_type: str, config_path: str) -> str:
863863
📂 Your {report_type} report is available at:
864864
quarto_report
865865
866-
✨ You can extend the report by adding new files to the input directory or
866+
✨ You can extend the report by adding new files to the input directory or
867867
updating the config file.
868868
869869
🛠️ Advanced users can modify the report template directly in:

0 commit comments

Comments
 (0)