From f05fe3884f7fccfe98369c33866ee601cff29430 Mon Sep 17 00:00:00 2001 From: Owen Littlejohns Date: Wed, 17 Apr 2024 15:08:01 -0400 Subject: [PATCH 1/2] IP-241 - Implement ruff import ordering. --- .pre-commit-config.yaml | 2 +- hoss/adapter.py | 4 ++-- hoss/bbox_utilities.py | 5 ++--- hoss/dimension_utilities.py | 10 ++++------ hoss/projection_utilities.py | 5 ++--- hoss/spatial.py | 6 +++--- hoss/subset.py | 7 ++++--- hoss/temporal.py | 3 +-- hoss/utilities.py | 5 +++-- tests/test_adapter.py | 6 +++--- tests/unit/test_adapter.py | 8 ++++---- tests/unit/test_bbox_utilities.py | 6 +++--- tests/unit/test_dimension_utilities.py | 10 +++++----- tests/unit/test_projection_utilities.py | 6 +++--- tests/unit/test_spatial.py | 4 ++-- tests/unit/test_subset.py | 11 ++++++----- tests/unit/test_temporal.py | 2 +- tests/utilities.py | 1 - 18 files changed, 49 insertions(+), 52 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 230e5c4..6d27033 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: rev: v0.3.4 hooks: - id: ruff - args: ["--fix", "--show-fixes"] + args: ["--fix", "--show-fixes", "--select", "I"] - repo: https://github.com/psf/black-pre-commit-mirror rev: 24.3.0 hooks: diff --git a/hoss/adapter.py b/hoss/adapter.py index 4215bed..c96cdc0 100644 --- a/hoss/adapter.py +++ b/hoss/adapter.py @@ -27,11 +27,11 @@ import shutil from tempfile import mkdtemp -from pystac import Asset, Item from harmony import BaseHarmonyAdapter from harmony.message import Source -from harmony.util import generate_output_filename, HarmonyException, stage +from harmony.util import HarmonyException, generate_output_filename, stage +from pystac import Asset, Item from hoss.dimension_utilities import is_index_subset from hoss.subset import subset_granule diff --git a/hoss/bbox_utilities.py b/hoss/bbox_utilities.py index 0e5152a..fc0594f 100644 --- a/hoss/bbox_utilities.py +++ b/hoss/bbox_utilities.py @@ -14,18 +14,17 @@ """ +import json from collections import namedtuple from logging import Logger from typing import Dict, List, Optional, Tuple, Union -import json +import numpy as np from harmony.message import Message from harmony.util import Config, download -import numpy as np from hoss.exceptions import InvalidInputGeoJSON, UnsupportedShapeFileFormat - AggCoordinates = List[Tuple[float]] BBox = namedtuple('BBox', ['west', 'south', 'east', 'north']) Coordinates = Union[ diff --git a/hoss/dimension_utilities.py b/hoss/dimension_utilities.py index 0e00742..59fe6b0 100644 --- a/hoss/dimension_utilities.py +++ b/hoss/dimension_utilities.py @@ -11,17 +11,16 @@ """ from logging import Logger +from pathlib import PurePosixPath from typing import Dict, Set, Tuple -from pathlib import PurePosixPath -from netCDF4 import Dataset -from numpy.ma.core import MaskedArray import numpy as np - from harmony.message import Message from harmony.message_utility import rgetattr from harmony.util import Config -from varinfo import VarInfoFromDmr, VariableFromDmr +from netCDF4 import Dataset +from numpy.ma.core import MaskedArray +from varinfo import VariableFromDmr, VarInfoFromDmr from hoss.bbox_utilities import flatten_list from hoss.exceptions import InvalidNamedDimension, InvalidRequestedRange @@ -31,7 +30,6 @@ get_value_or_default, ) - IndexRange = Tuple[int] IndexRanges = Dict[str, IndexRange] diff --git a/hoss/projection_utilities.py b/hoss/projection_utilities.py index 78d600e..bdacdc0 100644 --- a/hoss/projection_utilities.py +++ b/hoss/projection_utilities.py @@ -10,9 +10,10 @@ """ -from typing import Dict, get_args, List, Optional, Tuple, Union import json +from typing import Dict, List, Optional, Tuple, Union, get_args +import numpy as np from pyproj import CRS, Transformer from shapely.geometry import ( GeometryCollection, @@ -25,7 +26,6 @@ shape, ) from varinfo import VarInfoFromDmr -import numpy as np from hoss.bbox_utilities import BBox, flatten_list from hoss.exceptions import ( @@ -35,7 +35,6 @@ MissingSpatialSubsetInformation, ) - Coordinates = Tuple[float] MultiShape = Union[GeometryCollection, MultiLineString, MultiPoint, MultiPolygon] Shape = Union[LineString, Point, Polygon, MultiShape] diff --git a/hoss/spatial.py b/hoss/spatial.py index 91129fb..79eb5c2 100644 --- a/hoss/spatial.py +++ b/hoss/spatial.py @@ -31,16 +31,16 @@ from hoss.bbox_utilities import ( BBox, + get_geographic_bbox, get_harmony_message_bbox, get_shape_file_geojson, - get_geographic_bbox, ) from hoss.dimension_utilities import ( + IndexRange, + IndexRanges, get_dimension_bounds, get_dimension_extents, get_dimension_index_range, - IndexRange, - IndexRanges, ) from hoss.projection_utilities import ( get_projected_x_y_extents, diff --git a/hoss/subset.py b/hoss/subset.py index fb5f740..8a01321 100644 --- a/hoss/subset.py +++ b/hoss/subset.py @@ -8,7 +8,8 @@ from logging import Logger from typing import List, Set -from harmony.message import Message, Source, Variable as HarmonyVariable +from harmony.message import Message, Source +from harmony.message import Variable as HarmonyVariable from harmony.message_utility import rgetattr from harmony.util import Config from netCDF4 import Dataset @@ -17,11 +18,11 @@ from hoss.bbox_utilities import get_request_shape_file from hoss.dimension_utilities import ( + IndexRanges, add_index_range, get_fill_slice, - IndexRanges, - is_index_subset, get_requested_index_ranges, + is_index_subset, prefetch_dimension_variables, ) from hoss.spatial import get_spatial_index_ranges diff --git a/hoss/temporal.py b/hoss/temporal.py index a5a3559..2c1339e 100644 --- a/hoss/temporal.py +++ b/hoss/temporal.py @@ -17,13 +17,12 @@ from varinfo import VarInfoFromDmr from hoss.dimension_utilities import ( + IndexRanges, get_dimension_bounds, get_dimension_index_range, - IndexRanges, ) from hoss.exceptions import UnsupportedTemporalUnits - units_day = {'day', 'days', 'd'} units_hour = {'hour', 'hours', 'hr', 'h'} units_min = {'minutes', 'minute', 'min', 'mins'} diff --git a/hoss/utilities.py b/hoss/utilities.py index 4c0b9b0..aba78a5 100644 --- a/hoss/utilities.py +++ b/hoss/utilities.py @@ -4,6 +4,7 @@ """ +import mimetypes from logging import Logger from os import sep from os.path import splitext @@ -11,10 +12,10 @@ from typing import Dict, Optional, Set, Tuple from urllib.parse import quote from uuid import uuid4 -import mimetypes from harmony.exceptions import ForbiddenException, ServerException -from harmony.util import Config, download as util_download +from harmony.util import Config +from harmony.util import download as util_download from hoss.exceptions import UrlAccessFailed diff --git a/tests/test_adapter.py b/tests/test_adapter.py index 929a6fb..ab5a8c7 100755 --- a/tests/test_adapter.py +++ b/tests/test_adapter.py @@ -10,16 +10,16 @@ from tempfile import mkdtemp from typing import Dict, Set from unittest import TestCase -from unittest.mock import ANY, call, Mock, patch +from unittest.mock import ANY, Mock, call, patch from harmony.message import Message -from harmony.util import config, HarmonyException +from harmony.util import HarmonyException, config from netCDF4 import Dataset from numpy.testing import assert_array_equal from pystac import Catalog from hoss.adapter import HossAdapter -from tests.utilities import create_stac, Granule, write_dmr +from tests.utilities import Granule, create_stac, write_dmr class TestHossEndToEnd(TestCase): diff --git a/tests/unit/test_adapter.py b/tests/unit/test_adapter.py index 32d6701..977c01d 100644 --- a/tests/unit/test_adapter.py +++ b/tests/unit/test_adapter.py @@ -1,14 +1,14 @@ -from typing import List, Dict, Optional -from unittest import TestCase -from unittest.mock import patch, ANY import json +from typing import Dict, List, Optional +from unittest import TestCase +from unittest.mock import ANY, patch from harmony.message import Message from harmony.util import config from hoss.adapter import HossAdapter from hoss.bbox_utilities import BBox -from tests.utilities import create_stac, Granule, spy_on +from tests.utilities import Granule, create_stac, spy_on @patch('hoss.adapter.get_file_mimetype') diff --git a/tests/unit/test_bbox_utilities.py b/tests/unit/test_bbox_utilities.py index 8b8946c..db99d33 100644 --- a/tests/unit/test_bbox_utilities.py +++ b/tests/unit/test_bbox_utilities.py @@ -7,25 +7,25 @@ """ +import json from logging import getLogger from os.path import join as path_join from unittest import TestCase from unittest.mock import patch -import json from harmony.message import Message from harmony.util import config from hoss.bbox_utilities import ( + BBox, aggregate_all_geometries, aggregate_geometry_coordinates, - BBox, bbox_in_longitude_range, crosses_antimeridian, flatten_list, - get_bounding_box_lon_lat, get_antimeridian_bbox, get_antimeridian_geometry_bbox, + get_bounding_box_lon_lat, get_contiguous_bbox, get_geographic_bbox, get_harmony_message_bbox, diff --git a/tests/unit/test_dimension_utilities.py b/tests/unit/test_dimension_utilities.py index 51ac018..4e8d789 100644 --- a/tests/unit/test_dimension_utilities.py +++ b/tests/unit/test_dimension_utilities.py @@ -5,16 +5,18 @@ from unittest import TestCase from unittest.mock import ANY, patch -from harmony.util import config +import numpy as np from harmony.message import Message +from harmony.util import config from netCDF4 import Dataset from numpy.ma import masked_array from numpy.testing import assert_array_equal from varinfo import VarInfoFromDmr -import numpy as np from hoss.dimension_utilities import ( + add_bounds_variables, add_index_range, + get_bounds_array, get_dimension_bounds, get_dimension_extents, get_dimension_index_range, @@ -25,10 +27,8 @@ is_almost_in, is_dimension_ascending, is_index_subset, - prefetch_dimension_variables, - add_bounds_variables, needs_bounds, - get_bounds_array, + prefetch_dimension_variables, write_bounds, ) from hoss.exceptions import InvalidNamedDimension, InvalidRequestedRange diff --git a/tests/unit/test_projection_utilities.py b/tests/unit/test_projection_utilities.py index 2c3a955..0da8f66 100644 --- a/tests/unit/test_projection_utilities.py +++ b/tests/unit/test_projection_utilities.py @@ -5,17 +5,17 @@ """ +import json from os.path import join as path_join from shutil import rmtree from tempfile import mkdtemp from unittest import TestCase from unittest.mock import call, patch -import json +import numpy as np from pyproj import CRS from shapely.geometry import Polygon, shape from varinfo import VarInfoFromDmr -import numpy as np from hoss.bbox_utilities import BBox from hoss.exceptions import ( @@ -26,8 +26,8 @@ ) from hoss.projection_utilities import ( get_bbox_polygon, - get_grid_lat_lons, get_geographic_resolution, + get_grid_lat_lons, get_projected_x_y_extents, get_projected_x_y_variables, get_resolved_feature, diff --git a/tests/unit/test_spatial.py b/tests/unit/test_spatial.py index 9f55ad4..e5ee6d3 100644 --- a/tests/unit/test_spatial.py +++ b/tests/unit/test_spatial.py @@ -3,19 +3,19 @@ from unittest import TestCase from unittest.mock import ANY, call, patch +import numpy as np from harmony.message import Message from netCDF4 import Dataset from numpy.testing import assert_array_equal from pyproj import CRS from varinfo import VarInfoFromDmr -import numpy as np from hoss.bbox_utilities import BBox from hoss.spatial import ( get_bounding_box_longitudes, get_geographic_index_range, - get_projected_x_y_index_ranges, get_longitude_in_grid, + get_projected_x_y_index_ranges, get_spatial_index_ranges, ) diff --git a/tests/unit/test_subset.py b/tests/unit/test_subset.py index 51699bc..abbb5f1 100644 --- a/tests/unit/test_subset.py +++ b/tests/unit/test_subset.py @@ -1,18 +1,19 @@ +import shutil from logging import Logger +from tempfile import mkdtemp from unittest import TestCase from unittest.mock import call, patch -import shutil -from tempfile import mkdtemp -from harmony.message import Message, Source, Variable as HarmonyVariable +import numpy as np +from harmony.message import Message, Source +from harmony.message import Variable as HarmonyVariable from harmony.util import config from netCDF4 import Dataset from varinfo import VarInfoFromDmr -import numpy as np from hoss.subset import ( - fill_variables, fill_variable, + fill_variables, get_required_variables, get_varinfo, subset_granule, diff --git a/tests/unit/test_temporal.py b/tests/unit/test_temporal.py index 8e043ac..627a094 100644 --- a/tests/unit/test_temporal.py +++ b/tests/unit/test_temporal.py @@ -4,10 +4,10 @@ from unittest import TestCase from unittest.mock import ANY, patch +import numpy as np from harmony.message import Message from netCDF4 import Dataset from numpy.testing import assert_array_equal -import numpy as np from varinfo import VarInfoFromDmr from hoss.exceptions import UnsupportedTemporalUnits diff --git a/tests/utilities.py b/tests/utilities.py index 564a1ba..7aa25ad 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -8,7 +8,6 @@ from harmony.util import bbox_to_geometry from pystac import Asset, Catalog, Item - Granule = namedtuple('Granule', ['url', 'media_type', 'roles']) From b305ca96364ff8204f46f3a8d69ae6b9eb69ba3d Mon Sep 17 00:00:00 2001 From: Owen Littlejohns Date: Wed, 17 Apr 2024 15:09:10 -0400 Subject: [PATCH 2/2] IP-241 - Ignore ruff import ordering via .git-blame-ignore-revs. --- .git-blame-ignore-revs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 0514463..a95f82e 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -3,3 +3,6 @@ # Black code formatting of entire repository 56dd43f69d901abbba6cfb765a98dee26ff71cfc + +# Ruff ordering of imports for entire repository +f05fe3884f7fccfe98369c33866ee601cff29430