diff --git a/tosfs/core.py b/tosfs/core.py index 81b875d..b42ac49 100644 --- a/tosfs/core.py +++ b/tosfs/core.py @@ -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 @@ -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, @@ -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 @@ -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, diff --git a/tosfs/tests/conftest.py b/tosfs/tests/conftest.py index be549a4..affb007 100644 --- a/tosfs/tests/conftest.py +++ b/tosfs/tests/conftest.py @@ -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, diff --git a/tosfs/tests/test_fsspec_integration.py b/tosfs/tests/test_fsspec_integration.py index 536b33c..819bc3d 100644 --- a/tosfs/tests/test_fsspec_integration.py +++ b/tosfs/tests/test_fsspec_integration.py @@ -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(), ) @@ -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", @@ -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(), )