Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DAS-NONE: Random small fixes. #38

Merged
merged 14 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run_lib_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ['3.10', '3.11']
python-version: ['3.10', '3.11', '3.12']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!


steps:
- name: Checkout harmony-browse-image-generator repository
Expand Down
12 changes: 3 additions & 9 deletions .github/workflows/run_service_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ jobs:
- name: Run test image
run: ./bin/run-test

- name: Archive test results
- name: Archive test results and coverage
uses: actions/upload-artifact@v4
with:
name: Test results
path: test-reports/

- name: Archive coverage report
uses: actions/upload-artifact@v4
with:
name: Coverage report
path: coverage/*
name: reports
path: reports/**/*
13 changes: 5 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ repos:
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
rev: v0.8.2
hooks:
- id: ruff
args: ["--fix", "--show-fixes", "--extend-select", "I"]
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.10.0
hooks:
- id: black-jupyter
args: ["--skip-string-normalization"]
language_version: python3.11
args: ["--fix", "--show-fixes"]
types_or: [python, jupyter]
- id: ruff-format
types_or: [python, jupyter]
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ HyBIG follows semantic versioning. All notable changes to this project will be
documented in this file. The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).

## [unreleased] - 2024-12-10

### Changed

* Changed pre-commit configuration to remove `black-jupyter` dependency [#38](https://github.com/nasa/harmony-browse-image-generator/pull/38)
* Updates service image's python to 3.12 [#38](https://github.com/nasa/harmony-browse-image-generator/pull/38)
* Simplifies test scripts to run with pytest and pytest plugins [#38](https://github.com/nasa/harmony-browse-image-generator/pull/38)

### Removed

* Removes `test_code_format.py` in favor of `ruff` pre-commit configuration [#38](https://github.com/nasa/harmony-browse-image-generator/pull/38)


## [v2.0.2] - 2024-10-15

### Fixed
Expand Down
8 changes: 4 additions & 4 deletions bin/run-test
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ set -ex
find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf

# Make the directory into which XML format test reports will be saved
mkdir -p test-reports
mkdir -p reports/test-reports

# Make the directory into which coverage reports will be saved
mkdir -p coverage
mkdir -p reports/coverage

# Run the tests in a Docker container with mounted volumes for XML report
# output and test coverage reporting
docker run --platform linux/amd64 --rm \
-v $(pwd)/test-reports:/home/tests/reports \
-v $(pwd)/coverage:/home/tests/coverage \
-v $(pwd)/reports/test-reports:/home/reports/test-reports \
-v $(pwd)/reports/coverage:/home/reports/coverage \
ghcr.io/nasa/harmony-browse-image-generator-test "$@"
2 changes: 1 addition & 1 deletion docker/service.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# and updates the entrypoint of the new service container
#
###############################################################################
FROM python:3.11
FROM python:3.12
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice - I'm tempted to suggest releasing a version of HyBIG with just this change of Python version. Feels like it could be a fair candidate for a patch version.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't want to because it's a bunch of overhead for something that will be replaced as soon as I finish all that overhead. The next release will change functionality significantly and require updated regression-tests.

I could release it and not deploy it, but that also seems kind of dumb in that you've just created another version that is lying around.

I just did this in a separate PR to make it easier for someone to review and test. Since this does run against the existing regressions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. Given there isn't a dedicated ticket specifically for this clean up, I can buy that.


WORKDIR "/home"

Expand Down
6 changes: 3 additions & 3 deletions docs/HyBIG-Example-Usage.ipynb
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just changed 2 comments for line length.

Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
},
"outputs": [],
"source": [
"# if gdalinfo is installed you can see the palette associated with the PNG image.\n",
"# if gdalinfo is installed view the palette associated with the PNG image.\n",
"!gdalinfo hybig-output/example1/VCF5KYR_1991001_001_2018224205008.png"
]
},
Expand Down Expand Up @@ -318,7 +318,7 @@
"metadata": {},
"outputs": [],
"source": [
"# If gdal is installed this will show you the corner points associated with the output files.\n",
"# If gdal is installed, show the corner points associated with the output files.\n",
"!gdalinfo hybig-output/example2/ASTGTMV003_N00E022_dem.jpg | grep -E \"Left|Right\""
]
},
Expand Down Expand Up @@ -690,7 +690,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.12.6"
},
"name": "HyBIG-Example-Usage.ipynb"
},
Expand Down
10 changes: 5 additions & 5 deletions harmony_service/adapter.py
Copy link
Member

