Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/nsidc/earthaccess into kerc…
Browse files Browse the repository at this point in the history
…hunk
  • Loading branch information
jrbourbeau committed Oct 23, 2023
2 parents cd260a5 + 6fbc4ae commit 980cc76
Show file tree
Hide file tree
Showing 13 changed files with 562 additions and 96 deletions.
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Changelog

## Unreleased
## [unreleased]
* bug fixes:
* Fix spelling mistake in `access` variable assignment (`direc` -> `direct`)
in `earthaccess.store._get_granules`.
* Pass `threads` arg to `_open_urls_https` in
`earthaccess.store._open_urls`, replacing the hard-coded value of 8.

## [v0.6.0] 2023-09-20
* bug fixes:
* earthaccess.search_datasets() and earthaccess.search_data() can find restricted datasets #296
* distributed serialization fixed for EarthAccessFile #301 and #276
* new features:
* earthaccess.get_s3fs_session() can use the results to find the right set of S3 credentials

## [v0.5.3] 2023-08-01
* bug fixes:
* granule's size() returned zero
* Added exception handling for fsspec sessions, thanks to @jrbourbeau
Expand Down
73 changes: 73 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
cff-version: 1.2.0
message: |
Please cite this software using these metadata.
Authors are listed in alphabetical order.
title: "earthaccess"
doi: "https://doi.org/10.5281/zenodo.8365009"
abstract: "Python Library for NASA Earthdata APIs"
contact:
- name: "The earthaccess community"
website: "https://github.com/nsidc/earthaccess/discussions"
- name: "NSIDC"
email: "[email protected]"
type: "software"
license: ["MIT"]
keywords:
- "data"
- "Remote sensing"
- "Cloud computing"
- "authentication"
- "Earthdata Login"

url: "https://earthaccess.readthedocs.io"
repository-code: "https://github.com/nsidc/earthaccess"

version: "0.6.1"
date-released: "2023-09-20"

authors:
- family-names: "Barrett"
given-names: "Andrew"
orcid: "https://orcid.org/0000-0003-4394-5445"
website: "https://github.com/andypbarrett"
- family-names: "Battisto"
given-names: "Chris"
orcid: "https://orcid.org//0000-0002-9608-3634"
website: "https://github.com/battistowx"
- family-names: "Bourbeau"
given-names: "James"
orcid: "https://orcid.org/0000-0003-2164-7789"
website: "https://github.com/jrbourbeau"
- family-names: "Fisher"
given-names: "Matt"
orcid: "https://orcid.org/0000-0003-3260-5445"
website: "https://mfisher87.github.io/"
- family-names: "Kennedy"
given-names: "Joseph"
orcid: "https://orcid.org/0000-0002-9348-693X"
website: "https://github.com/jhkennedy"
- family-names: "Lopez"
given-names: "Luis"
orcid: "https://orcid.org/0000-0003-4896-3263"
website: "https://github.com/betolink"
- family-names: "Lowndes"
given-names: "Julia"
orcid: "https://orcid.org/0000-0003-1682-3872"
website: "https://github.com/jules32"
- family-names: "Scheick"
given-names: "Jessica"
orcid: "https://orcid.org/0000-0002-3421-4459"
website: "https://github.com/JessicaS11"
- family-names: "Steiker"
given-names: "Amy"
orcid: "https://orcid.org/0000-0002-3039-0260"
website: "https://github.com/asteiker"



references:
- type: "grant"
institution:
name: "National Aeronautics and Space Administration"
number: "20-TWSC20-2-0003"
44 changes: 36 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,44 @@ scripts/format.sh
- you must update the documentation
- you must run the above scripts to format and line

## Pull Request Process
## Pull Request process

1. Ensure you include test coverage for all changes
2. Ensure your code is formatted properly via the command above
3. Update the documentation and the README.md with details of changes to the interface, this includes new environment
variables, function names, decorators, etc..
4. Increase the version numbers in any examples files and the README.md to the new version that this
Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/).
5. You may merge the Pull Request in once you have the sign-off of another developers, or if you
do not have permission to do that, you may request the reviewer to merge it for you.
2. Ensure your code is formatted properly following this document
3. Update the documentation and the README.md with details of changes to the interface,
this includes new environment variables, function names, decorators, etc.
3. Update `CHANGELOG.md` with details about your change in a section titled
`Unreleased`. If one does not exist, please create one.
4. You may merge the Pull Request in once you have the sign-off of another developers,
or if you do not have permission to do that, you may request the reviewer to merge it
for you.

## Release process

