From fc2fcd61acb851d1c345ca17052f9f428be7078e Mon Sep 17 00:00:00 2001 From: Andrew Player Date: Mon, 16 Dec 2024 14:40:05 -0500 Subject: [PATCH] switch to ruff from flake8 --- .github/workflows/static-analysis.yml | 6 ++---- CHANGELOG.md | 5 +++++ environment.yml | 5 +---- pyproject.toml | 5 +---- ruff.toml | 4 ++++ src/hyp3lib/SLC_copy_S1_fullSW.py | 1 + src/hyp3lib/asf_geometry.py | 6 +++--- src/hyp3lib/byteSigmaScale.py | 1 + src/hyp3lib/createAmp.py | 1 + src/hyp3lib/fetch.py | 1 + tests/test_get_orb.py | 8 +++++--- 11 files changed, 25 insertions(+), 18 deletions(-) create mode 100644 ruff.toml diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 804805d..1d08910 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -7,8 +7,6 @@ jobs: # Docs: https://github.com/ASFHyP3/actions uses: ASFHyP3/actions/.github/workflows/reusable-secrets-analysis.yml@v0.12.0 - call-flake8-workflow: + call-ruff-workflow: # Docs: https://github.com/ASFHyP3/actions - uses: ASFHyP3/actions/.github/workflows/reusable-flake8.yml@v0.12.0 - with: - local_package_names: hyp3lib + uses: ASFHyP3/actions/.github/workflows/reusable-ruff.yml@v0.12.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 3acd4c2..fbf1307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/) and uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.1.3] + +### Changed +- The [`static-analysis`](.github/workflows/static-analysis.yml) Github Actions workflow now uses `ruff` rather than `flake8` for linting. + ## [3.1.2] ### Fixed diff --git a/environment.yml b/environment.yml index 2c97d9f..ea180df 100644 --- a/environment.yml +++ b/environment.yml @@ -18,10 +18,7 @@ dependencies: - urllib3 # For packaging, and testing - python-build - - flake8 - - flake8-import-order - - flake8-blind-except - - flake8-builtins + - ruff - setuptools - setuptools_scm - pytest diff --git a/pyproject.toml b/pyproject.toml index 6148ccb..c9e4ab8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -40,10 +40,7 @@ dynamic = ["version"] [project.optional-dependencies] develop = [ "botocore", - "flake8", - "flake8-import-order", - "flake8-blind-except", - "flake8-builtins", + "ruff", "pytest", "pytest-cov", "pytest-console-scripts", diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..61f9160 --- /dev/null +++ b/ruff.toml @@ -0,0 +1,4 @@ +line-length = 120 + +[format] +quote-style = "single" diff --git a/src/hyp3lib/SLC_copy_S1_fullSW.py b/src/hyp3lib/SLC_copy_S1_fullSW.py index 3177b39..7a6fe38 100755 --- a/src/hyp3lib/SLC_copy_S1_fullSW.py +++ b/src/hyp3lib/SLC_copy_S1_fullSW.py @@ -1,4 +1,5 @@ """re-process S1 SLC imagery into gamma format SLCs""" + import argparse import logging import os diff --git a/src/hyp3lib/asf_geometry.py b/src/hyp3lib/asf_geometry.py index d6148a8..b024903 100644 --- a/src/hyp3lib/asf_geometry.py +++ b/src/hyp3lib/asf_geometry.py @@ -126,7 +126,7 @@ def cut_blackfill(data, geoTrans): colFirst = rowProfile.index(1) originX += colFirst * pixelSize originY -= rowFirst * pixelSize - data = data[rowFirst:rows + rowFirst, colFirst:cols + colFirst] + data = data[rowFirst : rows + rowFirst, colFirst : cols + colFirst] geoTrans = (originX, pixelSize, 0, originY, 0, -pixelSize) return (data, colFirst, rowFirst, geoTrans) @@ -283,7 +283,7 @@ def data_geometry2shape_ext(data, fields, values, spatialRef, geoTrans, classes, originY = geoTrans[3] + 10 * pixelSize geoTrans = (originX, pixelSize, 0, originY, 0, -pixelSize) mask = np.zeros((rows + 20, cols + 20), dtype=np.float32) - mask[10:rows + 10, 10:cols + 10] = data + mask[10 : rows + 10, 10 : cols + 10] = data data = mask # Save in memory @@ -647,7 +647,7 @@ def apply_mask(data, dataGeoTrans, mask, maskGeoTrans): maskPixelSize = maskGeoTrans[1] offsetX = int(np.rint((maskOriginX - dataOriginX) / maskPixelSize)) offsetY = int(np.rint((dataOriginY - maskOriginY) / maskPixelSize)) - data = data[offsetY:maskRows + offsetY, offsetX:maskCols + offsetX] + data = data[offsetY : maskRows + offsetY, offsetX : maskCols + offsetX] data *= mask return data diff --git a/src/hyp3lib/byteSigmaScale.py b/src/hyp3lib/byteSigmaScale.py index d695b12..12001d7 100755 --- a/src/hyp3lib/byteSigmaScale.py +++ b/src/hyp3lib/byteSigmaScale.py @@ -1,4 +1,5 @@ """Convert a floating point tiff into a byte tiff using 2-sigma scaling.""" + import argparse import os diff --git a/src/hyp3lib/createAmp.py b/src/hyp3lib/createAmp.py index 5f4f870..52ec5a2 100755 --- a/src/hyp3lib/createAmp.py +++ b/src/hyp3lib/createAmp.py @@ -1,4 +1,5 @@ """Convert Geotiff Power to Amplitude""" + import argparse import os diff --git a/src/hyp3lib/fetch.py b/src/hyp3lib/fetch.py index a7d2184..a00b824 100644 --- a/src/hyp3lib/fetch.py +++ b/src/hyp3lib/fetch.py @@ -1,4 +1,5 @@ """Utilities for fetching things from external endpoints""" + import logging from email.message import Message from os.path import basename diff --git a/tests/test_get_orb.py b/tests/test_get_orb.py index 5e81e64..9078314 100644 --- a/tests/test_get_orb.py +++ b/tests/test_get_orb.py @@ -53,9 +53,11 @@ def test_download_sentinel_orbit_file_esa(tmp_path): match=[responses.matchers.header_matcher({'Authorization': 'Bearer test-token'})], ) - with patch('hyp3lib.get_orb.get_orbit_url', return_value='https://foo.bar/hello.txt'), patch( - 'hyp3lib.get_orb.EsaToken.__enter__', return_value='test-token' - ), patch('hyp3lib.get_orb.EsaToken.__exit__'): + with ( + patch('hyp3lib.get_orb.get_orbit_url', return_value='https://foo.bar/hello.txt'), + patch('hyp3lib.get_orb.EsaToken.__enter__', return_value='test-token'), + patch('hyp3lib.get_orb.EsaToken.__exit__'), + ): orbit_file, provider = get_orb.downloadSentinelOrbitFile( _GRANULE, providers=('ESA',),