@owenlittlejohns owenlittlejohns Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR - but if you are cleaning things up, you could tweak the process_item method to use a context manager with tempfile.TemporaryDirectory (like you do in the SMAP L2 Gridder) instead of the mkdtemp and a finally for clean-up. Both work, and both are fine, but I think you convinced me the context manager is marginally simpler.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that. Maybe in a follow-on PR.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, mixing pytest fixtures and unittest patches.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow that was a dumb 🐰 🕳️ 4fcded7

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

"""

from os.path import basename
from pathlib import Path
from shutil import rmtree
from tempfile import mkdtemp
Expand Down Expand Up @@ -73,7 +72,8 @@ def get_asset_from_item(self, item: Item) -> Asset:
This is used to select which asset is used by HyBIG to generate
the browse image following these steps:

1. If found, return the first asset with 'visual' in any of the item's values' roles.
1. If found, return the first asset with 'visual' in any of the item's
values' roles.
2. If found, return the first asset that has 'data' in its item's values' roles.
3. Raise a StopIteration error.

Expand Down Expand Up @@ -145,7 +145,7 @@ def process_item(self, item: Item, source: HarmonySource) -> Item:

except Exception as exception:
self.logger.exception(exception)
raise HyBIGServiceError from exception
raise HyBIGServiceError(str(exception)) from exception
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This actually is a change before we logged the correct exception and raised a new one from the old, but the workflow-ui didn't show any information about it.

finally:
rmtree(working_directory)

Expand Down Expand Up @@ -174,7 +174,7 @@ def create_output_stac_item(
"""Create an output STAC item used to access the browse imagery and
ESRI world file as staged in S3.

