Skip to content

Commit

Permalink
Did the necessary docstring cleanup as discussed in #590
Browse files Browse the repository at this point in the history
  • Loading branch information
Sherwin-14 committed Jun 11, 2024
1 parent 7cc9bbb commit 294230e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
9 changes: 6 additions & 3 deletions earthaccess/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ def __init__(
if username and password:
self.auth = (username, password)

# Overrides from the library to keep headers when redirected to or from
# the NASA auth host.
def rebuild_auth(self, prepared_request: Any, response: Any) -> None:
"""Overrides from the library to keep headers when redirected to or from the NASA auth host."""
headers = prepared_request.headers
url = prepared_request.url

Expand Down Expand Up @@ -93,14 +92,16 @@ def login(
* **"environment"**:
Retrieve a username and password from $EARTHDATA_USERNAME and $EARTHDATA_PASSWORD.
persist: Will persist credentials in a `.netrc` file.
system (Env): the EDL endpoint to log in to Earthdata, defaults to PROD
Returns:
An instance of Auth.
"""
if system is not None:
self._set_earthdata_system(system)

if system is not None:
self._set_earthdata_system(system)

if self.authenticated and (system == self.system):
logger.debug("We are already authenticated with NASA EDL")
return self
Expand Down Expand Up @@ -132,6 +133,7 @@ def _set_earthdata_system(self, system: System) -> None:

def refresh_tokens(self) -> bool:
"""Refresh CMR tokens.
Tokens are used to do authenticated queries on CMR for restricted and early access datasets.
This method renews the tokens to make sure we can query the collections allowed to our EDL user.
"""
Expand Down Expand Up @@ -188,6 +190,7 @@ def get_s3_credentials(
endpoint: Optional[str] = None,
) -> Dict[str, str]:
"""Gets AWS S3 credentials for a given NASA cloud provider.
The easier way is to use the DAAC short name; provider is optional if we know it.
Parameters:
Expand Down
2 changes: 2 additions & 0 deletions earthaccess/daac.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
def find_provider(
daac_short_name: Optional[str] = None, cloud_hosted: Optional[bool] = None
) -> Union[str, None]:
"""Placeholder."""
for daac in DAACS:
if daac_short_name == daac["short-name"]:
if cloud_hosted:
Expand All @@ -148,6 +149,7 @@ def find_provider(


def find_provider_by_shortname(short_name: str, cloud_hosted: bool) -> Union[str, None]:
"""Placeholder."""
base_url = "https://cmr.earthdata.nasa.gov/search/collections.umm_json?"
providers = requests.get(
f"{base_url}&cloud_hosted={cloud_hosted}&short_name={short_name}"
Expand Down
1 change: 1 addition & 0 deletions earthaccess/kerchunk.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def consolidate_metadata(
outfile: str | None = None,
storage_options: dict | None = None,
) -> str | dict:
"""Placeholder."""
try:
import dask

Expand Down
7 changes: 5 additions & 2 deletions earthaccess/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ def __init__(self, auth: Optional[Auth] = None, *args: Any, **kwargs: Any) -> No

@override
def hits(self) -> int:
"""Returns the number of hits the current query will return. This is done by
making a lightweight query to CMR and inspecting the returned headers.
"""Returns the number of hits the current query will return.
This is done by making a lightweight query to CMR and inspecting the returned headers.
Restricted datasets will always return zero results even if there are results.
Returns:
Expand Down Expand Up @@ -469,6 +470,7 @@ def __init__(self, auth: Optional[Auth] = None, *args: Any, **kwargs: Any) -> No
@override
def hits(self) -> int:
"""Returns the number of hits the current query will return.
This is done by making a lightweight query to CMR and inspecting the returned
headers.
Expand Down Expand Up @@ -561,6 +563,7 @@ def parameters(self, **kwargs: Any) -> Self:
@override
def provider(self, provider: str) -> Self:
"""Only match collections from a given provider.
A NASA datacenter or DAAC can have one or more providers.
For example, PODAAC is a data center or DAAC,
PODAAC is the default provider for on-prem data, and POCLOUD is
Expand Down
4 changes: 4 additions & 0 deletions earthaccess/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def make_instance(
cls: Any, granule: DataGranule, auth: Auth, data: Any
) -> EarthAccessFile:
# Attempt to re-authenticate
"""Placeholder."""
if not earthaccess.__auth__.authenticated:
earthaccess.__auth__ = auth
earthaccess.login()
Expand Down Expand Up @@ -165,6 +166,7 @@ def set_requests_session(
self, url: str, method: str = "get", bearer_token: bool = False
) -> None:
"""Sets up a `requests` session with bearer tokens that are used by CMR.
Mainly used to get the authentication cookies from different DAACs and URS.
This HTTPS session can be used to download granules if we want to use a direct,
lower level API.
Expand Down Expand Up @@ -265,6 +267,7 @@ def get_s3fs_session(
@lru_cache
def get_fsspec_session(self) -> fsspec.AbstractFileSystem:
"""Returns a fsspec HTTPS session with bearer tokens that are used by CMR.
This HTTPS session can be used to download granules if we want to use a direct,
lower level API.
Expand All @@ -283,6 +286,7 @@ def get_fsspec_session(self) -> fsspec.AbstractFileSystem:

def get_requests_session(self, bearer_token: bool = True) -> requests.Session:
"""Returns a requests HTTPS session with bearer tokens that are used by CMR.
This HTTPS session can be used to download granules if we want to use a direct,
lower level API.
Expand Down

0 comments on commit 294230e

Please sign in to comment.