Skip to content
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
32 changes: 32 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
minimum_pre_commit_version: 1.15.0
default_language_version:
python: python3.6
repos:
-
repo: 'https://github.com/ambv/black'
rev: 19.3b0
hooks:
- id: black
name: Black
exclude: templates/
args: ['--safe', '-l 100', '.']

-
repo: 'https://github.com/timothycrosley/isort.git'
rev: 4.3.21
hooks:
- id: isort
name: Sort Imports
exclude: templates/
args: ['-rc', '-m 3', '-tc', '-w 100', '-e']
-
repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: debug-statements
- id: check-merge-conflict
- id: check-docstring-first
language_version: python3.6
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
install:
pip install .

code-check:
pre-commit run --all-files

test:
pytest --mypy --cov --cov-report=html --verbose
1 change: 0 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@

"""
__author__ = "James Banting"

4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
requests>=2.19.1
pytest>=3.8.0
pytest-mypy==0.4.2
pytest-cov==2.8.1
docopt>=0.6.2
jsonschema>=3.0.1

pystac==0.3.3
6 changes: 2 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
setup(
name="stac_validator",
version=__version__,
author="James Banting",
author="James Banting, Darren Wiens",
author_email="jbanting@sparkgeo.com",
description="A package to validate STAC files",
license="MIT",
Expand All @@ -36,8 +36,6 @@
url="https://github.com/sparkgeo/stac-validator",
install_requires=requires,
packages=["stac_validator"],
entry_points={
"console_scripts": ["stac_validator = stac_validator.stac_validator:main"]
},
entry_points={"console_scripts": ["stac_validator = stac_validator.stac_validator:main"]},
tests_require=["pytest"],
)
31 changes: 30 additions & 1 deletion stac_validator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,30 @@
__version__ = '0.0.2'
__version__ = "0.0.2"
import boto3
import json
import urllib.request
from urllib.parse import urlparse
from pystac import STAC_IO


def read_remote_stacs(uri):
"""
Reads STACs from a remote location. To be used to set STAC_IO
Defaults to local storage.
"""
parsed = urlparse(uri)
if parsed.scheme == "s3":
bucket = parsed.netloc
key = parsed.path[1:]
s3 = boto3.resource("s3")
obj = s3.Object(bucket, key)
return obj.get()["Body"].read().decode("utf-8")
if parsed.scheme in ["http", "https"]:
with urllib.request.urlopen(uri) as url:
stac = url.read().decode()
return stac
else:
return STAC_IO.default_read_text_method(uri)

STAC_IO.read_text_method = read_remote_stacs

from . import stac_validator
20 changes: 15 additions & 5 deletions stac_validator/stac_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,24 @@ def _determine_verison(self):
self.COLLECTION_URL = os.path.join(cdn_base_url, self.filename)
else:
if self.version in old_versions:
self.CATALOG_URL = os.path.join(git_base_url, f"static-catalog/{self.input_type}/{self.filename}")
self.ITEM_URL = os.path.join(git_base_url, f"json-spec/{self.input_type}/{self.filename}")
self.CATALOG_URL = os.path.join(
git_base_url, f"static-catalog/{self.input_type}/{self.filename}"
)
self.ITEM_URL = os.path.join(
git_base_url, f"json-spec/{self.input_type}/{self.filename}"
)

else:

self.CATALOG_URL = os.path.join(git_base_url, f"catalog-spec/{self.input_type}/{self.filename}")
self.COLLECTION_URL = os.path.join(git_base_url, f"collection-spec/{self.input_type}/{self.filename}")
self.ITEM_URL = os.path.join(git_base_url, f"item-spec/{self.input_type}/{self.filename}")
self.CATALOG_URL = os.path.join(
git_base_url, f"catalog-spec/{self.input_type}/{self.filename}"
)
self.COLLECTION_URL = os.path.join(
git_base_url, f"collection-spec/{self.input_type}/{self.filename}"
)
self.ITEM_URL = os.path.join(
git_base_url, f"item-spec/{self.input_type}/{self.filename}"
)

@staticmethod
def fix_stac_item(version, filename):
Expand Down
Loading