Skip to content

Commit 36cbc20

Browse files
committed
1 parent 4ac1971 commit 36cbc20

File tree

4 files changed

+177
-104
lines changed

4 files changed

+177
-104
lines changed

src/vuegen/config_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ def _create_component_config_fromfile(self, file_path: Path) -> Dict[str, str]:
151151
else:
152152
component_config["plot_type"] = r.PlotType.PLOTLY.value
153153
except Exception as e:
154-
self.logger.warning("Could not parse JSON file %s: %s", file_path, e)
154+
self.logger.warning(
155+
"Could not parse JSON file %s: %s", file_path, e, exc_info=True
156+
)
155157
component_config["plot_type"] = "unknown"
156158
elif file_ext == ".md":
157159
component_config["component_type"] = r.ComponentType.MARKDOWN.value
@@ -637,7 +639,9 @@ def _create_apicall_component(self, component_data: dict) -> r.APICall:
637639
try:
638640
parsed_body = json.loads(request_body)
639641
except json.JSONDecodeError as e:
640-
self.logger.error("Failed to parse request_body JSON: %s", e)
642+
self.logger.error(
643+
"Failed to parse request_body JSON: %s", e, exc_info=True
644+
)
641645
raise ValueError("Invalid JSON in request_body.") from e
642646