> :memo: The versioning scheme we use is [SemVer](http://semver.org/). Note that until
> we agree we're ready for v1.0.0, we will not increment major version.
0. Ensure all desired features are merged to `main` branch and `CHANGELOG` is updated.
1. Use `bump-my-version` to increase the version number in all needed places, e.g. to
increase the minor version (`1.2.3` to `1.3.0`):
```
bumpversion bump minor
```
2. Push a tag on the new commit containing the version number, prefixed with `v`, e.g.
`v1.3.0`.
3. [Create a new GitHub Release](https://github.com/nsidc/earthaccess/releases/new). We
hand-curate our release notes to be valuable to humans. Please do not auto-generate
release notes and aim for consistency with the GitHub Release descriptions from other
releases.

> :gear: After the GitHub release is published, multiple automations will trigger:
>
> - Zenodo will create a new DOI.
> - GitHub Actions will publish a PyPI release.
> :memo: `earthaccess` is published to conda-forge through the
> [earthdata-feedstock](https://github.com/conda-forge/earthdata-feedstock), as this
> project was renamed early in its life. The conda package is named `earthaccess`.
---

Expand Down
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

<p align="center">

<a href="https://zenodo.org/badge/latestdoi/399867529" target="_blank">
<img src="https://zenodo.org/badge/399867529.svg" alt="DOI" />
</a>

<a href="https://twitter.com/allison_horst" target="_blank">
<img src="https://img.shields.io/badge/Art%20By-Allison%20Horst-blue" alt="Art Designer: Allison Horst">
</a>
Expand All @@ -20,8 +24,8 @@
<img src="https://img.shields.io/pypi/pyversions/earthaccess.svg" alt="Python Versions">
</a>

<a href='https://earthdata.readthedocs.io/en/latest/?badge=latest'>
<img src='https://readthedocs.org/projects/earthdata/badge/?version=latest' alt='Documentation Status' />
<a href='https://earthaccess.readthedocs.io/en/latest/?badge=latest'>
<img src='https://readthedocs.org/projects/earthaccess/badge/?version=latest' alt='Documentation Status' />
</a>

</p>
Expand Down Expand Up @@ -66,22 +70,24 @@ The only requirement to use this library is to open a free account with NASA [ED

### **Authentication**

Once you have an EDL account, you can authenticate using one of the following three methods:
By default, `earthaccess` with automatically look for your EDL account credentials in two locations:

1. A `~/.netrc` file
2. `EARTHDATA_USERNAME` and `EARTHDATA_PASSWORD` environment variables

1. Using a `.netrc` file
* Can use *earthaccess* to read your EDL credentials (username and password) from a `.netrc` file
2. Reading your EDL credentials from environment variables
* if available you can use environment variables **EARTHDATA_USERNAME** and **EARTHDATA_PASSWORD**
3. Interactively entering your EDL credentials
* You can be prompted for these credentials and save them to a `.netrc` file
If neither of these options are configured, you can authenticate by calling the `earthaccess.login()` method
and manually entering your EDL account credentials.

```python
import earthaccess

auth = earthaccess.login()

earthaccess.login()
```

Note you can pass `persist=True` to `earthaccess.login()` to have the EDL account credentials you enter
automatically saved to a `~/.netrc` file for future use.


Once you are authenticated with NASA EDL you can:

* Get a file from a DAAC using a `fsspec` session.
Expand Down
47 changes: 44 additions & 3 deletions earthaccess/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging
import threading
from importlib.metadata import version
from typing import Any

from .api import (
auth_environ,
collection_query,
download,
get_fsspec_https_session,
Expand All @@ -19,6 +22,8 @@
from .search import DataCollections, DataGranules
from .store import Store

logger = logging.getLogger(__name__)

__all__ = [
"login",
"search_datasets",
Expand All @@ -35,9 +40,45 @@
"DataCollections",
"Auth",
"Store",
"auth_environ",
]

__auth__ = Auth()
__store__: Any = None

__version__ = version("earthaccess")

_auth = Auth()
_store = None
_lock = threading.Lock()


def __getattr__(name): # type: ignore
"""
Module-level getattr to handle automatic authentication when accessing
`earthaccess.__auth__` and `earthaccess.__store__`.
Other unhandled attributes raise as `AttributeError` as expected.
"""
global _auth, _store

if name == "__auth__" or name == "__store__":
with _lock:
if not _auth.authenticated:
for strategy in ["environment", "netrc"]:
try:
_auth.login(strategy=strategy)
except Exception as e:
logger.debug(
f"An error occurred during automatic authentication with {strategy=}: {str(e)}"
)
continue
else:
if not _auth.authenticated:
continue
else:
_store = Store(_auth)
logger.debug(
f"Automatic authentication with {strategy=} was successful"
)
break
return _auth if name == "__auth__" else _store
else:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Loading

0 comments on commit 980cc76

Please sign in to comment.