Skip to content

Commit

Permalink
Merge pull request #65 from ASFHyP3/ruff
Browse files Browse the repository at this point in the history
update ruff config
  • Loading branch information
AndrewPlayer3 authored Dec 17, 2024
2 parents 0f852db + 8a8f77c commit 1efc155
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 31 deletions.
26 changes: 26 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,29 @@ readme = {file = ["README.md"], content-type = "text/markdown"}
where = ["src"]

[tool.setuptools_scm]

[tool.ruff]
line-length = 120
src = ["src", "tests"]

[tool.ruff.format]
indent-style = "space"
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
#"PTH", # use-pathlib-pth: https://docs.astral.sh/ruff/rules/#flake8-use-pathlib-pth
]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
case-sensitive = true
lines-after-imports = 2
4 changes: 0 additions & 4 deletions ruff.toml

This file was deleted.

1 change: 1 addition & 0 deletions src/hyp3_srg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from importlib.metadata import version


__version__ = version(__name__)

__all__ = [
Expand Down
4 changes: 1 addition & 3 deletions src/hyp3_srg/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""
HyP3 plugin for Stanford Radar Group (SRG) SAR Processor
"""
"""HyP3 plugin for Stanford Radar Group (SRG) SAR Processor"""

import argparse
import sys
Expand Down
8 changes: 3 additions & 5 deletions src/hyp3_srg/back_projection.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
"""
GSLC back-projection processing
"""
"""GSLC back-projection processing"""

import argparse
import logging
import os
import zipfile
from collections.abc import Iterable
from pathlib import Path
from typing import Iterable, Optional

from hyp3lib.aws import upload_file_to_s3
from shapely import unary_union
Expand Down Expand Up @@ -93,7 +91,7 @@ def back_project(
bucket: str = None,
bucket_prefix: str = '',
use_gslc_prefix: bool = False,
work_dir: Optional[Path] = None,
work_dir: Path | None = None,
gpu: bool = False,
):
"""Back-project a set of Sentinel-1 level-0 granules.
Expand Down
3 changes: 1 addition & 2 deletions src/hyp3_srg/dem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import logging
from pathlib import Path
from typing import Optional

import requests

Expand All @@ -28,7 +27,7 @@ def ensure_egm_model_available():
f.write(chunk)


def download_dem_for_srg(bounds: list[float], work_dir: Optional[Path]):
def download_dem_for_srg(bounds: list[float], work_dir: Path | None):
"""Download the DEM for the given bounds - [min_lon, min_lat, max_lon, max_lat].
Args:
Expand Down
14 changes: 6 additions & 8 deletions src/hyp3_srg/time_series.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
"""
Sentinel-1 GSLC time series processing
"""
"""Sentinel-1 GSLC time series processing"""

import argparse
import logging
import shutil
from collections.abc import Iterable
from os import mkdir
from pathlib import Path
from secrets import token_hex
from shutil import copyfile
from typing import Iterable, Optional

from hyp3lib.aws import upload_file_to_s3
from hyp3lib.fetch import download_file as download_from_http
Expand Down Expand Up @@ -172,10 +170,10 @@ def compute_sbas_velocity_solution(
tropo_correct_args = ['unwlist', unw_width, unw_length]
utils.call_stanford_module('int/tropocorrect.py', args=tropo_correct_args, work_dir=work_dir)

with open(work_dir / 'unwlist', 'r') as unw_list:
with open(work_dir / 'unwlist') as unw_list:
num_unw_files = len(unw_list.readlines())

with open(work_dir / 'geolist', 'r') as slc_list:
with open(work_dir / 'geolist') as slc_list:
num_slcs = len(slc_list.readlines())

sbas_velocity_args = ['unwlist', num_unw_files, num_slcs, unw_width, 'ref_locs']
Expand Down Expand Up @@ -259,7 +257,7 @@ def lon_string(lon):
)


def package_time_series(granules: list[str], bounds: list[float], work_dir: Optional[Path] = None) -> Path:
def package_time_series(granules: list[str], bounds: list[float], work_dir: Path | None = None) -> Path:
"""Package the time series into a product zip file.
Args:
Expand Down Expand Up @@ -304,7 +302,7 @@ def time_series(
use_gslc_prefix: bool,
bucket: str = None,
bucket_prefix: str = '',
work_dir: Optional[Path] = None,
work_dir: Path | None = None,
) -> None:
"""Create and package a time series stack from a set of Sentinel-1 GSLCs.
Expand Down
17 changes: 8 additions & 9 deletions src/hyp3_srg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import subprocess
from pathlib import Path
from platform import system
from typing import List, Optional, Tuple
from zipfile import ZipFile

import asf_search
Expand Down Expand Up @@ -58,7 +57,7 @@ def set_creds(service, username, password) -> None:
os.environ[f'{service.upper()}_PASSWORD'] = password


def find_creds_in_env(username_name, password_name) -> Tuple[str, str]:
def find_creds_in_env(username_name, password_name) -> tuple[str, str]:
"""Find credentials for a service in the environment.
Args:
Expand All @@ -76,7 +75,7 @@ def find_creds_in_env(username_name, password_name) -> Tuple[str, str]:
return None, None


def find_creds_in_netrc(service) -> Tuple[str, str]:
def find_creds_in_netrc(service) -> tuple[str, str]:
"""Find credentials for a service in the netrc file.
Args:
Expand All @@ -96,7 +95,7 @@ def find_creds_in_netrc(service) -> Tuple[str, str]:
return None, None


def get_earthdata_credentials() -> Tuple[str, str]:
def get_earthdata_credentials() -> tuple[str, str]:
"""Get NASA EarthData credentials from the environment or netrc file.
Returns:
Expand All @@ -116,7 +115,7 @@ def get_earthdata_credentials() -> Tuple[str, str]:
)


