Skip to content

Commit

Permalink
Merge pull request #173 from ASFHyP3/mypy
Browse files Browse the repository at this point in the history
add mypy
  • Loading branch information
jtherrmann authored Jan 17, 2025
2 parents 209f66f + ab82a2e commit 2b02f49
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 15 deletions.
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file

version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
labels:
- bumpless
3 changes: 3 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ jobs:
call-ruff-workflow:
# Docs: https://github.com/ASFHyP3/actions
uses: ASFHyP3/actions/.github/workflows/[email protected]

call-mypy-workflow:
uses: ASFHyP3/actions/.github/workflows/[email protected]

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions Job or Workflow does not set permissions
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.7.2]
### Added
- Add `mypy` to [`static-analysis`](.github/workflows/static-analysis.yml)

## [0.7.1]
### Changed
- The [`static-analysis`](.github/workflows/static-analysis.yml) Github Actions workflow now uses `ruff` rather than `flake8` for linting.
Expand Down
11 changes: 11 additions & 0 deletions environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: gis-services
channels:
- conda-forge
- nodefaults
dependencies:
- python=3.7
- pip
- pip:
# conda-forge ruff seems to require Python >=3.8
- ruff
- mypy
6 changes: 3 additions & 3 deletions image_services/egis/create_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def make_configuration(data_type, polarization, season):
config = {
'project_name': 'GSSICB',
's3_prefix': 'tiles/',
's3_suffix': f"_{SEASONS[season]['Season']}_{polarization.lower()}_{data_type}.tif",
's3_suffix': f'_{SEASONS[season]["Season"]}_{polarization.lower()}_{data_type}.tif',
'dataset_name': f'{data_type}_{polarization.upper()}_{season}',
'raster_function_templates': ['ScaledCoherence.rft.xml', 'UnscaledCoherence.rft.xml'],
'default_raster_function_template': 'UnscaledCoherence.rft.xml',
Expand Down Expand Up @@ -65,8 +65,8 @@ def get_environment() -> Environment:

def render_template(template: str, payload: dict) -> str:
env = get_environment()
template = env.get_template(template)
rendered = template.render(payload)
template_object = env.get_template(template)
rendered = template_object.render(payload)
return rendered


Expand Down
2 changes: 1 addition & 1 deletion image_services/egis/make_egis_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_raster_metadata(raster_path: str) -> dict:
def update_csv(csv_file: str, rasters: List[str]):
if os.path.isfile(csv_file):
with open(csv_file) as f:
records = [record for record in csv.DictReader(f)]
records: list = [record for record in csv.DictReader(f)]
else:
records = []
logging.info(f'Found {len(records)} items in {csv_file}')
Expand Down
4 changes: 2 additions & 2 deletions image_services/egis/metadata/print_service_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def get_environment() -> Environment:

def render_template(template: str, payload: dict) -> str:
env = get_environment()
template = env.get_template(template)
rendered = template.render(payload)
template_object = env.get_template(template)
rendered = template_object.render(payload)
return rendered


Expand Down
4 changes: 2 additions & 2 deletions image_services/opera/metadata/create_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def get_environment() -> Environment:

def render_template(template: str, payload: dict) -> str:
env = get_environment()
template = env.get_template(template)
rendered = template.render(payload)
template_object = env.get_template(template)
rendered = template_object.render(payload)
return rendered


Expand Down
4 changes: 2 additions & 2 deletions image_services/opera/update_opera_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def query_cmr(polarization):
session = requests.Session()
search_url = 'https://cmr.earthdata.nasa.gov/search/granules.umm_json'

params = {
params: dict = {
'short_name': 'OPERA_L2_RTC-S1_V1',
'attribute[]': f'string,POLARIZATION,{polarization}',
'page_size': 2000,
}
headers = {}
headers: dict = {}
vsis3_uris = []
while True:
response = session.get(search_url, params=params, headers=headers)
Expand Down
4 changes: 2 additions & 2 deletions image_services/rtc_services/make_rtc_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def get_raster_metadata(raster_path: str) -> dict:
def update_csv(csv_file: str, rasters: List[str]):
if os.path.isfile(csv_file):
with open(csv_file) as f:
records = [record for record in csv.DictReader(f)]
records: list = [record for record in csv.DictReader(f)]
else:
records = []
logging.info(f'Found {len(records)} items in {csv_file}')
Expand Down Expand Up @@ -235,7 +235,7 @@ def build_wms_extension() -> etree.Element:
],
[
'DownloadURL',
f'"https://s3-us-west-2.amazonaws.com/hyp3-nasa-disasters/{config["s3_prefix"]}" ' f'+ !Name! + ".tif"',
f'"https://s3-us-west-2.amazonaws.com/hyp3-nasa-disasters/{config["s3_prefix"]}" + !Name! + ".tif"',
],
],
)
Expand Down
2 changes: 1 addition & 1 deletion image_services/sample_data/make_sample_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_raster_metadata(raster_path: str) -> dict:
def update_csv(csv_file: str, rasters: List[str]):
if os.path.isfile(csv_file):
with open(csv_file) as f:
records = [record for record in csv.DictReader(f)]
records: list = [record for record in csv.DictReader(f)]
else:
records = []
logging.info(f'Found {len(records)} items in {csv_file}')
Expand Down
13 changes: 11 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[project]
name = "gis_services"
# TODO: Pinning to 3.8 for ruff, figure out the actual appropriate version:
requires-python = "==3.8"
# TODO: not sure if the entire codebase was written for a particular Python version,
# choosing 3.7 for now based off of image_server/environment.yml
requires-python = "==3.7"

[tool.ruff]
line-length = 120
Expand Down Expand Up @@ -29,3 +30,11 @@ convention = "google"
[tool.ruff.lint.isort]
case-sensitive = true
lines-after-imports = 2

[tool.mypy]
python_version = "3.7"
warn_redundant_casts = true
warn_unused_ignores = true
warn_unreachable = true
strict_equality = true
check_untyped_defs = true

0 comments on commit 2b02f49

Please sign in to comment.