Skip to content

Commit

Permalink
Merge pull request #201 from stac-utils/integrate_check
Browse files Browse the repository at this point in the history
Push stac-check linting messages into stac-validator messaging format
  • Loading branch information
jonhealy1 authored Mar 15, 2022
2 parents e42fb33 + c444d92 commit 324cfae
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 32 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)

## Unreleased - 2022-03-14

### Added

- Added core linting messages from stac-check to stac-validator messages https://github.com/stac-utils/stac-validator/pull/201/

### Fixed

- Reordered exception handlers to avoid unreachable code
- Details about invalid items is shown in the message when in recursive mode
- Reordered exception handlers to avoid unreachable code https://github.com/stac-utils/stac-validator/pull/203/
- Details about invalid items are shown in the message when in recursive mode https://github.com/stac-utils/stac-validator/pull/202/
- Dockerfile - change cli command from stac_validator to stac-validator https://github.com/stac-utils/stac-validator/pull/201/

## [v3.0.0] - 2022-03-11

Expand Down
49 changes: 42 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).

```bash
stac_validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json
[
{
"version": "1.0.0",
Expand Down Expand Up @@ -130,8 +130,8 @@ Options:
The validator can run using docker containers.
```bash
docker build -t stac_validator:2.2.0 .
docker run stac_validator:2.2.0 https://raw.githubusercontent.com/stac-extensions/projection/main/examples/item.json
docker build -t stac-validator .
docker run stac-validator https://raw.githubusercontent.com/stac-extensions/projection/main/examples/item.json
[
{
"version": "1.0.0",
Expand Down Expand Up @@ -221,7 +221,7 @@ See the [tests](./tests/test_stac_validator.py) files for examples on different
**--core**
```bash
stac_validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --core
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --core
[
{
"version": "1.0.0",
Expand All @@ -239,7 +239,7 @@ stac_validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
**--custom**
```bash
stac_validator https://radarstac.s3.amazonaws.com/stac/catalog.json --custom https://cdn.staclint.com/v0.7.0/catalog.json
stac-validator https://radarstac.s3.amazonaws.com/stac/catalog.json --custom https://cdn.staclint.com/v0.7.0/catalog.json
[
{
"version": "0.7.0",
Expand All @@ -257,7 +257,7 @@ stac_validator https://radarstac.s3.amazonaws.com/stac/catalog.json --custom htt
**--extensions**
```bash
stac_validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --extensions
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --extensions
[
{
"version": "1.0.0",
Expand All @@ -276,10 +276,45 @@ stac_validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
]
```
**--lint**
```bash
stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json --lint
[
{
"version": "1.0.0",
"path": "https://raw.githubusercontent.com/radiantearth/stac-spec/master/examples/extended-item.json",
"schema": [
"https://stac-extensions.github.io/eo/v1.0.0/schema.json",
"https://stac-extensions.github.io/projection/v1.0.0/schema.json",
"https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
"https://stac-extensions.github.io/view/v1.0.0/schema.json",
"https://stac-extensions.github.io/remote-data/v1.0.0/schema.json",
"https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
],
"valid_stac": true,
"asset_type": "ITEM",
"validation_method": "default",
"linting": {
"searchable_identifiers": [
"Item name '20201211_223832_CS2' should only contain Searchable identifiers",
"Identifiers should consist of only lowercase characters, numbers, '_', and '-'"
],
"check_item_id": [
"Item file names should match their ids: 'extended-item' not equal to '20201211_223832_CS2"
],
"bloated_metadata": [
"You have 21 properties. Please consider using links to avoid bloated metadata"
]
}
}
]
```
**--recursive**
```bash
stac_validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --verbose
stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursive --max-depth 1 --verbose
[
{
"version": "0.8.1",
Expand Down
13 changes: 13 additions & 0 deletions stac_validator/lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from stac_check.lint import Linter # type: ignore


class StacCheck:
def __init__(
self,
stac_file: str = None,
):
self.stac_file = stac_file

def lint_message(self):
linter = Linter(self.stac_file)
return linter.create_best_practices_dict()
47 changes: 24 additions & 23 deletions stac_validator/stac_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
import sys

import click # type: ignore
from stac_check.cli import cli_message as lint_message # type: ignore
from stac_check.lint import Linter # type: ignore

from .lint import StacCheck
from .validate import StacValidate


Expand All @@ -13,7 +12,7 @@
@click.option(
"--lint",
is_flag=True,
help="Use stac-check to lint the stac object in addition to validating it.",
help="Use stac-check to lint the stac object in addition to validating it. Not presently implemented with --recursive.",
)
@click.option(
"--core", is_flag=True, help="Validate core stac object only without extensions."
Expand Down Expand Up @@ -73,27 +72,29 @@ def main(
):

valid = True
if lint is True:
linter = Linter(stac_file, assets=True, links=True, recursive=False)
lint_message(linter)
else:
stac = StacValidate(
stac_file=stac_file,
recursive=recursive,
max_depth=max_depth,
core=core,
links=links,
assets=assets,
extensions=extensions,
custom=custom,
verbose=verbose,
no_output=no_output,
log=log_file,
)
valid = stac.run()
stac = StacValidate(
stac_file=stac_file,
recursive=recursive,
max_depth=max_depth,
core=core,
links=links,
assets=assets,
extensions=extensions,
custom=custom,
verbose=verbose,
no_output=no_output,
log=log_file,
)
valid = stac.run()

if no_output is False:
click.echo(json.dumps(stac.message, indent=4))
message = stac.message

if lint and not recursive:
linter = StacCheck(stac_file=stac_file)
message[0]["linting"] = linter.lint_message()

if no_output is False:
click.echo(json.dumps(message, indent=4))

sys.exit(0 if valid else 1)

Expand Down

0 comments on commit 324cfae

Please sign in to comment.