def download_raw_granule(granule_name: str, output_dir: Path, unzip: bool = False) -> Tuple[Path, Polygon]:
def download_raw_granule(granule_name: str, output_dir: Path, unzip: bool = False) -> tuple[Path, Polygon]:
"""Download a S1 granule using asf_search. Return its path
and buffered extent.
Expand Down Expand Up @@ -156,7 +155,7 @@ def download_raw_granule(granule_name: str, output_dir: Path, unzip: bool = Fals
return out_path, bbox


def get_bbox(granule_name: str) -> Tuple[Path, Polygon]:
def get_bbox(granule_name: str) -> tuple[Path, Polygon]:
"""Get the buffered extent from asf_search.
Args:
Expand Down Expand Up @@ -204,7 +203,7 @@ def create_param_file(dem_path: Path, dem_rsc_path: Path, output_dir: Path):
f.write('\n'.join(lines))


def call_stanford_module(local_name, args: List = [], work_dir: Optional[Path] = None) -> None:
def call_stanford_module(local_name, args: list = [], work_dir: Path | None = None) -> None:
"""Call a Stanford Processor modules (via subprocess) with the given arguments.
Args:
Expand All @@ -231,7 +230,7 @@ def how_many_gpus():
return ngpus


def get_s3_args(uri: str, dest_dir: Optional[Path] = None) -> None:
def get_s3_args(uri: str, dest_dir: Path | None = None) -> None:
"""Retrieve the arguments for downloading from an S3 bucket
Args:
Expand Down Expand Up @@ -268,7 +267,7 @@ def s3_list_objects(bucket: str, prefix: str = '') -> dict:
return res


def download_from_s3(uri: str, dest_dir: Optional[Path] = None) -> None:
def download_from_s3(uri: str, dest_dir: Path | None = None) -> None:
"""Download a file from an S3 bucket
Args:
Expand Down

0 comments on commit 1efc155

Please sign in to comment.