Skip to content

Commit caad446

Browse files
committed
added linting for docstrings, added D1,D205,D417,D401 to the ignore list
1 parent d3ad4c5 commit caad446

File tree

13 files changed

+461
-261
lines changed

13 files changed

+461
-261
lines changed

earthaccess/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@
6161

6262

6363
def __getattr__(name): # type: ignore
64-
"""
65-
Module-level getattr to handle automatic authentication when accessing
64+
"""Module-level getattr to handle automatic authentication when accessing
6665
`earthaccess.__auth__` and `earthaccess.__store__`.
6766
6867
Other unhandled attributes raise as `AttributeError` as expected.

earthaccess/api.py

Lines changed: 65 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ def search_datasets(count: int = -1, **kwargs: Any) -> List[DataCollection]:
3737
3838
[https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html)
3939
40-
Parameters:
40+
Parameters
41+
----------
4142
count: Number of records to get, -1 = all
4243
kwargs (Dict):
4344
arguments to CMR:
@@ -52,20 +53,24 @@ def search_datasets(count: int = -1, **kwargs: Any) -> List[DataCollection]:
5253
* **bounding_box**: a tuple representing spatial bounds in the form
5354
`(lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat)`
5455
55-
Returns:
56+
Returns
57+
-------
5658
A list of DataCollection results that can be used to get information about a
5759
dataset, e.g. concept_id, doi, etc.
5860
59-
Raises:
61+
Raises
62+
------
6063
RuntimeError: The CMR query failed.
6164
62-
Examples:
65+
Examples
66+
--------
6367
```python
6468
datasets = earthaccess.search_datasets(
6569
keyword="sea surface anomaly",
6670
cloud_hosted=True
6771
)
6872
```
73+
6974
"""
7075
if not validate.valid_dataset_parameters(**kwargs):
7176
logger.warn("A valid set of parameters is needed to search for datasets on CMR")
@@ -86,7 +91,8 @@ def search_data(count: int = -1, **kwargs: Any) -> List[DataGranule]:
8691
8792
[https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html](https://cmr.earthdata.nasa.gov/search/site/docs/search/api.html)
8893
89-
Parameters:
94+
Parameters
95+
----------
9096
count: Number of records to get, -1 = all
9197
kwargs (Dict):
9298
arguments to CMR:
@@ -101,21 +107,25 @@ def search_data(count: int = -1, **kwargs: Any) -> List[DataGranule]:
101107
* **bounding_box**: a tuple representing spatial bounds in the form
102108
`(lower_left_lon, lower_left_lat, upper_right_lon, upper_right_lat)`
103109
104-
Returns:
110+
Returns
111+
-------
105112
a list of DataGranules that can be used to access the granule files by using
106113
`download()` or `open()`.
107114
108-
Raises:
115+
Raises
116+
------
109117
RuntimeError: The CMR query failed.
110118
111-
Examples:
119+
Examples
120+
--------
112121
```python
113122
datasets = earthaccess.search_data(
114123
doi="10.5067/SLREF-CDRV2",
115124
cloud_hosted=True,
116125
temporal=("2002-01-01", "2002-12-31")
117126
)
118127
```
128+
119129
"""
120130
if earthaccess.__auth__.authenticated:
121131
query = DataGranules(earthaccess.__auth__).parameters(**kwargs)
@@ -131,7 +141,8 @@ def search_data(count: int = -1, **kwargs: Any) -> List[DataGranule]:
131141
def login(strategy: str = "all", persist: bool = False, system: System = PROD) -> Auth:
132142
"""Authenticate with Earthdata login (https://urs.earthdata.nasa.gov/).
133143
134-
Parameters:
144+
Parameters
145+
----------
135146
strategy:
136147
An authentication method.
137148
@@ -142,8 +153,10 @@ def login(strategy: str = "all", persist: bool = False, system: System = PROD) -
142153
persist: will persist credentials in a .netrc file
143154
system: the Earthdata system to access, defaults to PROD
144155
145-
Returns:
156+
Returns
157+
-------
146158
An instance of Auth.
159+
147160
"""
148161
# Set the underlying Auth object's earthdata system,
149162
# before triggering the getattr function for `__auth__`.
@@ -181,17 +194,21 @@ def download(
181194
* If we run it outside AWS (us-west-2 region) and the dataset is cloud hosted,
182195
we'll use HTTP links.
183196
184-
Parameters:
197+
Parameters
198+
----------
185199
granules: a granule, list of granules, a granule link (HTTP), or a list of granule links (HTTP)
186200
local_path: local directory to store the remote data granules
187201
provider: if we download a list of URLs, we need to specify the provider.
188202
threads: parallel number of threads to use to download the files, adjust as necessary, default = 8
189203
190-
Returns:
204+
Returns
205+
-------
191206
List of downloaded files
192207
193-
Raises:
208+
Raises
209+
------
194210
Exception: A file download failed.
211+
195212
"""
196213
provider = _normalize_location(provider)
197214
if isinstance(granules, DataGranule):
@@ -215,13 +232,16 @@ def open(
215232
"""Returns a list of fsspec file-like objects that can be used to access files
216233
hosted on S3 or HTTPS by third party libraries like xarray.
217234
218-
Parameters:
235+
Parameters
236+
----------
219237
granules: a list of granule instances **or** list of URLs, e.g. `s3://some-granule`.
220238
If a list of URLs is passed, we need to specify the data provider.
221239
provider: e.g. POCLOUD, NSIDC_CPRD, etc.
222240
223-
Returns:
241+
Returns
242+
-------
224243
a list of s3fs "file pointers" to s3 files.
244+
225245
"""
226246
provider = _normalize_location(provider)
227247
results = earthaccess.__store__.open(granules=granules, provider=provider)
@@ -238,13 +258,16 @@ def get_s3_credentials(
238258
If we use results, earthaccess will use the metadata on the response to get the credentials,
239259
which is useful for missions that do not use the same endpoint as their DAACs, e.g. SWOT.
240260
241-
Parameters:
261+
Parameters
262+
----------
242263
daac: a DAAC short_name like NSIDC or PODAAC, etc.
243264
provider: if we know the provider for the DAAC, e.g. POCLOUD, LPCLOUD etc.
244265
results: List of results from search_data()
245266
246-
Returns:
267+
Returns
268+
-------
247269
a dictionary with S3 credentials for the DAAC or provider
270+
248271
"""
249272
daac = _normalize_location(daac)
250273
provider = _normalize_location(provider)
@@ -257,8 +280,10 @@ def get_s3_credentials(
257280
def collection_query() -> CollectionQuery:
258281
"""Returns a query builder instance for NASA collections (datasets).
259282
260-
Returns:
283+
Returns
284+
-------
261285
a query builder instance for data collections.
286+
262287
"""
263288
if earthaccess.__auth__.authenticated:
264289
query_builder = DataCollections(earthaccess.__auth__)
@@ -268,10 +293,12 @@ def collection_query() -> CollectionQuery:
268293

269294

270295
def granule_query() -> GranuleQuery:
271-
"""Returns a query builder instance for data granules
296+
"""Returns a query builder instance for data granules.
272297
273-
Returns:
298+
Returns
299+
-------
274300
a query builder instance for data granules.
301+
275302
"""
276303
if earthaccess.__auth__.authenticated:
277304
query_builder = DataGranules(earthaccess.__auth__)
@@ -283,10 +310,12 @@ def granule_query() -> GranuleQuery:
283310
def get_fsspec_https_session() -> AbstractFileSystem:
284311
"""Returns a fsspec session that can be used to access datafiles across many different DAACs.
285312
286-
Returns:
313+
Returns
314+
-------
287315
An fsspec instance able to access data across DAACs.
288316
289-
Examples:
317+
Examples
318+
--------
290319
```python
291320
import earthaccess
292321
@@ -295,6 +324,7 @@ def get_fsspec_https_session() -> AbstractFileSystem:
295324
with fs.open(DAAC_GRANULE) as f:
296325
f.read(10)
297326
```
327+
298328
"""
299329
session = earthaccess.__store__.get_fsspec_session()
300330
return session
@@ -305,10 +335,12 @@ def get_requests_https_session() -> requests.Session:
305335
This is useful for making requests to restricted URLs, such as data granules or services that
306336
require authentication with NASA EDL.
307337
308-
Returns:
338+
Returns
339+
-------
309340
An authenticated requests Session instance.
310341
311-
Examples:
342+
Examples
343+
--------
312344
```python
313345
import earthaccess
314346
@@ -318,6 +350,7 @@ def get_requests_https_session() -> requests.Session:
318350
data = req_session.get(granule_url, headers = {"Range": "bytes=0-100"})
319351
320352
```
353+
321354
"""
322355
session = earthaccess.__store__.get_requests_session()
323356
return session
@@ -330,15 +363,18 @@ def get_s3fs_session(
330363
) -> s3fs.S3FileSystem:
331364
"""Returns a fsspec s3fs file session for direct access when we are in us-west-2.
332365
333-
Parameters:
366+
Parameters
367+
----------
334368
daac: Any DAAC short name e.g. NSIDC, GES_DISC
335369
provider: Each DAAC can have a cloud provider.
336370
If the DAAC is specified, there is no need to use provider.
337371
results: A list of results from search_data().
338372
`earthaccess` will use the metadata from CMR to obtain the S3 Endpoint.
339373
340-
Returns:
374+
Returns
375+
-------
341376
An authenticated s3fs session valid for 1 hour.
377+
342378
"""
343379
daac = _normalize_location(daac)
344380
provider = _normalize_location(provider)
@@ -354,8 +390,10 @@ def get_s3fs_session(
354390
def get_edl_token() -> str:
355391
"""Returns the current token used for EDL.
356392
357-
Returns:
393+
Returns
394+
-------
358395
EDL token
396+
359397
"""
360398
token = earthaccess.__auth__.token
361399
return token

earthaccess/auth.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525

2626

2727
class SessionWithHeaderRedirection(requests.Session):
28-
"""
29-
Requests removes auth headers if the redirect happens outside the
28+
"""Requests removes auth headers if the redirect happens outside the
3029
original req domain.
3130
"""
3231

@@ -85,7 +84,8 @@ def login(
8584
) -> Any:
8685
"""Authenticate with Earthdata login.
8786
88-
Parameters:
87+
Parameters
88+
----------
8989
strategy:
9090
The authentication method.
9191
@@ -96,8 +96,10 @@ def login(
9696
persist: Will persist credentials in a `.netrc` file.
9797
system (Env): the EDL endpoint to log in to Earthdata, defaults to PROD
9898
99-
Returns:
99+
Returns
100+
-------
100101
An instance of Auth.
102+
101103
"""
102104
if system is not None:
103105
self._set_earthdata_system(system)
@@ -191,13 +193,16 @@ def get_s3_credentials(
191193
"""Gets AWS S3 credentials for a given NASA cloud provider.
192194
The easier way is to use the DAAC short name; provider is optional if we know it.
193195
194-
Parameters:
196+
Parameters
197+
----------
195198
daac: The name of a NASA DAAC, e.g. NSIDC or PODAAC.
196199
provider: A valid cloud provider. Each DAAC has a provider code for their cloud distributions.
197200
endpoint: Getting the credentials directly from the S3Credentials URL.
198201
199-
Returns:
202+
Returns
203+
-------
200204
A Python dictionary with the temporary AWS S3 credentials.
205+
201206
"""
202207
if self.authenticated:
203208
session = SessionWithHeaderRedirection(self.username, self.password)
@@ -246,11 +251,14 @@ def get_s3_credentials(
246251
def get_session(self, bearer_token: bool = True) -> requests.Session:
247252
"""Returns a new request session instance.
248253
249-
Parameters:
254+
Parameters
255+
----------
250256
bearer_token: whether to include bearer token
251257
252-
Returns:
258+
Returns
259+
-------
253260
class Session instance with Auth and bearer token headers
261+
254262
"""
255263
session = SessionWithHeaderRedirection()
256264
if bearer_token and self.authenticated:

earthaccess/formatters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def _load_static_files() -> List[str]:
10-
"""Load styles"""
10+
"""Load styles."""
1111
return [
1212
importlib_resources.files("earthaccess.css").joinpath(fname).read_text("utf8")
1313
for fname in STATIC_FILES

0 commit comments

Comments
 (0)