Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move attributes docs to __init__ #170

Merged
merged 1 commit into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/stac_asset/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,6 @@ class HttpClient(Client):
Configure the session to customize its behavior.
"""

check_content_type: bool
"""If true, check the asset's content type against the response from the server.

See :py:func:`stac_asset.validate.content_type` for more information about
hte content type check.
"""

session: ClientSession
"""A atiohttp session that will be used for all requests."""

@classmethod
async def from_config(cls: Type[T], config: Config) -> T:
"""Creates the default http client with a vanilla session object."""
Expand All @@ -42,8 +32,16 @@ async def from_config(cls: Type[T], config: Config) -> T:

def __init__(self, session: ClientSession, check_content_type: bool = True) -> None:
super().__init__()
self.session = session
self.check_content_type = check_content_type

self.session: ClientSession = session
"""A aiohttp session that will be used for all requests."""

self.check_content_type: bool = check_content_type
"""If true, check the asset's content type against the response from the server.

See :py:func:`stac_asset.validate.content_type` for more information about
the content type check.
"""

async def open_url(
self,
Expand Down
12 changes: 5 additions & 7 deletions src/stac_asset/planetary_computer_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@ class PlanetaryComputerClient(HttpClient):
thanks Tom Augspurger!
"""

_cache: Dict[URL, _Token]
_cache_lock: Lock
token_request_url: URL

def __init__(
self,
session: ClientSession,
sas_token_endpoint: str = DEFAULT_SAS_TOKEN_ENDPOINT,
) -> None:
super().__init__(session)
self._cache = dict()
self._cache_lock = Lock()
self.sas_token_endpoint = URL(sas_token_endpoint)
self._cache: Dict[URL, _Token] = dict()
self._cache_lock: Lock = Lock()

self.sas_token_endpoint: URL = URL(sas_token_endpoint)
"""The endpoint that will be used to fetch a SAS token for reading."""

async def open_url(
self,
Expand Down
47 changes: 21 additions & 26 deletions src/stac_asset/s3_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,6 @@ class S3Client(Client):
for instructions.
"""

session: AioSession
"""The session that will be used for all s3 requests."""

region_name: str
"""The region that all clients will be rooted in."""

requester_pays: bool
"""If True, enable access to `requester pays buckets
<https://docs.aws.amazon.com/AmazonS3/latest/userguide/RequesterPaysBuckets.html>`_."""

retry_mode: str
"""The retry mode, one of "adaptive", "legacy", or "standard".

See `the boto3 docs
<https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html>`_
for more information on the available modes.
"""

max_attempts: int
"""The maximum number of attempts."""

@classmethod
async def from_config(cls, config: Config) -> S3Client:
"""Creates an s3 client from a config.
Expand All @@ -76,11 +55,27 @@ def __init__(
max_attempts: int = DEFAULT_S3_MAX_ATTEMPTS,
) -> None:
super().__init__()
self.session = aiobotocore.session.get_session()
self.region_name = region_name
self.requester_pays = requester_pays
self.retry_mode = retry_mode
self.max_attempts = max_attempts

self.session: AioSession = aiobotocore.session.get_session()
"""The session that will be used for all s3 requests."""

self.region_name: str = region_name
"""The region that all clients will be rooted in."""

self.requester_pays: bool = requester_pays
"""If True, enable access to `requester pays buckets
<https://docs.aws.amazon.com/AmazonS3/latest/userguide/RequesterPaysBuckets.html>`_."""

self.retry_mode: str = retry_mode
"""The retry mode, one of "adaptive", "legacy", or "standard".

See `the boto3 docs
<https://boto3.amazonaws.com/v1/documentation/api/latest/guide/retries.html>`_
for more information on the available modes.
"""

self.max_attempts: int = max_attempts
"""The maximum number of attempts."""

async def open_url(
self,
Expand Down