asset_items are an array of tuples where the tuples should be: (name,
item_assets is an array of tuples where the tuples should be: (name,
url, role)

"""
Expand All @@ -191,7 +191,7 @@ def create_output_stac_item(

output_stac_item.assets[asset_name] = Asset(
url,
title=basename(url),
title=Path(url).name,
media_type=get_file_mime_type(url),
roles=[role],
)
Expand Down
4 changes: 2 additions & 2 deletions harmony_service/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def get_tiled_file_extension(file_name: Path) -> str:
generate the correct one to pass in.

"""
ext_pattern = r"(\.r\d+c\d+)?\.(png|jpg|pgw|jgw|txt)(.aux.xml)?"
ext_pattern = r'(\.r\d+c\d+)?\.(png|jpg|pgw|jgw|txt)(.aux.xml)?'
Copy link

@vutrannasa vutrannasa Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change double quote to single quote?
Consistently?
Coding standards?

Copy link
Member Author

@flamingbear flamingbear Dec 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both of those things. I don't have a preference, but I couldn't convince Owen to go to Black style formatting with the double quotes. I'm not actually sure how all of these became double quotes in the past because we did have some style checks that I thought would have caught them. The new ruff-formatting added and used by pre-commit.ci, runs on all files, and found all of the places where I just accidentally left double quotes in.

So tl;dr Yes, consistency and coding standards.

ok, I looked, before we used black-jupyter with "skip-string-normalization" which just leaves strings however you put them in, and doesn't change them. the pyproject.toml specifies "single" for quote style to force you to choose one. (consistency)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't convince Owen to go to Black style formatting with the double quotes.

😅

before we used black-jupyter with "skip-string-normalization" which just leaves strings however you put them in

Yup, this.

Why change double quote to single quote?
Consistently?
Coding standards?

I think somewhere in PEP008 there's a sentence about whether to use single or double quotes. The sentiment is basically: it doesn't really matter which, but pick one and use it consistently.

match = re.search(ext_pattern, file_name.name)
return match.group()

Expand All @@ -34,7 +34,7 @@ def get_asset_name(name: str, url: str) -> str:
dictionary.

"""
tiled_pattern = r"\.(r\d+c\d+)\."
tiled_pattern = r'\.(r\d+c\d+)\.'
tile_id = re.search(tiled_pattern, url)
if tile_id is not None:
name = f'{name}_{tile_id.groups()[0]}'
Expand Down
16 changes: 8 additions & 8 deletions hybig/browse_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ def get_harmony_message_from_params(params: dict | None) -> HarmonyMessage:

return HarmonyMessage(
{
"format": {
"mime": mime,
"crs": crs,
"srs": crs,
"scaleExtent": scale_extent,
"scaleSize": scale_size,
"height": height,
"width": width,
'format': {
'mime': mime,
'crs': crs,
'srs': crs,
'scaleExtent': scale_extent,
'scaleSize': scale_size,
'height': height,
'width': width,
},
}
)
4 changes: 2 additions & 2 deletions hybig/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def choose_crs_from_srs(srs: SRS):

"""
try:
if srs.epsg is not None and srs.epsg != "":
if srs.epsg is not None and srs.epsg != '':
return CRS.from_string(srs.epsg)
if srs.wkt is not None and srs.wkt != "":
if srs.wkt is not None and srs.wkt != '':
return CRS.from_string(srs.wkt)
return CRS.from_string(srs.proj4)
except Exception as exception:
Expand Down
2 changes: 1 addition & 1 deletion hybig/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class HyBIGError(Exception):
"""Base error class for exceptions rasied by HyBIG library."""
"""Base error class for exceptions raised by HyBIG library."""

def __init__(self, message=None):
"""All HyBIG errors have a message field."""
Expand Down
32 changes: 16 additions & 16 deletions hybig/sizes.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,29 +79,29 @@ class Dimensions(TypedDict):

# This is Table 4.1.8-1 WGS84 (EPSG: 4326 Resolutions)
epsg_4326_resolutions = [
ResolutionInfo("2km", 0.017578125, 10240, 20480, 6, 2),
ResolutionInfo("1km", 0.0087890625, 20480, 40960, 7, 2),
ResolutionInfo("500m", 0.00439453125, 40960, 81920, 8, 2),
ResolutionInfo("250m", 0.002197265625, 81920, 163840, 9, 2),
ResolutionInfo("125m", 0.0010986328125, 163840, 327680, 10, 2),
ResolutionInfo("62.5m", 0.00054931640625, 327680, 655360, 11, 2),
ResolutionInfo("31.25m", 0.000274658203125, 655360, 1310720, 12, 2),
ResolutionInfo("15.625m", 0.0001373291015625, 1310720, 2521440, 13, 2),
ResolutionInfo('2km', 0.017578125, 10240, 20480, 6, 2),
ResolutionInfo('1km', 0.0087890625, 20480, 40960, 7, 2),
ResolutionInfo('500m', 0.00439453125, 40960, 81920, 8, 2),
ResolutionInfo('250m', 0.002197265625, 81920, 163840, 9, 2),
ResolutionInfo('125m', 0.0010986328125, 163840, 327680, 10, 2),
ResolutionInfo('62.5m', 0.00054931640625, 327680, 655360, 11, 2),
ResolutionInfo('31.25m', 0.000274658203125, 655360, 1310720, 12, 2),
ResolutionInfo('15.625m', 0.0001373291015625, 1310720, 2521440, 13, 2),
]

# Conversion used above: resolution / pixel_size
METERS_PER_DEGREE = 113777.77777777778

# This is Table 4.1.8-2 NSIDC Sea Ice Polar Stereographic Extent (EPSG:3413) Resolutions
epsg_3413_resolutions = [
ResolutionInfo("2km", 2048, 4096, 4096, 3, 2),
ResolutionInfo("1km", 1024, 8192, 8192, 4, 2),
ResolutionInfo("500m", 512, 16384, 16384, 5, 2),
ResolutionInfo("250m", 256, 32768, 32768, 6, 2),
ResolutionInfo("125m", 128, 65536, 65536, 7, 2),
ResolutionInfo("62.5m", 64, 131072, 131072, 8, 2),
ResolutionInfo("31.25m", 32, 252144, 252144, 9, 2),
ResolutionInfo("15.625m", 16, 524288, 524288, 10, 2),
ResolutionInfo('2km', 2048, 4096, 4096, 3, 2),
ResolutionInfo('1km', 1024, 8192, 8192, 4, 2),
ResolutionInfo('500m', 512, 16384, 16384, 5, 2),
ResolutionInfo('250m', 256, 32768, 32768, 6, 2),
ResolutionInfo('125m', 128, 65536, 65536, 7, 2),
ResolutionInfo('62.5m', 64, 131072, 131072, 8, 2),
ResolutionInfo('31.25m', 32, 252144, 252144, 9, 2),
ResolutionInfo('15.625m', 16, 524288, 524288, 10, 2),
]

# The Antarctic resolutions match the northern resolutions precisely.
Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,17 @@ exclude = [

[tool.hatch.build.targets.wheel]
packages=["hybig"]

[tool.ruff]
lint.select = [
"E", # pycodestyle
"F", # pyflakes
"UP", # pyupgrade
"I", # organize imports
]

[tool.ruff.format]
quote-style = "single"

[tool.ruff.lint.pydocstyle]
convention = "google"
8 changes: 3 additions & 5 deletions tests/pip_test_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
coverage~=7.6.0
pycodestyle~=2.12.0
pylint~=3.2.6
pytest~=8.3.1
unittest-xml-reporting~=3.2.0
pylint~=3.3.1
pytest-cov~=6.0.0
pytest~=8.3.3
25 changes: 6 additions & 19 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,14 @@ STATUS=0
export HDF5_DISABLE_VERSION_CHECK=1
Copy link
Member Author

@flamingbear flamingbear Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line doesn't seem necessary. I wonder if it's here from another project...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is some straight-up cargo cult stuff from some older version of this script which has been copied and pasted from project to project. Agree with cutting it. (One day this file will be a glorious one liner that just becomes part of the CI/CD directly)


# Run the standard set of unit tests, producing JUnit compatible output
coverage run -m pytest tests --junitxml=tests/reports/test-results-"$(date +'%Y%m%d%H%M%S')".xml
RESULT=$?

if [ "$RESULT" -ne "0" ]; then
STATUS=1
echo "ERROR: unittest generated errors"
fi

echo "\n"
echo "Test Coverage Estimates"
coverage report --omit="tests/*"
coverage html --omit="tests/*" -d tests/coverage
pytest --cov=hybig --cov=harmony_service \
--cov-report=html:reports/coverage \
--cov-report term \
--junitxml=reports/test-reports/test-results-"$(date +'%Y%m%d%H%M%S')".xml || STATUS=1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if STATUS=1 is set from code above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where we set it when the test fails so that the exit code is non-zero on failures.


# Run pylint
# Ignored errors/warnings:
# W1203 - use of f-strings in log statements. This warning is leftover from
# using ''.format() vs % notation. For more information, see:
# https://github.com/PyCQA/pylint/issues/2354#issuecomment-414526879
pylint hybig harmony_service --disable=W1203
RESULT=$?
RESULT=$((3 & $RESULT))
pylint hybig harmony_service
RESULT=$((3 & $?))

if [ "$RESULT" -ne "0" ]; then
STATUS=1
Expand Down
35 changes: 0 additions & 35 deletions tests/test_code_format.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

This file was deleted.

1 change: 1 addition & 0 deletions tests/test_service/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Module definition for test_service."""
Loading
Loading