643647
return r.APICall(

src/vuegen/quarto_reportview.py

Lines changed: 71 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def __init__(
5555
if getattr(sys, "frozen", False) and hasattr(sys, "_MEIPASS"):
5656
self.report.logger.info("running in a PyInstaller bundle")
5757
# self.BUNDLED_EXECUTION = True
58-
self.report.logger.debug(f"sys._MEIPASS: {sys._MEIPASS}")
58+
self.report.logger.debug("sys._MEIPASS: %s", sys._MEIPASS)
5959
else:
6060
self.report.logger.info("running in a normal Python process")
6161

6262
self.report.logger.debug("env_vars (QuartoReport): %s", os.environ)
63-
self.report.logger.debug(f"PATH: {os.environ['PATH']}")
64-
self.report.logger.debug(f"sys.path: {sys.path}")
63+
self.report.logger.debug("PATH: %s", os.environ["PATH"])
64+
self.report.logger.debug("sys.path: %s", sys.path)
6565

6666
self.is_report_static = self.report_type in {
6767
r.ReportType.PDF,
@@ -92,25 +92,27 @@ def generate_report(self, output_dir: Optional[Path] = None) -> None:
9292
self.output_dir = Path(output_dir).resolve()
9393

9494
self.report.logger.debug(
95-
f"Generating '{self.report_type}' report in directory: '{self.output_dir}'"
95+
"Generating '%s' report in directory: '%s'",
96+
self.report_type,
97+
self.output_dir,
9698
)
9799
# Create the output folder
98100
if create_folder(self.output_dir, is_nested=True):
99-
self.report.logger.debug(f"Created output directory: '{self.output_dir}'")
101+
self.report.logger.debug("Created output directory: '%s'", self.output_dir)
100102
else:
101103
self.report.logger.debug(
102-
f"Output directory already existed: '{self.output_dir}'"
104+
"Output directory already existed: '%s'", self.output_dir
103105
)
104106

105107
# Create the static folder
106108
if create_folder(self.static_dir):
107109
self.report.logger.info(
108-
f"Created output directory for static content: '{self.static_dir}'"
110+
"Created output directory for static content: '%s'", self.static_dir
109111
)
110112
else:
111113
self.report.logger.info(
112-
"Output directory for static content already existed: "
113-
f"'{self.static_dir}'"
114+
"Output directory for static content already existed: '%s'",
115+
self.static_dir,
114116
)
115117

116118
try:
@@ -140,8 +142,9 @@ def generate_report(self, output_dir: Optional[Path] = None) -> None:
140142
self.report.logger.info("Starting to generate sections for the report.")
141143
for section in self.report.sections:
142144
self.report.logger.debug(
143-
f"Processing section: '{section.title}' -"
144-
f" {len(section.subsections)} subsection(s)"
145+
"Processing section: '%s' - %d subsection(s)",
146+
section.title,
147+
len(section.subsections),
145148
)
146149
# Add section header and description
147150
qmd_content.append(f"# {section.title}")
@@ -176,8 +179,9 @@ def generate_report(self, output_dir: Optional[Path] = None) -> None:
176179
# Iterate through subsections and integrate them into the section file
177180
for subsection in section.subsections:
178181
self.report.logger.debug(
179-
f"Processing subsection: '{subsection.title}' - "
180-
f"{len(subsection.components)} component(s)"
182+
"Processing subsection: '%s' - %d component(s)",
183+
subsection.title,
184+
len(subsection.components),
181185
)
182186
# Generate content for the subsection
183187
subsection_content, subsection_imports = (
@@ -192,8 +196,9 @@ def generate_report(self, output_dir: Optional[Path] = None) -> None:
192196
) # even easier as it's global
193197
else:
194198
self.report.logger.warning(
195-
f"No subsections found in section: '{section.title}'. "
196-
"To show content in the report, add subsections to the section."
199+
"No subsections found in section: '%s'. To show content "
200+
"in the report, add subsections to the section.",
201+
section.title,
197202
)
198203
# Add globally set output folder
199204
report_imports.append("from pathlib import Path")
@@ -226,12 +231,14 @@ def generate_report(self, output_dir: Optional[Path] = None) -> None:
226231
)
227232
quarto_report.write("\n".join(qmd_content))
228233
self.report.logger.info(
229-
f"Created qmd script to render the app: {fname_qmd_report}"
234+
"Created qmd script to render the app: %s", fname_qmd_report
230235
)
231236

232237
except Exception as e:
233238
self.report.logger.error(
234-
f"An error occurred while generating the report: {str(e)}"
239+
"An error occurred while generating the report: %s",
240+
e,
241+
exc_info=True,
235242
)
236243
raise
237244

@@ -251,7 +258,10 @@ def run_report(self, output_dir: Optional[Path] = None) -> None:
251258
file_path_to_qmd = Path(self.output_dir) / f"{self.BASE_DIR}.qmd"
252259
args = [self.quarto_path, "render", str(file_path_to_qmd)]
253260
self.report.logger.info(
254-
f"Running '{self.report.title}' '{self.report_type}' report with {args!r}"
261+
"Running '%s' '%s' report with %r",
262+
self.report.title,
263+
self.report_type,
264+
args,
255265
)
256266
if (
257267
self.report_type
@@ -289,15 +299,22 @@ def run_report(self, output_dir: Optional[Path] = None) -> None:
289299
check=True,
290300
)
291301
self.report.logger.info(
292-
f"Converted '{self.report.title}' '{self.report_type}' "
293-
"report to Jupyter Notebook after execution"
302+
"Converted '%s' '%s' report to Jupyter Notebook after execution",
303+
self.report.title,
304+
self.report_type,
294305
)
295306
self.report.logger.info(
296-
f"'{self.report.title}' '{self.report_type}' report rendered"
307+
"'%s' '%s' report rendered",
308+
self.report.title,
309+
self.report_type,
297310
)
298311
except subprocess.CalledProcessError as e:
299312
self.report.logger.error(
300-
f"Error running '{self.report.title}' {self.report_type} report: {str(e)}"
313+
"Error running '%s' %s report: %s",
314+
self.report.title,
315+
self.report_type,
316+
e,
317+
exc_info=True,
301318
)
302319
raise
303320

@@ -495,7 +512,7 @@ def _combine_components(self, components: list[dict]) -> tuple[list, list]:
495512
fct = self.components_fct_map.get(component.component_type, None)
496513
if fct is None:
497514
self.report.logger.warning(
498-
f"Unsupported component type '{component.component_type}' "
515+
"Unsupported component type '%s'", component.component_type
499516
)
500517
elif (
501518
component.component_type == r.ComponentType.MARKDOWN
@@ -557,7 +574,7 @@ def _generate_subsection(
557574
subsection_content.append(":::\n")
558575

559576
self.report.logger.info(
560-
f"Generated content and imports for subsection: '{subsection.title}'"
577+
"Generated content and imports for subsection: '%s'", subsection.title
561578
)
562579
return subsection_content, subsection_imports
563580

@@ -585,7 +602,7 @@ def _generate_plot_content(self, plot) -> List[str]:
585602
static_plot_path = (
586603
Path(self.static_dir) / f"{plot.title.replace(' ', '_')}.png"
587604
).resolve()
588-
self.report.logger.debug(f"Static plot path: {static_plot_path}")
605+
self.report.logger.debug("Static plot path: %s", static_plot_path)
589606
else:
590607
html_plot_file = (
591608
Path(self.static_dir) / f"{plot.title.replace(' ', '_')}.html"
@@ -637,11 +654,15 @@ def _generate_plot_content(self, plot) -> List[str]:
637654
else:
638655
plot_content.append(self._generate_plot_code(plot, html_plot_file))
639656
else:
640-
self.report.logger.warning(f"Unsupported plot type: {plot.plot_type}")
657+
self.report.logger.warning("Unsupported plot type: %s", plot.plot_type)
641658
except Exception as e:
642659
self.report.logger.error(
643-
f"Error generating content for '{plot.plot_type}' plot '{plot.id}' "
644-
f"'{plot.title}': {str(e)}"
660+
"Error generating content for '%s' plot '%s' '%s': %s",
661+
plot.plot_type,
662+
plot.id,
663+
plot.title,
664+
e,
665+
exc_info=True,
645666
)
646667
raise
647668

@@ -650,7 +671,7 @@ def _generate_plot_content(self, plot) -> List[str]:
650671
plot_content.append(f">{plot.caption}\n")
651672

652673
self.report.logger.info(
653-
f"Successfully generated content for plot: '{plot.title}'"
674+
"Successfully generated content for plot: '%s'", plot.title
654675
)
655676
return plot_content
656677

@@ -786,8 +807,9 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
786807
file_extension == fmt.value_with_dot for fmt in r.DataFrameFormat
787808
):
788809
self.report.logger.error(
789-
f"Unsupported file extension: {file_extension}. Supported extensions"
790-
f" are: {', '.join(fmt.value for fmt in r.DataFrameFormat)}."
810+
"Unsupported file extension: %s. Supported extensions are: %s.",
811+
file_extension,
812+
", ".join(fmt.value for fmt in r.DataFrameFormat),
791813
)
792814

793815
# Build the file path (URL or local file)
@@ -807,8 +829,9 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
807829
if len(sheet_names) > 1:
808830
# If there are multiple sheets, use the first one
809831
self.report.logger.info(
810-
f"Multiple sheets found in the Excel file: {df_file_path}. "
811-
f"Sheets: {sheet_names}"
832+
"Multiple sheets found in the Excel file: %s. Sheets: %s",
833+
df_file_path,
834+
sheet_names,
812835
)
813836
else:
814837
sheet_names = None
@@ -853,8 +876,10 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
853876

854877
except Exception as e:
855878
self.report.logger.error(
856-
f"Error generating content for DataFrame: {dataframe.title}. "
857-
f"Error: {str(e)}"
879+
"Error generating content for DataFrame: %s. Error: %s",
880+
dataframe.title,
881+
e,
882+
exc_info=True,
858883
)
859884
raise
860885
# Add caption if available
@@ -863,7 +888,7 @@ def _generate_dataframe_content(self, dataframe) -> List[str]:
863888
dataframe_content.append(f">{dataframe.caption}\n")
864889

865890
self.report.logger.info(
866-
f"Successfully generated content for DataFrame: '{dataframe.title}'"
891+
"Successfully generated content for DataFrame: '%s'", dataframe.title
867892
)
868893
return dataframe_content
869894

@@ -922,8 +947,10 @@ def _generate_markdown_content(self, markdown) -> List[str]:
922947

923948
except Exception as e:
924949
self.report.logger.error(
925-
f"Error generating content for Markdown: {markdown.title}. "
926-
f"Error: {str(e)}"
950+
"Error generating content for Markdown: %s. Error: %s",
951+
markdown.title,
952+
e,
953+
exc_info=True,
927954
)
928955
raise
929956

@@ -932,7 +959,7 @@ def _generate_markdown_content(self, markdown) -> List[str]:
932959
markdown_content.append(f">{markdown.caption}\n")
933960

934961
self.report.logger.info(
935-
f"Successfully generated content for Markdown: '{markdown.title}'"
962+
"Successfully generated content for Markdown: '%s'", markdown.title
936963
)
937964
return markdown_content
938965

@@ -1020,12 +1047,15 @@ def _generate_html_content(self, html) -> List[str]:
10201047

10211048
except Exception as e:
10221049
self.report.logger.error(
1023-
f"Error generating content for HTML: {html.title}. Error: {str(e)}"
1050+
"Error generating content for HTML: %s. Error: %s",
1051+
html.title,
1052+
e,
1053+
exc_info=True,
10241054
)
10251055
raise
10261056

10271057
self.report.logger.info(
1028-
f"Successfully generated content for HTML: '{html.title}'"
1058+
"Successfully generated content for HTML: '%s'", html.title
10291059
)
10301060
return html_content
10311061

src/vuegen/report.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,13 @@ def read_network(self) -> nx.Graph:
240240
delimiter = "," if file_extension == ".csv" else "\\t"
241241
try:
242242
df_net = pd.read_csv(file_stream, delimiter=delimiter)
243-
except pd.errors.ParserError:
243+
except pd.errors.ParserError as e:
244244
self.logger.error(
245245
"Error parsing CSV/TXT file %s. "
246-
"Please check the file format or delimiter.",
246+
"Please check the file format or delimiter: %s.",
247247
self.file_path,
248+
e,
249+
exc_info=True,
248250
)
249251

250252
if self.csv_network_format == CSVNetworkFormat.EDGELIST:
@@ -256,8 +258,8 @@ def read_network(self) -> nx.Graph:
256258
required_columns.difference(df_net.columns)
257259
)
258260
self.logger.error(
259-
"CSV network file must contain 'source' and 'target' columns."
260-
" Missing columns: %s.",
261+
"CSV network file must contain 'source' and 'target'"
262+
" columns. Missing columns: %s.",
261263
missing_cols,
262264
)
263265

0 commit comments

Comments
 (0)