11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
- import base64
15
14
import json
16
15
import logging
17
- import os
18
- import tempfile
19
16
from datetime import datetime
20
17
from pathlib import Path
21
18
from typing import List , Optional
28
25
from pygments import formatters , highlight , lexers
29
26
30
27
from feast import utils
31
- from feast .constants import (
32
- DEFAULT_FEATURE_TRANSFORMATION_SERVER_PORT ,
33
- FEATURE_STORE_YAML_ENV_NAME ,
34
- )
28
+ from feast .constants import DEFAULT_FEATURE_TRANSFORMATION_SERVER_PORT
35
29
from feast .errors import FeastObjectNotFoundException , FeastProviderLoginError
36
- from feast .feature_store import FeatureStore
37
30
from feast .feature_view import FeatureView
38
31
from feast .on_demand_feature_view import OnDemandFeatureView
39
32
from feast .repo_config import load_repo_config
40
33
from feast .repo_operations import (
41
34
apply_total ,
42
35
cli_check_repo ,
36
+ create_feature_store ,
43
37
generate_project_name ,
44
38
init_repo ,
45
39
plan ,
@@ -172,10 +166,7 @@ def ui(
172
166
"""
173
167
Shows the Feast UI over the current directory
174
168
"""
175
- repo = ctx .obj ["CHDIR" ]
176
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
177
- cli_check_repo (repo , fs_yaml_file )
178
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
169
+ store = create_feature_store (ctx )
179
170
# Pass in the registry_dump method to get around a circular dependency
180
171
store .serve_ui (
181
172
host = host ,
@@ -192,10 +183,7 @@ def endpoint(ctx: click.Context):
192
183
"""
193
184
Display feature server endpoints
194
185
"""
195
- repo = ctx .obj ["CHDIR" ]
196
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
197
- cli_check_repo (repo , fs_yaml_file )
198
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
186
+ store = create_feature_store (ctx )
199
187
endpoint = store .get_feature_server_endpoint ()
200
188
if endpoint is not None :
201
189
_logger .info (
@@ -220,10 +208,7 @@ def data_source_describe(ctx: click.Context, name: str):
220
208
"""
221
209
Describe a data source
222
210
"""
223
- repo = ctx .obj ["CHDIR" ]
224
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
225
- cli_check_repo (repo , fs_yaml_file )
226
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
211
+ store = create_feature_store (ctx )
227
212
228
213
try :
229
214
data_source = store .get_data_source (name )
@@ -244,10 +229,7 @@ def data_source_list(ctx: click.Context):
244
229
"""
245
230
List all data sources
246
231
"""
247
- repo = ctx .obj ["CHDIR" ]
248
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
249
- cli_check_repo (repo , fs_yaml_file )
250
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
232
+ store = create_feature_store (ctx )
251
233
table = []
252
234
for datasource in store .list_data_sources ():
253
235
table .append ([datasource .name , datasource .__class__ ])
@@ -272,10 +254,7 @@ def entity_describe(ctx: click.Context, name: str):
272
254
"""
273
255
Describe an entity
274
256
"""
275
- repo = ctx .obj ["CHDIR" ]
276
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
277
- cli_check_repo (repo , fs_yaml_file )
278
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
257
+ store = create_feature_store (ctx )
279
258
280
259
try :
281
260
entity = store .get_entity (name )
@@ -296,10 +275,7 @@ def entity_list(ctx: click.Context):
296
275
"""
297
276
List all entities
298
277
"""
299
- repo = ctx .obj ["CHDIR" ]
300
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
301
- cli_check_repo (repo , fs_yaml_file )
302
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
278
+ store = create_feature_store (ctx )
303
279
table = []
304
280
for entity in store .list_entities ():
305
281
table .append ([entity .name , entity .description , entity .value_type ])
@@ -324,10 +300,7 @@ def feature_service_describe(ctx: click.Context, name: str):
324
300
"""
325
301
Describe a feature service
326
302
"""
327
- repo = ctx .obj ["CHDIR" ]
328
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
329
- cli_check_repo (repo , fs_yaml_file )
330
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
303
+ store = create_feature_store (ctx )
331
304
332
305
try :
333
306
feature_service = store .get_feature_service (name )
@@ -350,10 +323,7 @@ def feature_service_list(ctx: click.Context):
350
323
"""
351
324
List all feature services
352
325
"""
353
- repo = ctx .obj ["CHDIR" ]
354
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
355
- cli_check_repo (repo , fs_yaml_file )
356
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
326
+ store = create_feature_store (ctx )
357
327
feature_services = []
358
328
for feature_service in store .list_feature_services ():
359
329
feature_names = []
@@ -383,10 +353,7 @@ def feature_view_describe(ctx: click.Context, name: str):
383
353
"""
384
354
Describe a feature view
385
355
"""
386
- repo = ctx .obj ["CHDIR" ]
387
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
388
- cli_check_repo (repo , fs_yaml_file )
389
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
356
+ store = create_feature_store (ctx )
390
357
391
358
try :
392
359
feature_view = store .get_feature_view (name )
@@ -407,11 +374,7 @@ def feature_view_list(ctx: click.Context):
407
374
"""
408
375
List all feature views
409
376
"""
410
- repo = ctx .obj ["CHDIR" ]
411
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
412
-
413
- cli_check_repo (repo , fs_yaml_file )
414
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
377
+ store = create_feature_store (ctx )
415
378
table = []
416
379
for feature_view in [
417
380
* store .list_feature_views (),
@@ -452,10 +415,7 @@ def on_demand_feature_view_describe(ctx: click.Context, name: str):
452
415
"""
453
416
[Experimental] Describe an on demand feature view
454
417
"""
455
- repo = ctx .obj ["CHDIR" ]
456
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
457
- cli_check_repo (repo , fs_yaml_file )
458
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
418
+ store = create_feature_store (ctx )
459
419
460
420
try :
461
421
on_demand_feature_view = store .get_on_demand_feature_view (name )
@@ -478,10 +438,7 @@ def on_demand_feature_view_list(ctx: click.Context):
478
438
"""
479
439
[Experimental] List all on demand feature views
480
440
"""
481
- repo = ctx .obj ["CHDIR" ]
482
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
483
- cli_check_repo (repo , fs_yaml_file )
484
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
441
+ store = create_feature_store (ctx )
485
442
table = []
486
443
for on_demand_feature_view in store .list_on_demand_feature_views ():
487
444
table .append ([on_demand_feature_view .name ])
@@ -583,10 +540,8 @@ def materialize_command(
583
540
584
541
START_TS and END_TS should be in ISO 8601 format, e.g. '2021-07-16T19:20:01'
585
542
"""
586
- repo = ctx .obj ["CHDIR" ]
587
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
588
- cli_check_repo (repo , fs_yaml_file )
589
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
543
+ store = create_feature_store (ctx )
544
+
590
545
store .materialize (
591
546
feature_views = None if not views else views ,
592
547
start_date = utils .make_tzaware (parser .parse (start_ts )),
@@ -612,10 +567,7 @@ def materialize_incremental_command(ctx: click.Context, end_ts: str, views: List
612
567
613
568
END_TS should be in ISO 8601 format, e.g. '2021-07-16T19:20:01'
614
569
"""
615
- repo = ctx .obj ["CHDIR" ]
616
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
617
- cli_check_repo (repo , fs_yaml_file )
618
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
570
+ store = create_feature_store (ctx )
619
571
store .materialize_incremental (
620
572
feature_views = None if not views else views ,
621
573
end_date = utils .make_tzaware (datetime .fromisoformat (end_ts )),
@@ -707,22 +659,7 @@ def serve_command(
707
659
no_feature_log : bool ,
708
660
):
709
661
"""Start a feature server locally on a given port."""
710
- repo = ctx .obj ["CHDIR" ]
711
-
712
- # If we received a base64 encoded version of feature_store.yaml, use that
713
- config_base64 = os .getenv (FEATURE_STORE_YAML_ENV_NAME )
714
- if config_base64 :
715
- print ("Received base64 encoded feature_store.yaml" )
716
- config_bytes = base64 .b64decode (config_base64 )
717
- # Create a new unique directory for writing feature_store.yaml
718
- repo_path = Path (tempfile .mkdtemp ())
719
- with open (repo_path / "feature_store.yaml" , "wb" ) as f :
720
- f .write (config_bytes )
721
- store = FeatureStore (repo_path = str (repo_path .resolve ()))
722
- else :
723
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
724
- cli_check_repo (repo , fs_yaml_file )
725
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
662
+ store = create_feature_store (ctx )
726
663
727
664
store .serve (host , port , type_ , no_access_log , no_feature_log )
728
665
@@ -738,10 +675,7 @@ def serve_command(
738
675
@click .pass_context
739
676
def serve_transformations_command (ctx : click .Context , port : int ):
740
677
"""[Experimental] Start a feature consumption server locally on a given port."""
741
- repo = ctx .obj ["CHDIR" ]
742
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
743
- cli_check_repo (repo , fs_yaml_file )
744
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
678
+ store = create_feature_store (ctx )
745
679
746
680
store .serve_transformations (port )
747
681
@@ -778,10 +712,7 @@ def validate(
778
712
779
713
START_TS and END_TS should be in ISO 8601 format, e.g. '2021-07-16T19:20:01'
780
714
"""
781
- repo = ctx .obj ["CHDIR" ]
782
- fs_yaml_file = ctx .obj ["FS_YAML_FILE" ]
783
- cli_check_repo (repo , fs_yaml_file )
784
- store = FeatureStore (repo_path = str (repo ), fs_yaml_file = fs_yaml_file )
715
+ store = create_feature_store (ctx )
785
716
786
717
feature_service = store .get_feature_service (name = feature_service )
787
718
reference = store .get_validation_reference (reference )
0 commit comments