Skip to content
Snippets Groups Projects
Unverified Commit 7e787d8f authored by SUNYC's avatar SUNYC Committed by GitHub
Browse files

[Enhance] Add a new parameter conf_path in PetrelBackend (#774)


* feat: add conf_path in PetrelBackend

* Update mmengine/fileio/backends/petrel_backend.py

Co-authored-by: default avatarMashiro <57566630+HAOCHENYE@users.noreply.github.com>

Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>
Co-authored-by: default avatarMashiro <57566630+HAOCHENYE@users.noreply.github.com>
parent d3d75288
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,8 @@ class PetrelBackend(BaseStorageBackend): ...@@ -27,6 +27,8 @@ class PetrelBackend(BaseStorageBackend):
``filepath`` will be replaced by ``dst``. Defaults to None. ``filepath`` will be replaced by ``dst``. Defaults to None.
enable_mc (bool, optional): Whether to enable memcached support. enable_mc (bool, optional): Whether to enable memcached support.
Defaults to True. Defaults to True.
conf_path (str, optional): Config path of Petrel client. Default: None.
`New in version 0.3.3`.
Examples: Examples:
>>> backend = PetrelBackend() >>> backend = PetrelBackend()
...@@ -38,14 +40,15 @@ class PetrelBackend(BaseStorageBackend): ...@@ -38,14 +40,15 @@ class PetrelBackend(BaseStorageBackend):
def __init__(self, def __init__(self,
path_mapping: Optional[dict] = None, path_mapping: Optional[dict] = None,
enable_mc: bool = True): enable_mc: bool = True,
conf_path: Optional[str] = None):
try: try:
from petrel_client import client from petrel_client import client
except ImportError: except ImportError:
raise ImportError('Please install petrel_client to enable ' raise ImportError('Please install petrel_client to enable '
'PetrelBackend.') 'PetrelBackend.')
self._client = client.Client(enable_mc=enable_mc) self._client = client.Client(conf_path=conf_path, enable_mc=enable_mc)
assert isinstance(path_mapping, dict) or path_mapping is None assert isinstance(path_mapping, dict) or path_mapping is None
self.path_mapping = path_mapping self.path_mapping = path_mapping
......
...@@ -63,9 +63,13 @@ except ImportError: ...@@ -63,9 +63,13 @@ except ImportError:
class MockPetrelClient: class MockPetrelClient:
def __init__(self, enable_mc=True, enable_multi_cluster=False): def __init__(self,
enable_mc=True,
enable_multi_cluster=False,
conf_path=None):
self.enable_mc = enable_mc self.enable_mc = enable_mc
self.enable_multi_cluster = enable_multi_cluster self.enable_multi_cluster = enable_multi_cluster
self.conf_path = conf_path
def Get(self, filepath): def Get(self, filepath):
with open(filepath, 'rb') as f: with open(filepath, 'rb') as f:
......
...@@ -85,9 +85,13 @@ class MockS3Client: ...@@ -85,9 +85,13 @@ class MockS3Client:
class MockPetrelClient: class MockPetrelClient:
def __init__(self, enable_mc=True, enable_multi_cluster=False): def __init__(self,
enable_mc=True,
enable_multi_cluster=False,
conf_path=None):
self.enable_mc = enable_mc self.enable_mc = enable_mc
self.enable_multi_cluster = enable_multi_cluster self.enable_multi_cluster = enable_multi_cluster
self.conf_path = conf_path
def Get(self, filepath): def Get(self, filepath):
with open(filepath, 'rb') as f: with open(filepath, 'rb') as f:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment