-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
315 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,40 @@ | ||
# This workflow sets up the Earth Engine token and runs all tests. | ||
name: Test and lint | ||
|
||
name: tests | ||
on: [push, pull_request] | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ '3.7', '3.8', '3.9', '3.10' ] | ||
python-version: [ '3.8', '3.9', '3.10', '3.11' ] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pytest | ||
pip install -e .[test] | ||
pip install hatch | ||
- name: Store EE token | ||
run: | | ||
python ./.github/scripts/make_ee_token.py | ||
env: | ||
EE_TOKEN: ${{ secrets.EE_TOKEN }} | ||
- name: Test with pytest | ||
|
||
- name: Test | ||
run: | | ||
pytest . | ||
hatch run test:all | ||
- name: Pre-commit | ||
uses: pre-commit/[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,6 @@ __pycache__/ | |
htmlcov/ | ||
dist/ | ||
*.egg-info/ | ||
.tox/ | ||
.tox/ | ||
|
||
tests/data/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: v0.0.278 | ||
hooks: | ||
- id: ruff | ||
|
||
- repo: https://github.com/psf/black | ||
rev: 22.10.0 | ||
hooks: | ||
- id: black | ||
args: [--line-length=88, --preview] | ||
|
||
- repo: https://github.com/pre-commit/mirrors-mypy | ||
rev: v1.2.0 | ||
hooks: | ||
- id: mypy | ||
exclude: ^tests/|^setup.py | ||
args: [--ignore-missing-imports] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Contributing to eeprepr | ||
|
||
Contributions are always welcome! Bugs and feature requests can be opened in the [Issues](https://github.com/aazuspan/eerepr/issues). Questions and comments can be posted in the [Discussions](https://github.com/aazuspan/eerepr/discussions). To contribute code, please open an issue to discuss implementation, then follow the guide below to get started! | ||
|
||
## Setup | ||
|
||
`eeprepr` uses [Hatch](https://hatch.pypa.io/latest/) for package and environment management. To set up a development environment, first fork and clone `eerepr`, then install `hatch` in your environment. | ||
|
||
```bash | ||
pip install hatch | ||
``` | ||
|
||
This will install all required dependencies for development. You can enter the environment using: | ||
|
||
```bash | ||
hatch shell | ||
``` | ||
|
||
and exit by typing `quit` or `CTRL + D`. | ||
|
||
## Pre-commit Hooks | ||
|
||
Pre-commit hooks automatically run linting, formatting, and type-checking whenever a change is commited. This ensures that the codebase is always in good shape. | ||
|
||
The command below registers the pre-commit hooks for the project so that they run before every commit. | ||
|
||
```bash | ||
hatch run pre-commit install | ||
``` | ||
|
||
To run all the checks manually, you can use: | ||
|
||
```bash | ||
hatch run pre-commit run --all-files | ||
``` | ||
|
||
## Testing | ||
|
||
### Running Tests | ||
|
||
You can run all tests with `pytest` using the command below: | ||
|
||
```bash | ||
hatch run test:all | ||
``` | ||
|
||
To measure test coverage, run: | ||
|
||
```bash | ||
hatch run test:cov | ||
``` | ||
|
||
Additional arguments can be passed to `pytest` after the script name, e.g.: | ||
|
||
```bash | ||
hatch run test:all -k feature | ||
``` | ||
|
||
### Building New Tests | ||
|
||
New features should have unit tests. If your test needs to use `getInfo` to retrieve data from an Earth Engine object, you'll need to use the caching system described below. | ||
|
||
Using `getInfo` to retrieve data from an Earth Engine object can be slow and network-dependent. To speed up tests, `eerepr` uses a caching function `tests.cache.get_info` to load data. This function takes an Earth Engine object and either 1) retrieves its info from a local cache file if it has been used before, or 2) retrieves it from the server and adds it to the cache. The cache directory and file (`tests/data/data.json`) will be created automatically the first time tests are run. | ||
|
||
To demonstrate, let's write a new dummy test that checks the properties of a custom `ee.Image`. | ||
|
||
```python | ||
from tests.cache import get_info | ||
|
||
def test_my_image(): | ||
img = ee.Image.constant(42).set("custom_property", ["a", "b", "c"]) | ||
# Use `get_info` instead of `img.getInfo` to utilize the cache | ||
info = get_info(img) | ||
|
||
assert "custom_property" in info["properties"] | ||
``` | ||
|
||
The first time the test is run, `getInfo` will be used to retrieve the image metadata and store it in `tests/data/data.json`. Subsequent runs will pull the data directly from the cache. | ||
|
||
Caches are kept locally and are not version-controlled, so there's no need to commit newly added objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import ee | ||
|
||
from eerepr.config import options | ||
from eerepr.repr import initialize | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.