def get_repo(path: Optional[str] = None, experiment_name: Optional[str] = None) -> AimRepo: # Auto commit if os.getenv(AIM_AUTOMATED_EXEC_ENV_VAR): # Get Aim environment variables branch_name = os.getenv(AIM_BRANCH_ENV_VAR) commit_hash = os.getenv(AIM_COMMIT_ENV_VAR) else: commit_hash = AimRepo.generate_commit_hash() if experiment_name is not None: branch_name = experiment_name else: # FIXME: Get active experiment name from given repo # if path is specified. Currently active experiment name of # the highest repo in the hierarchy will be returned. branch_name = AimRepo.get_active_branch_if_exists() \ or AIM_DEFAULT_BRANCH_NAME if path is not None: repo = AimRepo(path) if not repo.exists(): if not repo.init(): raise ValueError('can not create repo `{}`'.format(path)) repo = AimRepo(path, branch_name, commit_hash) else: if AimRepo.get_working_repo() is None: path = os.getcwd() repo = AimRepo(path) if not repo.init(): raise ValueError('can not create repo `{}`'.format(path)) repo = AimRepo(path, branch_name, commit_hash) else: repo = AimRepo.get_working_repo(branch_name, commit_hash) return repo
def init(): """ Initializes new repository in the current working directory: - Creates .aim directory - Adds .aim/config.json file with initial configuration """ repo = AimRepo(os.getcwd()) re_init = False # Check whether repo already exists if repo.exists(): re_init = click.confirm('Aim repository is already initialized. ' + 'Do you want to re-initialize it?') if not re_init: return # Clear old repo repo.rm() # Init repo new_repo = AimRepo(os.getcwd()) if new_repo.init(): if re_init: click.echo( 'Re-initialized empty Aim repository at {}'.format(new_repo)) else: click.echo(('Initialized a new ' + 'Aim repository at {}').format(new_repo))
def init(): repo = AimRepo(os.getcwd()) re_init = False # Check whether repo already exists if repo.exists(): re_init = click.confirm('Aim repository is already initialized. ' + 'Do you want to re-initialize it?') if not re_init: return # Clear old repo repo.rm() # Init repo new_repo = AimRepo(os.getcwd()) if new_repo.init(): if re_init: click.echo( 'Re-initialized empty Aim repository in {}'.format(new_repo)) else: click.echo(('Initialized empty ' + 'Aim repository in {}').format(new_repo))