Skip to content

Commit 1c8b4c4

Browse files
authored
Merge pull request #229 from stac-utils/add-mypy
Add mypy, update pre-commit
2 parents 66547c0 + 4a6f0c7 commit 1c8b4c4

File tree

7 files changed

+45
-22
lines changed

7 files changed

+45
-22
lines changed

.pre-commit-config.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
11
repos:
22
- repo: https://github.com/PyCQA/flake8
3-
rev: 3.9.1
3+
rev: 6.1.0
44
hooks:
55
- id: flake8
66
- repo: https://github.com/timothycrosley/isort
7-
rev: 5.11.5
7+
rev: 5.12.0
88
hooks:
99
- id: isort
1010
args: ["--profile", "black"]
1111
- repo: https://github.com/psf/black
12-
rev: 22.3.0
12+
rev: 23.11.0
1313
hooks:
1414
- id: black
15-
language_version: python3.8
15+
language_version: python3.8
16+
- repo: https://github.com/pre-commit/mirrors-mypy
17+
rev: v1.7.0
18+
hooks:
19+
- id: mypy
20+
exclude: /tests/
21+
# --strict
22+
args: [
23+
--no-strict-optional,
24+
--ignore-missing-imports,
25+
--implicit-reexport,
26+
--explicit-package-bases,
27+
]
28+
additional_dependencies: [
29+
"types-attrs",
30+
"types-requests"
31+
]

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Added mypy to pre-commit config ([#229](https://github.com/stac-utils/stac-validator/pull/224))
12+
913
## [v3.3.2] - 2023-11-17
1014

1115
### Added

docs/conf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
# list see the documentation:
55
# https://www.sphinx-doc.org/en/master/usage/configuration.html
66

7+
from typing import List
8+
79
# -- Path setup --------------------------------------------------------------
810

911
# If extensions (or modules to document with autodoc) are in another directory,
@@ -30,7 +32,7 @@
3032
# Add any Sphinx extension module names here, as strings. They can be
3133
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3234
# ones.
33-
extensions = []
35+
extensions: List[str] = []
3436

3537
# Add any paths that contain templates here, relative to this directory.
3638
templates_path = ["_templates"]

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"Intended Audience :: Information Technology",
1919
"Intended Audience :: Science/Research",
2020
"License :: OSI Approved :: Apache Software License",
21-
"Programming Language :: Python :: 3.7",
21+
"Programming Language :: Python :: 3.8",
2222
"Topic :: Scientific/Engineering :: GIS",
2323
],
2424
keywords="STAC validation raster",

stac_validator/utilities.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import functools
22
import json
33
import ssl
4+
from typing import Dict
45
from urllib.parse import urlparse
56
from urllib.request import urlopen
67

@@ -44,7 +45,7 @@ def is_valid_url(url: str) -> bool:
4445
return urlparse(url).scheme in ["http", "https"]
4546

4647

47-
def get_stac_type(stac_content: dict) -> str:
48+
def get_stac_type(stac_content: Dict) -> str:
4849
"""Determine the type of a STAC resource.
4950
5051
Given a dictionary representing a STAC resource, this function determines the
@@ -74,7 +75,7 @@ def get_stac_type(stac_content: dict) -> str:
7475
return str(e)
7576

7677

77-
def fetch_and_parse_file(input_path: str) -> dict:
78+
def fetch_and_parse_file(input_path: str) -> Dict:
7879
"""Fetches and parses a JSON file from a URL or local file.
7980
8081
Given a URL or local file path to a JSON file, this function fetches the file,
@@ -107,7 +108,7 @@ def fetch_and_parse_file(input_path: str) -> dict:
107108

108109

109110
@functools.lru_cache(maxsize=48)
110-
def fetch_and_parse_schema(input_path: str) -> dict:
111+
def fetch_and_parse_schema(input_path: str) -> Dict:
111112
"""Fetches and parses a JSON schema file from a URL or local file using a cache.
112113
113114
Given a URL or local file path to a JSON schema file, this function fetches the file
@@ -147,8 +148,8 @@ def set_schema_addr(version: str, stac_type: str) -> str:
147148

148149

149150
def link_request(
150-
link: dict,
151-
initial_message: dict,
151+
link: Dict,
152+
initial_message: Dict,
152153
) -> None:
153154
"""Makes a request to a URL and appends it to the relevant field of the initial message.
154155

stac_validator/validate.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import json
22
import os
33
from json.decoder import JSONDecodeError
4-
from typing import Optional
4+
from typing import Dict, List, Optional
55
from urllib.error import HTTPError, URLError
66

77
import click # type: ignore
@@ -60,23 +60,23 @@ def __init__(
6060
self.stac_file = stac_file
6161
self.item_collection = item_collection
6262
self.pages = pages
63-
self.message: list = []
63+
self.message: List = []
6464
self.schema = custom
6565
self.links = links
6666
self.assets = assets
6767
self.recursive = recursive
6868
self.max_depth = max_depth
6969
self.extensions = extensions
7070
self.core = core
71-
self.stac_content: dict = {}
71+
self.stac_content: Dict = {}
7272
self.version = ""
7373
self.depth: int = 0
7474
self.skip_val = False
7575
self.verbose = verbose
7676
self.valid = False
7777
self.log = log
7878

79-
def create_err_msg(self, err_type: str, err_msg: str) -> dict:
79+
def create_err_msg(self, err_type: str, err_msg: str) -> Dict:
8080
self.valid = False
8181
return {
8282
"version": self.version,
@@ -99,7 +99,7 @@ def create_links_message(self):
9999
"request_invalid": request_invalid,
100100
}
101101

102-
def create_message(self, stac_type: str, val_type: str) -> dict:
102+
def create_message(self, stac_type: str, val_type: str) -> Dict:
103103
return {
104104
"version": self.version,
105105
"path": self.stac_file,
@@ -109,7 +109,7 @@ def create_message(self, stac_type: str, val_type: str) -> dict:
109109
"validation_method": val_type,
110110
}
111111

112-
def assets_validator(self) -> dict:
112+
def assets_validator(self) -> Dict:
113113
"""Validate assets.
114114
115115
Returns:
@@ -122,7 +122,7 @@ def assets_validator(self) -> dict:
122122
link_request(asset, initial_message)
123123
return initial_message
124124

125-
def links_validator(self) -> dict:
125+
def links_validator(self) -> Dict:
126126
"""Validate links.
127127
128128
Returns:
@@ -143,7 +143,7 @@ def links_validator(self) -> dict:
143143

144144
return initial_message
145145

146-
def extensions_validator(self, stac_type: str) -> dict:
146+
def extensions_validator(self, stac_type: str) -> Dict:
147147
"""Validate the STAC extensions according to their corresponding JSON schemas.
148148
149149
Args:
@@ -253,7 +253,7 @@ def core_validator(self, stac_type: str) -> None:
253253
self.schema = set_schema_addr(self.version, stac_type)
254254
self.custom_validator()
255255

256-
def default_validator(self, stac_type: str) -> dict:
256+
def default_validator(self, stac_type: str) -> Dict:
257257
"""Validate the STAC catalog or item against the core schema and its extensions.
258258
259259
Args:
@@ -379,7 +379,7 @@ def validate_dict(self, stac_content) -> bool:
379379
self.stac_content = stac_content
380380
return self.run()
381381

382-
def validate_item_collection_dict(self, item_collection: dict) -> None:
382+
def validate_item_collection_dict(self, item_collection: Dict) -> None:
383383
"""Validate the contents of an item collection.
384384
385385
Args:

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = py37,py38,py39
2+
envlist = py38,py39,py310,py311
33

44
[testenv]
55
deps = pytest

0 commit comments

Comments
 (0)