Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mypy, update pre-commit #229

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
repos:
- repo: https://github.com/PyCQA/flake8
rev: 3.9.1
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/timothycrosley/isort
rev: 5.11.5
rev: 5.12.0
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/psf/black
rev: 22.3.0
rev: 23.11.0
hooks:
- id: black
language_version: python3.8
language_version: python3.8
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.0
hooks:
- id: mypy
exclude: /tests/
# --strict
args: [
--no-strict-optional,
--ignore-missing-imports,
--implicit-reexport,
--explicit-package-bases,
]
additional_dependencies: [
"types-attrs",
"types-requests"
]
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)

## [Unreleased]

### Added

- Added mypy to pre-commit config ([#229](https://github.com/stac-utils/stac-validator/pull/224))

## [v3.3.2] - 2023-11-17

### Added
Expand Down
4 changes: 3 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

from typing import List

# -- Path setup --------------------------------------------------------------

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

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"Intended Audience :: Information Technology",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Topic :: Scientific/Engineering :: GIS",
],
keywords="STAC validation raster",
Expand Down
11 changes: 6 additions & 5 deletions stac_validator/utilities.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import json
import ssl
from typing import Dict
from urllib.parse import urlparse
from urllib.request import urlopen

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


def get_stac_type(stac_content: dict) -> str:
def get_stac_type(stac_content: Dict) -> str:
"""Determine the type of a STAC resource.

Given a dictionary representing a STAC resource, this function determines the
Expand Down Expand Up @@ -74,7 +75,7 @@ def get_stac_type(stac_content: dict) -> str:
return str(e)


def fetch_and_parse_file(input_path: str) -> dict:
def fetch_and_parse_file(input_path: str) -> Dict:
"""Fetches and parses a JSON file from a URL or local file.

Given a URL or local file path to a JSON file, this function fetches the file,
Expand Down Expand Up @@ -107,7 +108,7 @@ def fetch_and_parse_file(input_path: str) -> dict:


@functools.lru_cache(maxsize=48)
def fetch_and_parse_schema(input_path: str) -> dict:
def fetch_and_parse_schema(input_path: str) -> Dict:
"""Fetches and parses a JSON schema file from a URL or local file using a cache.

Given a URL or local file path to a JSON schema file, this function fetches the file
Expand Down Expand Up @@ -147,8 +148,8 @@ def set_schema_addr(version: str, stac_type: str) -> str:


def link_request(
link: dict,
initial_message: dict,
link: Dict,
initial_message: Dict,
) -> None:
"""Makes a request to a URL and appends it to the relevant field of the initial message.

Expand Down
20 changes: 10 additions & 10 deletions stac_validator/validate.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json
import os
from json.decoder import JSONDecodeError
from typing import Optional
from typing import Dict, List, Optional
from urllib.error import HTTPError, URLError

import click # type: ignore
Expand Down Expand Up @@ -60,23 +60,23 @@ def __init__(
self.stac_file = stac_file
self.item_collection = item_collection
self.pages = pages
self.message: list = []
self.message: List = []
self.schema = custom
self.links = links
self.assets = assets
self.recursive = recursive
self.max_depth = max_depth
self.extensions = extensions
self.core = core
self.stac_content: dict = {}
self.stac_content: Dict = {}
self.version = ""
self.depth: int = 0
self.skip_val = False
self.verbose = verbose
self.valid = False
self.log = log

def create_err_msg(self, err_type: str, err_msg: str) -> dict:
def create_err_msg(self, err_type: str, err_msg: str) -> Dict:
self.valid = False
return {
"version": self.version,
Expand All @@ -99,7 +99,7 @@ def create_links_message(self):
"request_invalid": request_invalid,
}

def create_message(self, stac_type: str, val_type: str) -> dict:
def create_message(self, stac_type: str, val_type: str) -> Dict:
return {
"version": self.version,
"path": self.stac_file,
Expand All @@ -109,7 +109,7 @@ def create_message(self, stac_type: str, val_type: str) -> dict:
"validation_method": val_type,
}

def assets_validator(self) -> dict:
def assets_validator(self) -> Dict:
"""Validate assets.

Returns:
Expand All @@ -122,7 +122,7 @@ def assets_validator(self) -> dict:
link_request(asset, initial_message)
return initial_message

def links_validator(self) -> dict:
def links_validator(self) -> Dict:
"""Validate links.

Returns:
Expand All @@ -143,7 +143,7 @@ def links_validator(self) -> dict:

return initial_message

def extensions_validator(self, stac_type: str) -> dict:
def extensions_validator(self, stac_type: str) -> Dict:
"""Validate the STAC extensions according to their corresponding JSON schemas.

Args:
Expand Down Expand Up @@ -253,7 +253,7 @@ def core_validator(self, stac_type: str) -> None:
self.schema = set_schema_addr(self.version, stac_type)
self.custom_validator()

def default_validator(self, stac_type: str) -> dict:
def default_validator(self, stac_type: str) -> Dict:
"""Validate the STAC catalog or item against the core schema and its extensions.

Args:
Expand Down Expand Up @@ -379,7 +379,7 @@ def validate_dict(self, stac_content) -> bool:
self.stac_content = stac_content
return self.run()

def validate_item_collection_dict(self, item_collection: dict) -> None:
def validate_item_collection_dict(self, item_collection: Dict) -> None:
"""Validate the contents of an item collection.

Args:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py37,py38,py39
envlist = py38,py39,py310,py311

[testenv]
deps = pytest
Expand Down
Loading