Exemple #1
0
 def get_version(cls, path: str):
     path = clean_repo_path(path)
     version_file_path = os.path.join(path, get_aim_repo_name(), 'VERSION')
     if os.path.exists(version_file_path):
         with open(version_file_path, 'r') as version_fh:
             return version_fh.read()
     return '0.0'  # old Aim repos
Exemple #2
0
    def exists(cls, path: str) -> bool:
        """Check Aim repository existence.

        Args:
            path (str): Path to Aim repository.
        Returns:
            True if repository exists, False otherwise.
        """
        path = clean_repo_path(path)
        aim_repo_path = os.path.join(path, get_aim_repo_name())
        return os.path.exists(aim_repo_path)
Exemple #3
0
def search_aim_repo(path):
    found = False
    path = os.path.abspath(path)
    while path:
        repo_path = os.path.join(path, get_aim_repo_name())
        if os.path.exists(repo_path) and os.path.isdir(repo_path):
            found = True
            return path, found
        if path == '/':
            return None, found
        path = os.path.dirname(path)
Exemple #4
0
    def rm(cls, path: str):
        """Remove Aim repository.

        Args:
            path (str): Path to Aim repository.
        """
        path = clean_repo_path(path)
        repo = cls._pool.get(path)
        if repo is not None:
            del cls._pool[path]
        aim_repo_path = os.path.join(path, get_aim_repo_name())
        shutil.rmtree(aim_repo_path)
Exemple #5
0
def clean_repo_path(repo_path: Union[str, pathlib.Path]) -> str:
    if isinstance(repo_path, pathlib.Path):
        repo_path = str(repo_path)

    if not isinstance(repo_path, str) or not repo_path:
        return ''

    repo_path = repo_path.strip().rstrip('/')

    if isinstance(repo_path, pathlib.Path):
        repo_path = str(repo_path)
    if repo_path == '.':
        return os.getcwd()
    if repo_path == '~':
        return os.path.expanduser('~')

    if repo_path.endswith(get_aim_repo_name()):
        repo_path = repo_path[:-len(get_aim_repo_name())]
    if repo_path.startswith('~'):
        repo_path = os.path.expanduser('~') + repo_path[1:]

    return os.path.abspath(repo_path)
Exemple #6
0
    def __init__(self,
                 path: str,
                 *,
                 read_only: bool = None,
                 init: bool = False):
        if read_only is not None:
            raise NotImplementedError

        self._resources = None
        self.read_only = read_only
        self.is_remote_repo = False
        self._mount_root = None
        self._client: Client = None
        if path.startswith('ssh://'):
            self._mount_root, self.root_path = mount_remote_repo(path)
        elif path.startswith('aim://'):
            remote_path = path.replace('aim://', '')
            self._client = Client(remote_path)
            self.root_path = remote_path
            self.is_remote_repo = True
        else:
            self.root_path = path
        self.path = os.path.join(self.root_path, get_aim_repo_name())

        if init:
            os.makedirs(self.path, exist_ok=True)
            with open(os.path.join(self.path, 'VERSION'), 'w') as version_fh:
                version_fh.write(DATA_VERSION + '\n')
        if not self.is_remote_repo and not os.path.exists(self.path):
            if self._mount_root:
                unmount_remote_repo(self.root_path, self._mount_root)
            raise RuntimeError(
                f'Cannot find repository \'{self.path}\'. Please init first.')

        self.container_pool: Dict[ContainerConfig,
                                  Container] = WeakValueDictionary()
        self.persistent_pool: Dict[ContainerConfig, Container] = dict()
        self.container_view_pool: Dict[ContainerConfig,
                                       Container] = WeakValueDictionary()

        self._run_props_cache_hint = None
        self._encryption_key = None
        self.structured_db = None
        if not self.is_remote_repo:
            self.structured_db = DB.from_path(self.path)
            if init:
                self.structured_db.run_upgrades()

        self._resources = RepoAutoClean(self)
Exemple #7
0
    def __init__(self, path=None, repo_branch=None,
                 repo_commit=None,
                 repo_full_path=None,
                 mode=WRITING_MODE):
        self._config = {}
        path = clean_repo_path(path)
        self.path = repo_full_path or os.path.join(path, get_aim_repo_name())
        self.config_path = os.path.join(self.path, AIM_CONFIG_FILE_NAME)
        self.hash = hashlib.md5(self.path.encode('utf-8')).hexdigest()

        self.active_commit = repo_commit or AIM_COMMIT_INDEX_DIR_NAME
        if re.match(r'^[A-Za-z0-9_\-]{2,}$', self.active_commit) is None:
            raise ValueError('run name must be at least 2 characters ' +
                             'and contain only latin letters, numbers, ' +
                             'dash and underscore')

        self.root_path = repo_full_path or path
        self.name = self.root_path.split(os.sep)[-1]

        self.branch_path = None
        self.index_path = None
        self.objects_dir_path = None
        self.media_dir_path = None
        self.records_storage = None
        self.mode = mode

        active_exp = self.config.get('active_branch')

        if repo_branch is not None:
            experiment = repo_branch
        elif active_exp is not None:
            experiment = active_exp
        else:
            experiment = None

        if experiment is not None:
            run_full_path = get_experiment_run_path(self.path,
                                                    experiment,
                                                    self.active_commit)
        else:
            run_full_path = None

        if self.active_commit != AIM_COMMIT_INDEX_DIR_NAME and run_full_path \
                and os.path.exists(run_full_path):
            raise ValueError(('run `{}` already exists' +
                              '').format(self.active_commit))