12
12
from typing import Any , Dict , Optional , Tuple
13
13
14
14
from kedro import __version__
15
+ from kedro .framework .session import KedroSession
15
16
from kedro .framework .session .store import BaseSessionStore
16
17
17
18
try :
32
33
from kedro .io import DataCatalog
33
34
from kedro .io .core import get_filepath_str
34
35
from kedro .pipeline import Pipeline
35
- from semver import VersionInfo
36
+
37
+ from kedro_viz .constants import KEDRO_VERSION
36
38
37
39
logger = logging .getLogger (__name__ )
38
- KEDRO_VERSION = VersionInfo .parse (__version__ )
40
+
41
+
42
+ class _VizNullPluginManager :
43
+ """This class creates an empty ``hook_manager`` that will ignore all calls to hooks
44
+ and registered plugins allowing the runner to function if no ``hook_manager``
45
+ has been instantiated.
46
+
47
+ NOTE: _VizNullPluginManager is a clone of _NullPluginManager class in Kedro.
48
+ This was introduced to support the earliest version of Kedro which does not
49
+ have _NullPluginManager defined
50
+ """
51
+
52
+ def __init__ (self , * args , ** kwargs ):
53
+ pass
54
+
55
+ def __getattr__ (self , name ):
56
+ return self
57
+
58
+ def __call__ (self , * args , ** kwargs ):
59
+ pass
39
60
40
61
41
62
def _bootstrap (project_path : Path ):
@@ -58,7 +79,7 @@ def _bootstrap(project_path: Path):
58
79
return
59
80
60
81
61
- def get_dataset_stats (project_path : Path ) -> Dict :
82
+ def _get_dataset_stats (project_path : Path ) -> Dict :
62
83
"""Return the stats saved at stats.json as a dictionary if found.
63
84
If not, return an empty dictionary
64
85
@@ -87,13 +108,15 @@ def get_dataset_stats(project_path: Path) -> Dict:
87
108
def load_data (
88
109
project_path : Path ,
89
110
env : Optional [str ] = None ,
111
+ ignore_plugins : bool = False ,
90
112
extra_params : Optional [Dict [str , Any ]] = None ,
91
113
) -> Tuple [DataCatalog , Dict [str , Pipeline ], BaseSessionStore , Dict ]:
92
114
"""Load data from a Kedro project.
93
115
Args:
94
116
project_path: the path whether the Kedro project is located.
95
117
env: the Kedro environment to load the data. If not provided.
96
118
it will use Kedro default, which is local.
119
+ ignore_plugins: the flag to unregister all installed plugins in a kedro project.
97
120
extra_params: Optional dictionary containing extra project parameters
98
121
for underlying KedroContext. If specified, will update (and therefore
99
122
take precedence over) the parameters retrieved from the project
@@ -106,41 +129,46 @@ def load_data(
106
129
107
130
if KEDRO_VERSION .match (">=0.17.3" ):
108
131
from kedro .framework .project import pipelines
109
- from kedro .framework .session import KedroSession
110
132
111
133
with KedroSession .create (
112
134
project_path = project_path ,
113
135
env = env , # type: ignore
114
136
save_on_close = False ,
115
137
extra_params = extra_params , # type: ignore
116
138
) as session :
139
+ # check for --ignore-plugins option
140
+ if ignore_plugins :
141
+ session ._hook_manager = _VizNullPluginManager ()
142
+
117
143
context = session .load_context ()
118
144
session_store = session ._store
119
145
catalog = context .catalog
146
+
120
147
# Pipelines is a lazy dict-like object, so we force it to populate here
121
148
# in case user doesn't have an active session down the line when it's first accessed.
122
149
# Useful for users who have `get_current_session` in their `register_pipelines()`.
123
150
pipelines_dict = dict (pipelines )
124
- stats_dict = get_dataset_stats (project_path )
151
+ stats_dict = _get_dataset_stats (project_path )
125
152
126
153
return catalog , pipelines_dict , session_store , stats_dict
127
154
elif KEDRO_VERSION .match (">=0.17.1" ):
128
- from kedro .framework .session import KedroSession
129
-
130
155
with KedroSession .create (
131
156
project_path = project_path ,
132
157
env = env , # type: ignore
133
158
save_on_close = False ,
134
159
extra_params = extra_params , # type: ignore
135
160
) as session :
161
+ # check for --ignore-plugins option
162
+ if ignore_plugins :
163
+ session ._hook_manager = _VizNullPluginManager ()
164
+
136
165
context = session .load_context ()
137
166
session_store = session ._store
138
- stats_dict = get_dataset_stats (project_path )
167
+ stats_dict = _get_dataset_stats (project_path )
139
168
140
169
return context .catalog , context .pipelines , session_store , stats_dict
141
170
else :
142
171
# Since Viz is only compatible with kedro>=0.17.0, this just matches 0.17.0
143
- from kedro .framework .session import KedroSession
144
172
from kedro .framework .startup import _get_project_metadata
145
173
146
174
metadata = _get_project_metadata (project_path )
@@ -151,9 +179,13 @@ def load_data(
151
179
save_on_close = False ,
152
180
extra_params = extra_params , # type: ignore
153
181
) as session :
182
+ # check for --ignore-plugins option
183
+ if ignore_plugins :
184
+ session ._hook_manager = _VizNullPluginManager ()
185
+
154
186
context = session .load_context ()
155
187
session_store = session ._store
156
- stats_dict = get_dataset_stats (project_path )
188
+ stats_dict = _get_dataset_stats (project_path )
157
189
158
190
return context .catalog , context .pipelines , session_store , stats_dict
159
191
0 commit comments