From 2ed834e954a7b564db39646ff7b6b085522a4475 Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Mon, 5 May 2025 11:17:35 +0200 Subject: [PATCH 1/2] :art: remove f-strings, imports or vars if not needed --- src/vuegen/quarto_reportview.py | 10 +++++----- src/vuegen/report.py | 1 - src/vuegen/streamlit_reportview.py | 13 ++++++------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/vuegen/quarto_reportview.py b/src/vuegen/quarto_reportview.py index af18eff..cd3881b 100644 --- a/src/vuegen/quarto_reportview.py +++ b/src/vuegen/quarto_reportview.py @@ -578,7 +578,7 @@ def _generate_plot_content(self, plot) -> List[str]: ) plot_content.append(self._generate_image_content(static_plot_path)) else: - plot_content.append(f"""fig_plotly.show()\n```\n""") + plot_content.append("""fig_plotly.show()\n```\n""") elif plot.plot_type == r.PlotType.ALTAIR: plot_content.append(self._generate_plot_code(plot)) if self.is_report_static: @@ -587,7 +587,7 @@ def _generate_plot_content(self, plot) -> List[str]: ) plot_content.append(self._generate_image_content(static_plot_path)) else: - plot_content.append(f"""fig_altair\n```\n""") + plot_content.append("""fig_altair\n```\n""") elif plot.plot_type == r.PlotType.INTERACTIVE_NETWORK: networkx_graph = plot.read_network() if isinstance(networkx_graph, tuple): @@ -595,7 +595,7 @@ def _generate_plot_content(self, plot) -> List[str]: networkx_graph, html_plot_file = networkx_graph elif isinstance(networkx_graph, nx.Graph) and not self.is_report_static: # Get the pyvis object and create html - pyvis_graph = plot.create_and_save_pyvis_network( + _ = plot.create_and_save_pyvis_network( networkx_graph, html_plot_file ) @@ -805,7 +805,7 @@ def _generate_markdown_content(self, markdown) -> List[str]: ) # Code to display md content - markdown_content.append(f"""display.Markdown(markdown_content)\n```\n""") + markdown_content.append("""display.Markdown(markdown_content)\n```\n""") except Exception as e: self.report.logger.error( @@ -926,7 +926,7 @@ def _show_dataframe(self, dataframe) -> List[str]: else: # Append code to display the DataFrame interactively dataframe_content.append( - f"""show(df, classes="display nowrap compact", lengthMenu=[3, 5, 10])\n```\n""" + """show(df, classes="display nowrap compact", lengthMenu=[3, 5, 10])\n```\n""" ) return dataframe_content diff --git a/src/vuegen/report.py b/src/vuegen/report.py index c3f6625..55aab67 100644 --- a/src/vuegen/report.py +++ b/src/vuegen/report.py @@ -1,4 +1,3 @@ -import json import logging import os from abc import ABC, abstractmethod diff --git a/src/vuegen/streamlit_reportview.py b/src/vuegen/streamlit_reportview.py index 2e568fe..4b470df 100644 --- a/src/vuegen/streamlit_reportview.py +++ b/src/vuegen/streamlit_reportview.py @@ -296,7 +296,7 @@ def run_report(self, output_dir: str = SECTIONS_DIR) -> None: f"All the scripts to build the Streamlit app are available at {output_dir}" ) self.report.logger.info( - f"To run the Streamlit app, use the following command:" + "To run the Streamlit app, use the following command:" ) self.report.logger.info( f"streamlit run {Path(output_dir) / self.REPORT_MANAG_SCRIPT}" @@ -381,7 +381,7 @@ def _generate_home_section( # Create the home page content home_content = [] - home_content.append(f"import streamlit as st") + home_content.append("import streamlit as st") if subsection_imports: home_content.extend(subsection_imports) if self.report.description: @@ -409,9 +409,9 @@ def _generate_home_section( # Add the home page to the report manager content report_manag_content.append( - f"homepage = st.Page('Home/Homepage.py', title='Homepage')" # ! here Posix Path is hardcoded + "homepage = st.Page('Home/Homepage.py', title='Homepage')" # ! here Posix Path is hardcoded ) - report_manag_content.append(f"sections_pages['Home'] = [homepage]\n") + report_manag_content.append("sections_pages['Home'] = [homepage]\n") self.report.logger.info("Home page added to the report manager content.") except Exception as e: self.report.logger.error(f"Error generating the home section: {str(e)}") @@ -430,7 +430,6 @@ def _generate_sections(self, output_dir: str) -> None: try: for section in self.report.sections[1:]: - section_name_var = section.title.replace(" ", "_") self.report.logger.debug( f"Processing section '{section.id}': '{section.title}' - {len(section.subsections)} subsection(s)" ) @@ -604,11 +603,11 @@ def _generate_plot_content(self, plot) -> List[str]: html_plot_file = ( Path(self.static_dir) / f"{plot.title.replace(' ', '_')}.html" ) - pyvis_graph = plot.create_and_save_pyvis_network( + _ = plot.create_and_save_pyvis_network( networkx_graph, html_plot_file ) - # Add number of nodes and edges to the plor conetnt + # Add number of nodes and edges to the plot content num_nodes = networkx_graph.number_of_nodes() num_edges = networkx_graph.number_of_edges() From 4af5ad19cc8049e0a638ad155e5608dbc10c32ba Mon Sep 17 00:00:00 2001 From: Henry Webel Date: Mon, 5 May 2025 11:21:12 +0200 Subject: [PATCH 2/2] :art: lint code base with ruff --- .github/workflows/cdci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cdci.yml b/.github/workflows/cdci.yml index aa458b3..f86bb11 100644 --- a/.github/workflows/cdci.yml +++ b/.github/workflows/cdci.yml @@ -27,9 +27,13 @@ jobs: python-version: ${{ matrix.python-version }} cache: "pip" # caching pip dependencies cache-dependency-path: "**/pyproject.toml" - - name: Install dependencies + - name: lint package code with ruff run: | python -m pip install --upgrade pip + pip install ruff + ruff check src + - name: Install dependencies for testing + run: | pip install pytest pip install -e . - name: Run tests