Skip to content

Commit

Permalink
Merge pull request #3 from nasa/implement-pre-commit-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
owenlittlejohns authored Apr 5, 2024
2 parents f0d4b40 + 54820bf commit a931233
Show file tree
Hide file tree
Showing 22 changed files with 535 additions and 372 deletions.
5 changes: 5 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# For more information, see:
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view

# Black code formatting of entire repository
c75775b10b19a361fd8ecfdaccc2bb2f820ea115
37 changes: 19 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/akaihola/darker
rev: 1.7.2
hooks:
- id: darker
args:
- --isort
- --skip-string-normalization
additional_dependencies:
- isort~=5.13.1
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-json
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.4
hooks:
- id: ruff
args: ["--fix", "--show-fixes"]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
hooks:
- id: black-jupyter
args: ["--skip-string-normalization"]
language_version: python3.11
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## v1.0.1
### 2024-04-05

This version of HyBIG updates the repository to use `black` code formatting
throughout. There should be no functional change to the service.

## v1.0.0
### 2024-01-22
This version of the Harmony Browse Image Generator (HyBIG) contains all
Expand Down
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,39 @@ newest relate of the code (starting at the top of the file).
## vX.Y.Z
```

### pre-commit hooks:

This repository uses [pre-commit](https://pre-commit.com/) to enable pre-commit
checking the repository for some coding standard best practices. These include:

* Removing trailing whitespaces.
* Removing blank lines at the end of a file.
* JSON files have valid formats.
* [ruff](https://github.com/astral-sh/ruff) Python linting checks.
* [black](https://black.readthedocs.io/en/stable/index.html) Python code
formatting checks.

To enable these checks:

```bash
# Install pre-commit Python package as part of test requirements:
pip install -r tests/pip_test_requirements.txt

# Install the git hook scripts:
pre-commit install

