@@ -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