Repository: microsoft/qlib
File: qlib/config.py (Python)

Code before:
    # URI_TYPE
    LOCAL_URI = "local"
    NFS_URI = "nfs"

    def set_mode(self, mode):
        # raise KeyError
        self.update(MODE_CONF[mode])
        # TODO: update region based on kwargs

    def set_region(self, region):
        # raise KeyError
        self.update(_default_region_config[region])

    def resolve_path(self):
        # resolve path
        if self["mount_path"] is not None:
            self["mount_path"] = str(Path(self["mount_path"]).expanduser().resolve())

        if self.get_uri_type() == QlibConfig.LOCAL_URI:
            self["provider_uri"] = str(Path(self["provider_uri"]).expanduser().resolve())

    def get_uri_type(self):
        win_rm = re.match("^[a-zA-Z]:.*", self["provider_uri"])
        nfs_or_win_rm = re.match("^[^/]+:.+", self["provider_uri"])
        # Windows path is "C:\\"
        if win_rm is None:
            if nfs_or_win_rm is None:
                return QlibConfig.LOCAL_URI
            else:
                return QlibConfig.NFS_URI
        else:
            return QlibConfig.LOCAL_URI

    def get_data_path(self):
        if self.get_uri_type() == QlibConfig.LOCAL_URI:
            return self["provider_uri"]
        elif self.get_uri_type() == QlibConfig.NFS_URI:
            return self["mount_path"]
        else:
            raise NotImplementedError(f"This type of uri is not supported")


# global config
C = QlibConfig(_default_config)


Review comment (suggestion):
The logic could be simpler
```python
win = re.match("^[a-zA-Z]:.*", self["provider_uri"]) is not None  # such as 'C:\\data', 'D:'
nfs_or_win = re.match("^[^/]+:.+", self["provider_uri"]) is not None  # such as 'host:/data/'   (User may define short hostname by themselves)

if nfs_or_win and not win:
     return QlibConfig.NFS_URI
else:
     return QlibConfig.LOCAL_URI
```

Code after:
    # URI_TYPE
    LOCAL_URI = "local"
    NFS_URI = "nfs"

    def set_mode(self, mode):
        # raise KeyError
        self.update(MODE_CONF[mode])
        # TODO: update region based on kwargs

    def set_region(self, region):
        # raise KeyError
        self.update(_default_region_config[region])

    def resolve_path(self):
        # resolve path
        if self["mount_path"] is not None:
            self["mount_path"] = str(Path(self["mount_path"]).expanduser().resolve())

        if self.get_uri_type() == QlibConfig.LOCAL_URI:
            self["provider_uri"] = str(Path(self["provider_uri"]).expanduser().resolve())

    def get_uri_type(self):
        is_win = re.match("^[a-zA-Z]:.*", self["provider_uri"]) is not None  # such as 'C:\\data', 'D:'
        is_nfs_or_win = re.match("^[^/]+:.+", self["provider_uri"]) is not None  # such as 'host:/data/'   (User may define short hostname by themselves or use localhost)

        if is_nfs_or_win and not is_win:
            return QlibConfig.NFS_URI
        else:
            return QlibConfig.LOCAL_URI

    def get_data_path(self):
        if self.get_uri_type() == QlibConfig.LOCAL_URI:
            return self["provider_uri"]
        elif self.get_uri_type() == QlibConfig.NFS_URI:
            return self["mount_path"]
        else:
            raise NotImplementedError(f"This type of uri is not supported")


# global config
C = QlibConfig(_default_config)