mirror of
https://github.com/microsoft/qlib.git
synced 2026-07-10 14:26:56 +08:00
Add future calendar collector (#795)
* fix Windows mount * add future_calendar_collector * update docs Co-authored-by: Young <afe.young@gmail.com> Co-authored-by: you-n-g <you-n-g@users.noreply.github.com>
This commit is contained in:
@@ -63,7 +63,7 @@ def init(default_conf="client", **kwargs):
|
||||
else:
|
||||
logger.warning(f"auto_path is False, please make sure {mount_path} is mounted")
|
||||
elif uri_type == C.NFS_URI:
|
||||
_mount_nfs_uri(provider_uri, mount_path, C["auto_mount"])
|
||||
_mount_nfs_uri(provider_uri, C.dpm.get_data_uri(_freq), C["auto_mount"])
|
||||
else:
|
||||
raise NotImplementedError(f"This type of URI is not supported")
|
||||
|
||||
@@ -96,7 +96,7 @@ def _mount_nfs_uri(provider_uri, mount_path, auto_mount: bool = False):
|
||||
sys_type = platform.system()
|
||||
if "win" in sys_type.lower():
|
||||
# system: window
|
||||
exec_result = os.popen("mount -o anon %s %s" % (provider_uri, mount_path + ":"))
|
||||
exec_result = os.popen(f"mount -o anon {provider_uri} {mount_path}")
|
||||
result = exec_result.read()
|
||||
if "85" in result:
|
||||
LOG.warning(f"{provider_uri} on Windows:{mount_path} is already mounted")
|
||||
|
||||
@@ -269,11 +269,19 @@ class QlibConfig(Config):
|
||||
self._registered = False
|
||||
|
||||
class DataPathManager:
|
||||
def __init__(
|
||||
self,
|
||||
provider_uri: Union[str, Path, dict],
|
||||
mount_path: Union[str, Path, dict],
|
||||
):
|
||||
"""
|
||||
Motivation:
|
||||
- get the right path (e.g. data uri) for accessing data based on given information(e.g. provider_uri, mount_path and frequency)
|
||||
- some helper functions to process uri.
|
||||
"""
|
||||
|
||||
def __init__(self, provider_uri: Union[str, Path, dict], mount_path: Union[str, Path, dict]):
|
||||
|
||||
"""
|
||||
The relation of `provider_uri` and `mount_path`
|
||||
- `mount_path` is used only if provider_uri is an NFS path
|
||||
- otherwise, provider_uri will be used for accessing data
|
||||
"""
|
||||
self.provider_uri = provider_uri
|
||||
self.mount_path = mount_path
|
||||
|
||||
@@ -304,6 +312,9 @@ class QlibConfig(Config):
|
||||
return QlibConfig.LOCAL_URI
|
||||
|
||||
def get_data_uri(self, freq: Optional[Union[str, Freq]] = None) -> Path:
|
||||
"""
|
||||
please refer DataPathManager's __init__ and class doc
|
||||
"""
|
||||
if freq is not None:
|
||||
freq = str(freq) # converting Freq to string
|
||||
if freq is None or freq not in self.provider_uri:
|
||||
@@ -314,7 +325,8 @@ class QlibConfig(Config):
|
||||
elif self.get_uri_type(_provider_uri) == QlibConfig.NFS_URI:
|
||||
if "win" in platform.system().lower():
|
||||
# windows, mount_path is the drive
|
||||
return Path(f"{self.mount_path[freq]}:\\")
|
||||
_path = str(self.mount_path[freq])
|
||||
return Path(f"{_path}:\\") if ":" not in _path else Path(_path)
|
||||
return Path(self.mount_path[freq])
|
||||
else:
|
||||
raise NotImplementedError(f"This type of uri is not supported")
|
||||
@@ -351,9 +363,7 @@ class QlibConfig(Config):
|
||||
for _freq in _provider_uri.keys():
|
||||
# mount_path
|
||||
_mount_path[_freq] = (
|
||||
_mount_path[_freq]
|
||||
if _mount_path[_freq] is None
|
||||
else str(Path(_mount_path[_freq]).expanduser().resolve())
|
||||
_mount_path[_freq] if _mount_path[_freq] is None else str(Path(_mount_path[_freq]).expanduser())
|
||||
)
|
||||
self["provider_uri"] = _provider_uri
|
||||
self["mount_path"] = _mount_path
|
||||
|
||||
@@ -34,7 +34,11 @@ class FileStorageMixin:
|
||||
|
||||
@property
|
||||
def dpm(self):
|
||||
return C.dpm if getattr(self, "_provider_uri", None) is None else C.DataPathManager(self._provider_uri, None)
|
||||
return (
|
||||
C.dpm
|
||||
if getattr(self, "_provider_uri", None) is None
|
||||
else C.DataPathManager(self._provider_uri, C.mount_path)
|
||||
)
|
||||
|
||||
@property
|
||||
def support_freq(self) -> List[str]:
|
||||
|
||||
Reference in New Issue
Block a user