# (Optional) Run against all files:
pre-commit run --all-files
```

When you try to make a new commit locally, `pre-commit` will automatically run.
If any of the hooks detect non-compliance (e.g., trailing whitespace), that
hook will state it failed, and also try to fix the issue. You will need to
review and `git add` the changes before you can make a commit.

It is planned to implement additional hooks, possibly including tools such as
`mypy`.

## Releasing a new version of the service:

Once a new Docker image has been published with a new semantic version tag,
Expand Down
2 changes: 1 addition & 1 deletion docker/service_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
1.0.1
44 changes: 24 additions & 20 deletions docs/HyBIG-Example-Usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"\n",
"# creates an output directory for the downloaded files\n",
"from pathlib import Path\n",
"\n",
"output_dir = Path('./hybig-output')\n",
"Path.mkdir(output_dir, exist_ok=True)"
]
Expand All @@ -79,12 +80,11 @@
"metadata": {},
"outputs": [],
"source": [
"\n",
"aster_collection = Collection(id='C1256584478-EEDTEST')\n",
"aster_granule = 'G1256584570-EEDTEST'\n",
"\n",
"measures_collection = Collection(id='C1258119317-EEDTEST')\n",
"measures_granule = 'G1258119387-EEDTEST'\n",
"measures_granule = 'G1258119387-EEDTEST'\n",
"\n",
"harmony_client = Client(env=Environment.UAT)"
]
Expand Down Expand Up @@ -118,9 +118,7 @@
"\n",
"# Specify a request to create a browse image from an MEaSUREs granule:\n",
"measures_request = Request(\n",
" collection=measures_collection,\n",
" granule_id=measures_granule,\n",
" format=image_format\n",
" collection=measures_collection, granule_id=measures_granule, format=image_format\n",
")\n",
"\n",
"# Submit the request and wait for it to complete:\n",
Expand All @@ -132,8 +130,9 @@
"Path.mkdir(example1_output_dir, exist_ok=True)\n",
"downloaded_outputs = [\n",
" file_future.result()\n",
" for file_future\n",
" in harmony_client.download_all(measures_job_id, overwrite=True, directory=example1_output_dir)\n",
" for file_future in harmony_client.download_all(\n",
" measures_job_id, overwrite=True, directory=example1_output_dir\n",
" )\n",
"]"
]
},
Expand Down Expand Up @@ -234,7 +233,7 @@
" collection=aster_collection,\n",
" granule_id=aster_granule,\n",
" scale_extent=scale_extent,\n",
" format='image/jpeg'\n",
" format='image/jpeg',\n",
")\n",
"\n",
"# Submit the request and wait for it to complete:\n",
Expand All @@ -246,8 +245,9 @@
"Path.mkdir(example2_output_dir, exist_ok=True)\n",
"downloaded_extent_outputs = [\n",
" file_future.result()\n",
" for file_future\n",
" in harmony_client.download_all(extent_job_id, overwrite=True, directory=example2_output_dir)\n",
" for file_future in harmony_client.download_all(\n",
" extent_job_id, overwrite=True, directory=example2_output_dir\n",
" )\n",
"]"
]
},
Expand Down Expand Up @@ -312,7 +312,7 @@
" collection=measures_collection,\n",
" granule_id=measures_granule,\n",
" scale_size=scale_sizes,\n",
" format='image/png'\n",
" format='image/png',\n",
")\n",
"\n",
"# Submit the request and wait for it to complete:\n",
Expand All @@ -324,8 +324,9 @@
"Path.mkdir(example3_output_dir, exist_ok=True)\n",
"downloaded_scale_size_outputs = [\n",
" file_future.result()\n",
" for file_future\n",
" in harmony_client.download_all(scale_size_job_id, overwrite=True, directory=example3_output_dir)\n",
" for file_future in harmony_client.download_all(\n",
" scale_size_job_id, overwrite=True, directory=example3_output_dir\n",
" )\n",
"]"
]
},
Expand Down Expand Up @@ -366,8 +367,9 @@
"dimensions_request = Request(\n",
" collection=measures_collection,\n",
" granule_id=measures_granule,\n",
" height=180, width=180,\n",
" format='image/png'\n",
" height=180,\n",
" width=180,\n",
" format='image/png',\n",
")\n",
"\n",
"# Submit the request and wait for it to complete:\n",
Expand All @@ -379,8 +381,9 @@
"Path.mkdir(example4_output_dir, exist_ok=True)\n",
"downloaded_dimensions_outputs = [\n",
" file_future.result()\n",
" for file_future\n",
" in harmony_client.download_all(dimensions_job_id, overwrite=True, directory=example4_output_dir)\n",
" for file_future in harmony_client.download_all(\n",
" dimensions_job_id, overwrite=True, directory=example4_output_dir\n",
" )\n",
"]"
]
},
Expand Down Expand Up @@ -432,7 +435,7 @@
" granule_id=measures_granule,\n",
" scale_extent=iceland_extent,\n",
" scale_size=iceland_scale_size,\n",
" format='image/png'\n",
" format='image/png',\n",
")\n",
"\n",
"# Submit the request and wait for it to complete:\n",
Expand All @@ -444,8 +447,9 @@
"Path.mkdir(example5_output_dir, exist_ok=True)\n",
"downloaded_tiled_outputs = [\n",
" file_future.result()\n",
" for file_future\n",
" in harmony_client.download_all(tiled_job_id, overwrite=True, directory=example5_output_dir)\n",
" for file_future in harmony_client.download_all(\n",
" tiled_job_id, overwrite=True, directory=example5_output_dir\n",
" )\n",
"]"
]
},
Expand Down
10 changes: 6 additions & 4 deletions harmony_browse_image_generator/__main__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Run the Harmony Browse Image Generator Adapter via the Harmony CLI. """

from argparse import ArgumentParser
from sys import argv

Expand All @@ -9,12 +10,13 @@


def main(arguments: list[str]):
""" Parse command line arguments and invoke the appropriate method to
respond to them
"""Parse command line arguments and invoke the appropriate method to
respond to them
"""
parser = ArgumentParser(prog=SERVICE_NAME,
description='Run Harmony Browse Image Generator.')
parser = ArgumentParser(
prog=SERVICE_NAME, description='Run Harmony Browse Image Generator.'
)

setup_cli(parser)
harmony_arguments, _ = parser.parse_known_args(arguments[1:])
Expand Down
Loading

0 comments on commit a931233

Please sign in to comment.