Skip to content

Commit 7386c2a

Browse files
franciscojavierarceoantznette1
authored andcommitted
feat: Add Pytorch template (feast-dev#5780)
* feat: Add PyTorch NLP template with sentiment analysis and update CLI to support repo-path * feat: Add PyTorch NLP template with sentiment analysis and update CLI to support repo-path * fix linter Signed-off-by: Francisco Javier Arceo <farceo@redhat.com> --------- Signed-off-by: Francisco Javier Arceo <farceo@redhat.com> Signed-off-by: Anthonette Adanyin <106275232+antznette1@users.noreply.github.com>
1 parent aaca79c commit 7386c2a

10 files changed

Lines changed: 1654 additions & 15 deletions

File tree

sdk/python/feast/cli/cli.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,21 +412,26 @@ def materialize_incremental_command(ctx: click.Context, end_ts: str, views: List
412412
"milvus",
413413
"ray",
414414
"ray_rag",
415+
"pytorch_nlp",
415416
],
416417
case_sensitive=False,
417418
),
418419
help="Specify a template for the created project",
419420
default="local",
420421
)
421-
def init_command(project_directory, minimal: bool, template: str):
422+
@click.option(
423+
"--repo-path",
424+
help="Directory path where the repository will be created (default: create subdirectory with project name)",
425+
)
426+
def init_command(project_directory, minimal: bool, template: str, repo_path: str):
422427
"""Create a new Feast repository"""
423428
if not project_directory:
424429
project_directory = generate_project_name()
425430

426431
if minimal:
427432
template = "minimal"
428433

429-
init_repo(project_directory, template)
434+
init_repo(project_directory, template, repo_path)
430435

431436

432437
@cli.command("listen")

sdk/python/feast/repo_operations.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -445,27 +445,37 @@ def cli_check_repo(repo_path: Path, fs_yaml_file: Path):
445445
sys.exit(1)
446446

447447

448-
def init_repo(repo_name: str, template: str):
448+
def init_repo(repo_name: str, template: str, repo_path: Optional[str] = None):
449449
import os
450450
from pathlib import Path
451451
from shutil import copytree
452452

453453
from colorama import Fore, Style
454454

455+
# Validate project name
455456
if not is_valid_name(repo_name):
456457
raise BadParameter(
457458
message="Name should be alphanumeric values, underscores, and hyphens but not start with an underscore or hyphen",
458459
param_hint="PROJECT_DIRECTORY",
459460
)
460-
repo_path = Path(os.path.join(Path.cwd(), repo_name))
461-
repo_path.mkdir(exist_ok=True)
462-
repo_config_path = repo_path / "feature_store.yaml"
463461

464-
if repo_config_path.exists():
465-
new_directory = os.path.relpath(repo_path, os.getcwd())
462+
# Determine where to create the repository
463+
if repo_path:
464+
# User specified a custom path
465+
target_path = Path(repo_path).resolve()
466+
target_path.mkdir(parents=True, exist_ok=True)
467+
display_path = repo_path
468+
else:
469+
# Default behavior: create subdirectory with project name
470+
target_path = Path(os.path.join(Path.cwd(), repo_name))
471+
target_path.mkdir(exist_ok=True)
472+
display_path = repo_name
466473

474+
repo_config_path = target_path / "feature_store.yaml"
475+
476+
if repo_config_path.exists():
467477
print(
468-
f"The directory {Style.BRIGHT + Fore.GREEN}{new_directory}{Style.RESET_ALL} contains an existing feature "
478+
f"The directory {Style.BRIGHT + Fore.GREEN}{display_path}{Style.RESET_ALL} contains an existing feature "
469479
f"store repository that may cause a conflict"
470480
)
471481
print()
@@ -475,14 +485,14 @@ def init_repo(repo_name: str, template: str):
475485
template_path = str(Path(Path(__file__).parent / "templates" / template).absolute())
476486
if not os.path.exists(template_path):
477487
raise IOError(f"Could not find template {template}")
478-
copytree(template_path, str(repo_path), dirs_exist_ok=True)
488+
copytree(template_path, str(target_path), dirs_exist_ok=True)
479489

480490
# Rename gitignore files back to .gitignore
481-
for gitignore_path in repo_path.rglob("gitignore"):
491+
for gitignore_path in target_path.rglob("gitignore"):
482492
gitignore_path.rename(gitignore_path.with_name(".gitignore"))
483493

484494
# Seed the repository
485-
bootstrap_path = repo_path / "bootstrap.py"
495+
bootstrap_path = target_path / "bootstrap.py"
486496
if os.path.exists(bootstrap_path):
487497
import importlib.util
488498

@@ -495,21 +505,21 @@ def init_repo(repo_name: str, template: str):
495505
os.remove(bootstrap_path)
496506

497507
# Template the feature_store.yaml file
498-
feature_store_yaml_path = repo_path / "feature_repo" / "feature_store.yaml"
508+
feature_store_yaml_path = target_path / "feature_repo" / "feature_store.yaml"
499509
replace_str_in_file(
500510
feature_store_yaml_path, "project: my_project", f"project: {repo_name}"
501511
)
502512

503513
# Remove the __pycache__ folder if it exists
504514
import shutil
505515

506-
shutil.rmtree(repo_path / "__pycache__", ignore_errors=True)
516+
shutil.rmtree(target_path / "__pycache__", ignore_errors=True)
507517

508518
import click
509519

510520
click.echo()
511521
click.echo(
512-
f"Creating a new Feast repository in {Style.BRIGHT + Fore.GREEN}{repo_path}{Style.RESET_ALL}."
522+
f"Creating a new Feast repository in {Style.BRIGHT + Fore.GREEN}{target_path}{Style.RESET_ALL}."
513523
)
514524
click.echo()
515525

0 commit comments

Comments
 (0)