1+ """Contains all comonent classes and Report related base classes for VueGen."""
2+
13import logging
24import os
35from abc import ABC , abstractmethod
1719import requests
1820from pyvis .network import Network
1921
22+ from vuegen .constants import TIMEOUT
23+
2024from .utils import cyjs_to_networkx , fetch_file_stream , pyvishtml_to_networkx
2125
2226
2327class 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
3440class 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
4351class 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
5060class 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
6981class CSVNetworkFormat (StrEnum ):
82+ """Enum representing different formats for CSV network files."""
83+
7084 EDGELIST = auto ()
7185 ADJLIST = auto ()
7286
7387
7488class 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
715737class 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
853872class 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
0 commit comments