Skip to content

Commit

Permalink
Merge pull request #320 from ASFHyP3/add-ruff
Browse files Browse the repository at this point in the history
Switch to `ruff` from `flake8` for Static Analysis
  • Loading branch information
jtherrmann authored Dec 17, 2024
2 parents 92d6405 + 6613dc7 commit 8232b73
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 20 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ jobs:
# Docs: https://github.com/ASFHyP3/actions
uses: ASFHyP3/actions/.github/workflows/[email protected]

call-flake8-workflow:
call-ruff-workflow:
# Docs: https://github.com/ASFHyP3/actions
uses: ASFHyP3/actions/.github/workflows/[email protected]
with:
local_package_names: hyp3lib
uses: ASFHyP3/actions/.github/workflows/[email protected]
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 1 addition & 4 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -73,8 +70,12 @@ script-files = ["scripts/GC_map_mod"]
[tool.setuptools.packages.find]
where = ["src"]

[tool.setuptools_scm]

[tool.ruff]
line-length = 120
# The directories to consider when resolving first- vs. third-party imports.
# See: https://docs.astral.sh/ruff/settings/#src
src = ["src", "tests"]

[tool.ruff.format]
Expand All @@ -84,6 +85,7 @@ quote-style = "single"
[tool.ruff.lint]
extend-select = [
"I", # isort: https://docs.astral.sh/ruff/rules/#isort-i
# TODO: Uncomment the following extensions and address their warnings:
# "UP", # pyupgrade: https://docs.astral.sh/ruff/rules/#pyupgrade-up
# "D", # pydocstyle: https://docs.astral.sh/ruff/rules/#pydocstyle-d
# "ANN", # annotations: https://docs.astral.sh/ruff/rules/#flake8-annotations-ann
Expand All @@ -96,5 +98,3 @@ convention = "google"
[tool.ruff.lint.isort]
case-sensitive = true
lines-after-imports = 2

[tool.setuptools_scm]
1 change: 1 addition & 0 deletions src/hyp3lib/SLC_copy_S1_fullSW.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""re-process S1 SLC imagery into gamma format SLCs"""

import argparse
import logging
import os
Expand Down
1 change: 1 addition & 0 deletions src/hyp3lib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
OrbitDownloadError,
)


__version__ = version(__name__)

__all__ = [
Expand Down
6 changes: 3 additions & 3 deletions src/hyp3lib/asf_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/hyp3lib/byteSigmaScale.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Convert a floating point tiff into a byte tiff using 2-sigma scaling."""

import argparse
import os

Expand Down
1 change: 1 addition & 0 deletions src/hyp3lib/createAmp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Convert Geotiff Power to Amplitude"""

import argparse
import os

Expand Down
1 change: 1 addition & 0 deletions src/hyp3lib/fetch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for fetching things from external endpoints"""

import logging
from email.message import Message
from os.path import basename
Expand Down
1 change: 1 addition & 0 deletions src/hyp3lib/get_orb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from hyp3lib import OrbitDownloadError
from hyp3lib.fetch import download_file


ESA_CREATE_TOKEN_URL = 'https://identity.dataspace.copernicus.eu/auth/realms/CDSE/protocol/openid-connect/token'
ESA_DELETE_TOKEN_URL = 'https://identity.dataspace.copernicus.eu/auth/realms/CDSE/account/sessions'

Expand Down
8 changes: 5 additions & 3 deletions tests/test_get_orb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',),
Expand Down

0 comments on commit 8232b73

Please sign in to comment.