Skip to content

Commit

Permalink
Introduce endpoint arg and deprecate endpoint_url
Browse files Browse the repository at this point in the history
  • Loading branch information
yanghua committed Nov 19, 2024
1 parent 42682fd commit e52e4f1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
21 changes: 17 additions & 4 deletions tosfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import mimetypes
import os
import tempfile
import warnings
from glob import has_magic
from typing import Any, BinaryIO, Collection, Generator, List, Optional, Tuple, Union

Expand Down Expand Up @@ -104,7 +105,7 @@ class TosFileSystem(FsspecCompatibleFS):

def __init__(
self,
endpoint_url: Optional[str] = None,
endpoint: Optional[str] = None,
key: str = "",
secret: str = "",
region: Optional[str] = None,
Expand Down Expand Up @@ -132,14 +133,15 @@ def __init__(
proxy_password: Optional[str] = None,
disable_encoding_meta: Optional[bool] = None,
except100_continue_threshold: int = 65536,
endpoint_url: Optional[str] = None, # Deprecated parameter
**kwargs: Any,
) -> None:
"""Initialise the TosFileSystem.
Parameters
----------
endpoint_url : str, optional
The endpoint URL of the TOS service.
endpoint : str, optional
The endpoint of the TOS service.
key : str
The access key ID(ak) to access the TOS service.
secret : str
Expand Down Expand Up @@ -219,14 +221,25 @@ def __init__(
length of the data to be uploaded greater than the threshold
(if the length of the data cannot be predicted, it is uniformly determined
to be greater than the threshold), unit byte, default 65536
endpoint_url : str, optional
(deprecated) The endpoint URL of the TOS service.
kwargs : Any, optional
Additional arguments.
"""
if endpoint_url is not None:
warnings.warn(
"The 'endpoint_url' parameter is deprecated and will be removed"
" in a future release. Please use 'endpoint' instead.",
DeprecationWarning,
stacklevel=2
)
endpoint = endpoint_url

self.tos_client = tos.TosClientV2(
key,
secret,
endpoint_url,
endpoint,
region,
security_token=session_token,
max_retry_count=0,
Expand Down
2 changes: 1 addition & 1 deletion tosfs/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _tosfs_env_prepare() -> None:
@pytest.fixture(scope="module")
def tosfs(_tosfs_env_prepare: None) -> TosFileSystem:
tosfs = TosFileSystem(
endpoint_url=os.environ.get("TOS_ENDPOINT"),
endpoint=os.environ.get("TOS_ENDPOINT"),
region=os.environ.get("TOS_REGION"),
credentials_provider=EnvCredentialsProvider(),
max_retry_num=1000,
Expand Down
6 changes: 3 additions & 3 deletions tosfs/tests/test_fsspec_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_fssepc_register():

tosfs, _ = fsspec.core.url_to_fs(
"tos://",
endpoint_url=os.environ.get("TOS_ENDPOINT"),
endpoint=os.environ.get("TOS_ENDPOINT"),
region=os.environ.get("TOS_REGION"),
credentials_provider=EnvCredentialsProvider(),
)
Expand All @@ -53,7 +53,7 @@ def test_fsspec_open(bucket, temporary_workspace):
content = "Hello TOSFS."
with fsspec.open(
f"tos://{bucket}/{temporary_workspace}/{file}",
endpoint_url=os.environ.get("TOS_ENDPOINT"),
endpoint=os.environ.get("TOS_ENDPOINT"),
region=os.environ.get("TOS_REGION"),
credentials_provider=EnvCredentialsProvider(),
mode="w",
Expand All @@ -76,7 +76,7 @@ class MyTosFileSystem(TosFileSystem):
def __init__(self):
"""Init MyTosFileSystem."""
super().__init__(
endpoint_url=os.environ.get("TOS_ENDPOINT"),
endpoint=os.environ.get("TOS_ENDPOINT"),
region=os.environ.get("TOS_REGION"),
credentials_provider=EnvCredentialsProvider(),
)
Expand Down

0 comments on commit e52e4f1

Please sign in to comment.