Skip to content

Commit

Permalink
pre-commit 1
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhealy1 committed Oct 9, 2024
1 parent 9145b27 commit fc9b7f2
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 255 deletions.
16 changes: 8 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'stac-check'
author = 'Jonathan Healy'
release = '1.3.1'
project = "stac-check"
author = "Jonathan Healy"
release = "1.3.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = []

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']
html_theme = "alabaster"
html_static_path = ["_static"]

html_css_files = [
'custom.css',
"custom.css",
]
60 changes: 36 additions & 24 deletions stac_check/cli.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import click
from .lint import Linter
import pkg_resources

def link_asset_message(link_list:list, type: str, format: str) -> None:
from .lint import Linter


def link_asset_message(link_list: list, type: str, format: str) -> None:
"""Prints a list of links or assets and any errors associated with them.
Args:
Expand All @@ -20,6 +22,7 @@ def link_asset_message(link_list:list, type: str, format: str) -> None:
else:
click.secho(f"No {type.upper()} {format} errors!", fg="green")


def recursive_message(linter: Linter) -> None:
"""Displays messages related to the recursive validation of assets in a collection or catalog.
Expand All @@ -36,18 +39,19 @@ def recursive_message(linter: Linter) -> None:
for count, msg in enumerate(linter.validate_all):
click.secho(f"Asset {count+1} Validated: {msg['path']}", bg="white", fg="black")
click.secho()
if msg['valid_stac'] == True:
if msg["valid_stac"] == True:
recursive_linter = Linter(msg["path"], recursive=0)
cli_message(recursive_linter)
else:
click.secho(f"Valid: {msg['valid_stac']}", fg='red')
click.secho(f"Valid: {msg['valid_stac']}", fg="red")
click.secho("Schemas validated: ", fg="blue")
for schema in msg["schema"]:
click.secho(f" {schema}")
click.secho(f"Error Type: {msg['error_type']}", fg='red')
click.secho(f"Error Message: {msg['error_message']}", fg='red')
click.secho(f"Error Type: {msg['error_type']}", fg="red")
click.secho(f"Error Message: {msg['error_message']}", fg="red")
click.secho("-------------------------")


def intro_message(linter: Linter) -> None:
"""Prints an introduction message for the stac-check tool.
Expand All @@ -63,64 +67,69 @@ def intro_message(linter: Linter) -> None:
Returns:
None.
"""
click.secho("""
click.secho(
"""
____ ____ __ ___ ___ _ _ ____ ___ __ _
/ ___)(_ _)/ _\ / __)___ / __)/ )( \( __)/ __)( / )
\___ \ )( / \( (__(___)( (__ ) __ ( ) _)( (__ ) (
(____/ (__)\_/\_/ \___) \___)\_)(_/(____)\___)(__\_)
""")
"""
)

click.secho("stac-check: STAC spec validaton and linting tool", bold=True)

click.secho()

if linter.version == "1.0.0":
click.secho(linter.set_update_message(), fg='green')
click.secho(linter.set_update_message(), fg="green")
else:
click.secho(linter.set_update_message(), fg='red')
click.secho(linter.set_update_message(), fg="red")

click.secho()

click.secho(f"Validator: stac-validator {linter.validator_version}", bg="blue", fg="white")
click.secho(
f"Validator: stac-validator {linter.validator_version}", bg="blue", fg="white"
)

click.secho()


def cli_message(linter: Linter) -> None:
"""Prints various messages about the STAC object being validated.
Args:
linter: The `Linter` object containing information about
linter: The `Linter` object containing information about
the STAC object to be validated.
Returns:
None
"""
if linter.valid_stac == True:
click.secho(f"Valid {linter.asset_type}: {linter.valid_stac}", fg='green')
click.secho(f"Valid {linter.asset_type}: {linter.valid_stac}", fg="green")
else:
click.secho(f"Valid {linter.asset_type}: {linter.valid_stac}", fg='red')
click.secho(f"Valid {linter.asset_type}: {linter.valid_stac}", fg="red")

''' schemas validated for core object '''
""" schemas validated for core object """
click.secho()
if len(linter.schema) > 0:
click.secho("Schemas validated: ", fg="blue")
for schema in linter.schema:
click.secho(f" {schema}")

''' best practices message'''
""" best practices message"""
click.secho()
for message in linter.best_practices_msg:
if message == linter.best_practices_msg[0]:
click.secho(message, bg='blue')
click.secho(message, bg="blue")
else:
click.secho(message, fg='red')
click.secho(message, fg="red")

if linter.validate_all == True:
click.secho()
click.secho(f"Recursive validation has passed!", fg='blue')
click.secho(f"Recursive validation has passed!", fg="blue")
elif linter.validate_all == False and linter.recursive:
click.secho()
click.secho(f"Recursive validation has failed!", fg='red')
click.secho(f"Recursive validation has failed!", fg="red")

if linter.invalid_asset_format is not None:
click.secho()
Expand All @@ -143,7 +152,7 @@ def cli_message(linter: Linter) -> None:
click.secho(f" {linter.error_type}")

if linter.error_msg != "":
click.secho(f"Validation error message: ", fg='red')
click.secho(f"Validation error message: ", fg="red")
click.secho(f" {linter.error_msg}")

click.secho(f"This object has {len(linter.data['links'])} links")
Expand All @@ -153,6 +162,7 @@ def cli_message(linter: Linter) -> None:
### Stac validator response for reference
# click.secho(json.dumps(linter.message, indent=4))


@click.option(
"--recursive",
"-r",
Expand All @@ -172,12 +182,14 @@ def cli_message(linter: Linter) -> None:
"-l", "--links", is_flag=True, help="Validate links for format and response."
)
@click.command()
@click.argument('file')
@click.argument("file")
@click.version_option(version=pkg_resources.require("stac-check")[0].version)
def main(file, recursive, max_depth, assets, links):
linter = Linter(file, assets=assets, links=links, recursive=recursive, max_depth=max_depth)
linter = Linter(
file, assets=assets, links=links, recursive=recursive, max_depth=max_depth
)
intro_message(linter)
if recursive > 0:
recursive_message(linter)
else:
cli_message(linter)
cli_message(linter)
Loading

0 comments on commit fc9b7f2

Please sign in to comment.