|
21 | 21 | import pkg_resources |
22 | 22 | import yaml |
23 | 23 |
|
24 | | -from feast import utils |
| 24 | +from feast import flags, flags_helper, utils |
25 | 25 | from feast.errors import FeastObjectNotFoundException, FeastProviderLoginError |
26 | 26 | from feast.feature_store import FeatureStore |
27 | 27 | from feast.repo_config import load_repo_config |
@@ -423,5 +423,112 @@ def serve_command(ctx: click.Context, port: int): |
423 | 423 | store.serve(port) |
424 | 424 |
|
425 | 425 |
|
| 426 | +@cli.group(name="alpha") |
| 427 | +def alpha_cmd(): |
| 428 | + """ |
| 429 | + Access alpha features |
| 430 | + """ |
| 431 | + pass |
| 432 | + |
| 433 | + |
| 434 | +@alpha_cmd.command("list") |
| 435 | +@click.pass_context |
| 436 | +def list_alpha_features(ctx: click.Context): |
| 437 | + """ |
| 438 | + Lists all alpha features |
| 439 | + """ |
| 440 | + repo = ctx.obj["CHDIR"] |
| 441 | + cli_check_repo(repo) |
| 442 | + repo_path = str(repo) |
| 443 | + store = FeatureStore(repo_path=repo_path) |
| 444 | + |
| 445 | + flags_to_show = flags.FLAG_NAMES.copy() |
| 446 | + flags_to_show.remove(flags.FLAG_ALPHA_FEATURES_NAME) |
| 447 | + print("Alpha features:") |
| 448 | + for flag in flags_to_show: |
| 449 | + enabled_string = ( |
| 450 | + "enabled" |
| 451 | + if flags_helper.feature_flag_enabled(store.config, flag) |
| 452 | + else "disabled" |
| 453 | + ) |
| 454 | + print(f"{flag}: {enabled_string}") |
| 455 | + |
| 456 | + |
| 457 | +@alpha_cmd.command("enable-all") |
| 458 | +@click.pass_context |
| 459 | +def enable_alpha_features(ctx: click.Context): |
| 460 | + """ |
| 461 | + Enables all alpha features |
| 462 | + """ |
| 463 | + repo = ctx.obj["CHDIR"] |
| 464 | + cli_check_repo(repo) |
| 465 | + repo_path = str(repo) |
| 466 | + store = FeatureStore(repo_path=repo_path) |
| 467 | + |
| 468 | + if store.config.flags is None: |
| 469 | + store.config.flags = {} |
| 470 | + for flag_name in flags.FLAG_NAMES: |
| 471 | + store.config.flags[flag_name] = True |
| 472 | + store.config.write_to_path(Path(repo_path)) |
| 473 | + |
| 474 | + |
| 475 | +@alpha_cmd.command("enable") |
| 476 | +@click.argument("name", type=click.STRING) |
| 477 | +@click.pass_context |
| 478 | +def enable_alpha_feature(ctx: click.Context, name: str): |
| 479 | + """ |
| 480 | + Enables an alpha feature |
| 481 | + """ |
| 482 | + if name not in flags.FLAG_NAMES: |
| 483 | + raise ValueError(f"Flag name, {name}, not valid.") |
| 484 | + |
| 485 | + repo = ctx.obj["CHDIR"] |
| 486 | + cli_check_repo(repo) |
| 487 | + repo_path = str(repo) |
| 488 | + store = FeatureStore(repo_path=repo_path) |
| 489 | + |
| 490 | + if store.config.flags is None: |
| 491 | + store.config.flags = {} |
| 492 | + store.config.flags[flags.FLAG_ALPHA_FEATURES_NAME] = True |
| 493 | + store.config.flags[name] = True |
| 494 | + store.config.write_to_path(Path(repo_path)) |
| 495 | + |
| 496 | + |
| 497 | +@alpha_cmd.command("disable") |
| 498 | +@click.argument("name", type=click.STRING) |
| 499 | +@click.pass_context |
| 500 | +def disable_alpha_feature(ctx: click.Context, name: str): |
| 501 | + """ |
| 502 | + Disables an alpha feature |
| 503 | + """ |
| 504 | + if name not in flags.FLAG_NAMES: |
| 505 | + raise ValueError(f"Flag name, {name}, not valid.") |
| 506 | + |
| 507 | + repo = ctx.obj["CHDIR"] |
| 508 | + cli_check_repo(repo) |
| 509 | + repo_path = str(repo) |
| 510 | + store = FeatureStore(repo_path=repo_path) |
| 511 | + |
| 512 | + if store.config.flags is None or name not in store.config.flags: |
| 513 | + return |
| 514 | + store.config.flags[name] = False |
| 515 | + store.config.write_to_path(Path(repo_path)) |
| 516 | + |
| 517 | + |
| 518 | +@alpha_cmd.command("disable-all") |
| 519 | +@click.pass_context |
| 520 | +def disable_alpha_features(ctx: click.Context): |
| 521 | + """ |
| 522 | + Disables all alpha features |
| 523 | + """ |
| 524 | + repo = ctx.obj["CHDIR"] |
| 525 | + cli_check_repo(repo) |
| 526 | + repo_path = str(repo) |
| 527 | + store = FeatureStore(repo_path=repo_path) |
| 528 | + |
| 529 | + store.config.flags = None |
| 530 | + store.config.write_to_path(Path(repo_path)) |
| 531 | + |
| 532 | + |
426 | 533 | if __name__ == "__main__": |
427 | 534 | cli() |
0 commit comments