From 6d54e1e0896f0c3e59cefd8966d68bc9603c981f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bel=C3=A1k?= Date: Tue, 26 Sep 2023 15:07:37 +0200 Subject: [PATCH 1/2] refactor: move default imports to a constant Preparatory commit for testing of exported code being able to execute (#8). --- edvart/report.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/edvart/report.py b/edvart/report.py index 8a1c19b..0bc0308 100755 --- a/edvart/report.py +++ b/edvart/report.py @@ -37,6 +37,14 @@ class ReportBase(ABC): The default verbosity for the exported code of the entire report, by default Verbosity.LOW. """ + _DEFAULT_IMPORTS = { + "import pandas as pd", + "import os", + "from typing import Any, Callable, Dict, List, Optional, Tuple, Union", + "import plotly.offline as py", + "import plotly.io as pio", + } + def __init__( self, dataframe: pd.DataFrame, @@ -119,13 +127,7 @@ def _generate_notebook( ) # Add imports cell - imports_set = { - "import pandas as pd", - "import os", - "from typing import Any, Callable, Dict, List, Optional, Tuple, Union", - "import plotly.offline as py", - "import plotly.io as pio", - } + imports_set = self._DEFAULT_IMPORTS if extra_imports is not None: imports_set.update(extra_imports) for section in self.sections: From 43f876192298cf8ec699306a4c34488d3923b311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bel=C3=A1k?= Date: Fri, 29 Sep 2023 09:16:21 +0200 Subject: [PATCH 2/2] add copying of the constant --- edvart/report.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/edvart/report.py b/edvart/report.py index 0bc0308..03b1907 100755 --- a/edvart/report.py +++ b/edvart/report.py @@ -4,6 +4,7 @@ import logging import pickle from abc import ABC +from copy import copy from typing import List, Optional, Tuple, Union import isort @@ -127,7 +128,7 @@ def _generate_notebook( ) # Add imports cell - imports_set = self._DEFAULT_IMPORTS + imports_set = copy(self._DEFAULT_IMPORTS) if extra_imports is not None: imports_set.update(extra_imports) for section in self.sections: