[Git][debian-gis-team/stac-validator][upstream] New upstream version 3.4.0+ds

Antonio Valentino (@antonio.valentino) gitlab at salsa.debian.org
Sun Oct 13 19:32:35 BST 2024



Antonio Valentino pushed to branch upstream at Debian GIS Project / stac-validator


Commits:
c1f82c57 by Antonio Valentino at 2024-10-13T17:43:16+00:00
New upstream version 3.4.0+ds
- - - - -


17 changed files:

- .github/workflows/test-runner.yml
- .pre-commit-config.yaml
- CHANGELOG.md
- README.md
- docs/conf.py
- setup.py
- stac_validator/stac_validator.py
- stac_validator/utilities.py
- stac_validator/validate.py
- tests/test_assets.py
- tests/test_core.py
- + tests/test_data/v110/collection.json
- + tests/test_data/v110/simple-item.json
- + tests/test_validate_collections.py
- tests/test_validate_dict.py
- tests/test_validate_item_collection.py
- tox.ini


Changes:

=====================================
.github/workflows/test-runner.yml
=====================================
@@ -11,17 +11,14 @@ on:
       - dev
 
 jobs:
-
   test:
-
     name: Execute tests
     runs-on: ubuntu-latest
     strategy:
       matrix:
         python-version: ["3.8", "3.9", "3.10", "3.11"]
-    
-    steps:
 
+    steps:
       - uses: actions/checkout at v2
       - name: Set up Python ${{ matrix.python-version }}
         uses: actions/setup-python at main
@@ -35,7 +32,7 @@ jobs:
           pytest --mypy stac_validator
 
       - name: Run pre-commit
-        if: matrix.python-version == 3.8
+        if: matrix.python-version == 3.10
         run: |
           pre-commit install
           pre-commit autoupdate


=====================================
.pre-commit-config.yaml
=====================================
@@ -1,15 +1,29 @@
 repos:
--   repo: https://github.com/PyCQA/flake8
-    rev: 3.9.1
+  - repo: https://github.com/PyCQA/flake8
+    rev: 7.0.0
     hooks:
-    - id: flake8
--   repo: https://github.com/timothycrosley/isort
-    rev: 5.11.5
+      - id: flake8
+  - repo: https://github.com/timothycrosley/isort
+    rev: 5.13.2
     hooks:
-    - id: isort
-      args: ["--profile", "black"]
--   repo: https://github.com/psf/black
-    rev: 22.3.0
+      - id: isort
+        args: ["--profile", "black"]
+  - repo: https://github.com/psf/black
+    rev: 24.1.1
     hooks:
-    - id: black
-      language_version: python3.8
\ No newline at end of file
+      - id: black
+        language_version: python3.10
+  - repo: https://github.com/pre-commit/mirrors-mypy
+    rev: v1.8.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"]


=====================================
CHANGELOG.md
=====================================
@@ -6,13 +6,21 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
 
 ## [Unreleased]
 
+## [v3.4.0] - 2024-10-08
+
+### Added
+
+- Added ability to validate response from a /collections endpoint [#220](https://github.com/stac-utils/stac-validator/issues/220)
+- Added mypy to pre-commit config ([#229](https://github.com/stac-utils/stac-validator/pull/224))
+- Support for stac spec version 1.1.0 [#235](https://github.com/stac-utils/stac-validator/pull/235)
+
 ## [v3.3.2] - 2023-11-17
 
 ### Added
 
 - Docstrings ([#224](https://github.com/stac-utils/stac-validator/pull/224))
 
-### Changed 
+### Changed
 
 - Development dependencies removed from runtime dependency list
   ([#228](https://github.com/stac-utils/stac-check/pull/109))
@@ -33,13 +41,13 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
 
 ## [v3.2.0] - 2022-09-20
 
-### Added  
-  
+### Added
+
 - Added ability to check local schemas in item extensions https://github.com/stac-utils/stac-validator/pull/215
 - Added an example on validating a dictionary https://github.com/stac-utils/stac-validator/pull/215
 
 ### Changed
-  
+
 - Changed 'ValidationError' error type to 'JSONSchemaValidationError' https://github.com/stac-utils/stac-validator/pull/213
 
 ## [v3.1.0] - 2022-04-28
@@ -78,32 +86,38 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
 - References to Python 3.6
 
 ## [v2.5.0] - 2022-03-10
+
 ### Changed
 
 - Split the `--recursive` option into a `--recursive` flag and a `--max-depth` option
 - Renamed the entry point from `stac_validator` to `stac-validator`
 
 ## [v2.4.3] - 2022-03-10
+
 ### Changed
 
- - Add schema caching
+- Add schema caching
 
 ## [v2.4.2] - 2022-03-02
+
 ### Changed
 
- - Loosen pystac version dependency
+- Loosen pystac version dependency
 
 ## [v2.4.1] - 2022-03-02
+
 ### Changed
 
- - Loosen stac-check version dependency
+- Loosen stac-check version dependency
 
 ## [v2.4.0] - 2022-02-02
+
 ### Added
 
- - Linting option in cli to display stac-check generated information
+- Linting option in cli to display stac-check generated information
 
 ## [v2.3.0] - 2021-08-31 - 2021-11-28
+
 ### Added
 
 - Added --links option to validate links on format and a valid response
@@ -120,6 +134,7 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
 - Moved backend to validate.py
 
 ## [v2.2.0] - 2021-05-25
+
 ### Added
 
 - Added Support for STAC 1.0.0
@@ -128,17 +143,18 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
 
 ### Changed
 
-- Moved std out to cli so that it doesn't display in pure python applications 
-- Added Pypi badges to readme 
-  
+- Moved std out to cli so that it doesn't display in pure python applications
+- Added Pypi badges to readme
+
 ## [v2.1.0] - 2021-05-06
+
 ### Added
 
 - Added more tests for STAC 1.0.0-rc.3
 - Added basic support for rc.4
 - Add system exit code to CLI. see #144
 
-### Changed 
+### Changed
 
 - Modified how Lambda CDK is built
 
@@ -155,7 +171,7 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
 
 ### Changed
 
-- Pystac is now only being used to identify stac objects. Jsonschema is being used for all other validation.  
+- Pystac is now only being used to identify stac objects. Jsonschema is being used for all other validation.
 - The cli library was changed from Docopt to Click.
 - Custom validation was updated to allow for local schemas.
 
@@ -191,24 +207,25 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
 - With the newest version - 1.0.0-beta.2 - items will run through jsonchema validation before the PySTAC validation. The reason for this is that jsonschema will give more informative error messages. This should be addressed better in the future. This is not the case with the --recursive option as time can be a concern here with larger collections.
 - Logging. Various additions were made here depending on the options selected. This was done to help assist people to update their STAC collections.
 
-[Unreleased]: <https://github.com/sparkgeo/stac-validator/compare/v3.3.2..main>
-[v3.3.2]: <https://github.com/sparkgeo/stac-validator/compare/v3.3.1..v3.3.2>
-[v3.3.1]: <https://github.com/sparkgeo/stac-validator/compare/v3.3.0..v3.3.1>
-[v3.3.0]: <https://github.com/sparkgeo/stac-validator/compare/v3.2.0..v3.3.0>
-[v3.2.0]: <https://github.com/sparkgeo/stac-validator/compare/v3.1.0..v3.2.0>
-[v3.1.0]: <https://github.com/sparkgeo/stac-validator/compare/v3.0.0..v3.1.0>
-[v3.0.0]: <https://github.com/sparkgeo/stac-validator/compare/v2.5.0..v3.0.0>
-[v2.5.0]: <https://github.com/sparkgeo/stac-validator/compare/v2.4.3..v2.5.0>
-[v2.4.3]: <https://github.com/sparkgeo/stac-validator/compare/v2.3.0..v2.4.0>
-[v2.4.2]: <https://github.com/sparkgeo/stac-validator/compare/v2.4.1..v2.4.2>
-[v2.4.1]: <https://github.com/sparkgeo/stac-validator/compare/v2.4.0..v2.4.1>
-[v2.4.0]: <https://github.com/sparkgeo/stac-validator/compare/v2.3.0..v2.4.0>
-[v2.3.0]: <https://github.com/sparkgeo/stac-validator/compare/v2.2.0..v2.3.0>
-[v2.2.0]: <https://github.com/sparkgeo/stac-validator/compare/v2.1.0..v2.2.0>
-[v2.1.0]: <https://github.com/sparkgeo/stac-validator/compare/v2.0.0..v2.1.0>
-[v2.0.0]: <https://github.com/sparkgeo/stac-validator/compare/v1.0.1..v2.0.0>
-[v1.0.1]: <https://github.com/sparkgeo/stac-validator/compare/v0.5.0..v1.0.1>
-[v0.5.0]: <https://github.com/sparkgeo/stac-validator/compare/v0.1.3..v0.5.0>
-[v0.1.3]: <https://github.com/sparkgeo/stac-validator/compare/v0.1.1..v0.1.3>
-[v0.1.1]: <https://github.com/sparkgeo/stac-validator/compare/v0.1.0..v0.1.1>
-[v0.1.0]: <https://github.com/sparkgeo/stac-validator/releases/tag/v0.1.0>
+[Unreleased]: https://github.com/sparkgeo/stac-validator/compare/v3.4.0..main
+[v3.4.0]: https://github.com/sparkgeo/stac-validator/compare/v3.3.2..v3.4.0
+[v3.3.2]: https://github.com/sparkgeo/stac-validator/compare/v3.3.1..v3.3.2
+[v3.3.1]: https://github.com/sparkgeo/stac-validator/compare/v3.3.0..v3.3.1
+[v3.3.0]: https://github.com/sparkgeo/stac-validator/compare/v3.2.0..v3.3.0
+[v3.2.0]: https://github.com/sparkgeo/stac-validator/compare/v3.1.0..v3.2.0
+[v3.1.0]: https://github.com/sparkgeo/stac-validator/compare/v3.0.0..v3.1.0
+[v3.0.0]: https://github.com/sparkgeo/stac-validator/compare/v2.5.0..v3.0.0
+[v2.5.0]: https://github.com/sparkgeo/stac-validator/compare/v2.4.3..v2.5.0
+[v2.4.3]: https://github.com/sparkgeo/stac-validator/compare/v2.3.0..v2.4.0
+[v2.4.2]: https://github.com/sparkgeo/stac-validator/compare/v2.4.1..v2.4.2
+[v2.4.1]: https://github.com/sparkgeo/stac-validator/compare/v2.4.0..v2.4.1
+[v2.4.0]: https://github.com/sparkgeo/stac-validator/compare/v2.3.0..v2.4.0
+[v2.3.0]: https://github.com/sparkgeo/stac-validator/compare/v2.2.0..v2.3.0
+[v2.2.0]: https://github.com/sparkgeo/stac-validator/compare/v2.1.0..v2.2.0
+[v2.1.0]: https://github.com/sparkgeo/stac-validator/compare/v2.0.0..v2.1.0
+[v2.0.0]: https://github.com/sparkgeo/stac-validator/compare/v1.0.1..v2.0.0
+[v1.0.1]: https://github.com/sparkgeo/stac-validator/compare/v0.5.0..v1.0.1
+[v0.5.0]: https://github.com/sparkgeo/stac-validator/compare/v0.1.3..v0.5.0
+[v0.1.3]: https://github.com/sparkgeo/stac-validator/compare/v0.1.1..v0.1.3
+[v0.1.1]: https://github.com/sparkgeo/stac-validator/compare/v0.1.0..v0.1.1
+[v0.1.0]: https://github.com/sparkgeo/stac-validator/releases/tag/v0.1.0


=====================================
README.md
=====================================
@@ -4,10 +4,7 @@
 
 [read the docs](https://stac-validator.readthedocs.io/en/latest/)
 
-
-## Validate STAC json files against the [STAC spec](https://github.com/radiantearth/stac-spec).   
-    
-
+## 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
@@ -32,10 +29,9 @@ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
 
 ## Requirements
 
-- Python 3.7+
+- Python 3.8+
   - Requests
   - Click
-  - Pytest
   - Jsonschema
 
 Note: Stac-validator is also used in stac-check which adds linting messages based on the official STAC best practices document.  
@@ -61,7 +57,6 @@ or for local development
 pip install -e '.[dev]'
 ```
 
-
 The [Makefile](./Makefile) has convenience commands if Make is installed.
 
 ```bash
@@ -82,7 +77,8 @@ make help
 | 1.0.0-rc.3   |
 | 1.0.0-rc.4   |
 | 1.0.0        |
-
+| 1.1.0-beta.1 |
+| 1.1.0        |
 
 ---
 
@@ -107,6 +103,7 @@ Options:
   -m, --max-depth INTEGER  Maximum depth to traverse when recursing. Omit this
                            argument to get full recursion. Ignored if
                            `recursive == False`.
+  --collections            Validate /collections response.
   --item-collection        Validate item collection response. Can be combined
                            with --pages. Defaults to one page.
   -p, --pages INTEGER      Maximum number of pages to validate via --item-
@@ -146,7 +143,9 @@ docker run stac-validator https://raw.githubusercontent.com/stac-extensions/proj
 ```
 
 ## AWS (CDK)
+
 An example [AWS CDK](https://aws.amazon.com/cdk/) deployment is available in [cdk-deployment](./cdk-deployment/README.md)
+
 ```bash
 cd cdk-deployment
 cdk diff
@@ -201,29 +200,29 @@ print(stac.message)
 ```
 
 **Dictionary**
-  
+
 ```python
 from stac_validator import stac_validator
-  
+
 stac = stac_validator.StacValidate()
 stac.validate_dict(dictionary)
 print(stac.message)
 ```
 
 **Item Collection**
-  
+
 ```python
 from stac_validator import stac_validator
-  
+
 stac = stac_validator.StacValidate()
 stac.validate_item_collection_dict(item_collection_dict)
 print(stac.message)
 ```
+
 ---
 
 # Testing
 
-
 ```bash
 make test
 # or
@@ -233,6 +232,7 @@ pytest -v
 See the [tests](./tests/test_stac_validator.py) files for examples on different usages.
 
 ---
+
 # Additional Examples
 
 **--core**
@@ -292,7 +292,7 @@ stac-validator https://raw.githubusercontent.com/radiantearth/stac-spec/master/e
     }
 ]
 ```
-   
+
 **--recursive**
 
 ```bash
@@ -324,8 +324,9 @@ stac-validator https://spot-canada-ortho.s3.amazonaws.com/catalog.json --recursi
     }
 ]
 ```
+
 **--item-collection**
 
 ```bash
 stac-validator https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l2a/items --item-collection --pages 2
-```
\ No newline at end of file
+```


=====================================
docs/conf.py
=====================================
@@ -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,
@@ -30,7 +32,7 @@ release = "3.3.1"
 # 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"]


=====================================
setup.py
=====================================
@@ -2,7 +2,7 @@
 
 from setuptools import setup
 
-__version__ = "3.3.2"
+__version__ = "3.4.0"
 
 with open("README.md", "r") as fh:
     long_description = fh.read()
@@ -11,14 +11,14 @@ setup(
     name="stac_validator",
     version=__version__,
     author="James Banting, Jonathan Healy",
-    author_email="jhealy at sparkgeo.com",
+    author_email="jonathan.d.healy at gmail.com",
     description="A package to validate STAC files",
     license="Apache-2.0",
     classifiers=[
         "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",


=====================================
stac_validator/stac_validator.py
=====================================
@@ -18,12 +18,12 @@ def print_update_message(version: str) -> None:
         None
     """
     click.secho()
-    if version != "1.0.0":
+    if version != "1.1.0":
         click.secho(
-            f"Please upgrade from version {version} to version 1.0.0!", fg="red"
+            f"Please upgrade from version {version} to version 1.1.0!", fg="red"
         )
     else:
-        click.secho("Thanks for using STAC version 1.0.0!", fg="green")
+        click.secho("Thanks for using STAC version 1.1.0!", fg="green")
     click.secho()
 
 
@@ -46,6 +46,25 @@ def item_collection_summary(message: List[Dict[str, Any]]) -> None:
     click.secho(f"valid_items: {valid_count}")
 
 
+def collections_summary(message: List[Dict[str, Any]]) -> None:
+    """Prints a summary of the validation results for an item collection response.
+
+    Args:
+        message (List[Dict[str, Any]]): The validation results for the item collection.
+
+    Returns:
+        None
+    """
+    valid_count = 0
+    for collection in message:
+        if "valid_stac" in collection and collection["valid_stac"] is True:
+            valid_count = valid_count + 1
+    click.secho()
+    click.secho("--collections summary", bold=True)
+    click.secho(f"collections_validated: {len(message)}")
+    click.secho(f"valid_collections: {valid_count}")
+
+
 @click.command()
 @click.argument("stac_file")
 @click.option(
@@ -80,6 +99,11 @@ def item_collection_summary(message: List[Dict[str, Any]]) -> None:
     type=int,
     help="Maximum depth to traverse when recursing. Omit this argument to get full recursion. Ignored if `recursive == False`.",
 )
+ at click.option(
+    "--collections",
+    is_flag=True,
+    help="Validate /collections response.",
+)
 @click.option(
     "--item-collection",
     is_flag=True,
@@ -102,6 +126,7 @@ def item_collection_summary(message: List[Dict[str, Any]]) -> None:
 )
 def main(
     stac_file: str,
+    collections: bool,
     item_collection: bool,
     pages: int,
     recursive: bool,
@@ -120,6 +145,7 @@ def main(
 
     Args:
         stac_file (str): Path to the STAC file to be validated.
+        collections (bool): Validate response from /collections endpoint.
         item_collection (bool): Whether to validate item collection responses.
         pages (int): Maximum number of pages to validate via `item_collection`.
         recursive (bool): Whether to recursively validate all related STAC objects.
@@ -143,6 +169,7 @@ def main(
     valid = True
     stac = StacValidate(
         stac_file=stac_file,
+        collections=collections,
         item_collection=item_collection,
         pages=pages,
         recursive=recursive,
@@ -155,8 +182,10 @@ def main(
         verbose=verbose,
         log=log_file,
     )
-    if not item_collection:
+    if not item_collection and not collections:
         valid = stac.run()
+    elif collections:
+        stac.validate_collections()
     else:
         stac.validate_item_collection()
 
@@ -169,6 +198,8 @@ def main(
 
     if item_collection:
         item_collection_summary(message)
+    elif collections:
+        collections_summary(message)
 
     sys.exit(0 if valid else 1)
 


=====================================
stac_validator/utilities.py
=====================================
@@ -1,6 +1,7 @@
 import functools
 import json
 import ssl
+from typing import Dict
 from urllib.parse import urlparse
 from urllib.request import urlopen
 
@@ -13,6 +14,8 @@ NEW_VERSIONS = [
     "1.0.0-rc.3",
     "1.0.0-rc.4",
     "1.0.0",
+    "1.1.0-beta.1",
+    "1.1.0",
 ]
 
 
@@ -44,7 +47,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
@@ -74,7 +77,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,
@@ -107,7 +110,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
@@ -147,8 +150,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.
 


=====================================
stac_validator/validate.py
=====================================
@@ -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
@@ -25,6 +25,7 @@ class StacValidate:
 
     Attributes:
         stac_file (str): The path or URL to the STAC object to be validated.
+        collections (bool): Validate response from a /collections endpoint.
         item_collection (bool): Whether the STAC object to be validated is an item collection.
         pages (int): The maximum number of pages to validate if `item_collection` is True.
         recursive (bool): Whether to recursively validate related STAC objects.
@@ -45,6 +46,7 @@ class StacValidate:
     def __init__(
         self,
         stac_file: Optional[str] = None,
+        collections: bool = False,
         item_collection: bool = False,
         pages: Optional[int] = None,
         recursive: bool = False,
@@ -58,9 +60,10 @@ class StacValidate:
         log: str = "",
     ):
         self.stac_file = stac_file
+        self.collections = collections
         self.item_collection = item_collection
         self.pages = pages
-        self.message: list = []
+        self.message: List = []
         self.schema = custom
         self.links = links
         self.assets = assets
@@ -68,7 +71,7 @@ class StacValidate:
         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
@@ -76,7 +79,7 @@ class StacValidate:
         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,
@@ -99,7 +102,7 @@ class StacValidate:
             "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,
@@ -109,7 +112,7 @@ class StacValidate:
             "validation_method": val_type,
         }
 
-    def assets_validator(self) -> dict:
+    def assets_validator(self) -> Dict:
         """Validate assets.
 
         Returns:
@@ -122,7 +125,7 @@ class StacValidate:
                 link_request(asset, initial_message)
         return initial_message
 
-    def links_validator(self) -> dict:
+    def links_validator(self) -> Dict:
         """Validate links.
 
         Returns:
@@ -143,7 +146,7 @@ class StacValidate:
 
         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:
@@ -253,7 +256,7 @@ class StacValidate:
         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:
@@ -379,7 +382,7 @@ class StacValidate:
         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:
@@ -392,6 +395,27 @@ class StacValidate:
             self.schema = ""
             self.validate_dict(item)
 
+    def validate_collections(self) -> None:
+        """ "Validate STAC collections from a /collections endpoint.
+
+        Raises:
+            URLError: If there is an issue with the URL used to fetch the item collection.
+            JSONDecodeError: If the item collection content cannot be parsed as JSON.
+            ValueError: If the item collection does not conform to the STAC specification.
+            TypeError: If the item collection content is not a dictionary or JSON object.
+            FileNotFoundError: If the item collection file cannot be found.
+            ConnectionError: If there is an issue with the internet connection used to fetch the item collection.
+            exceptions.SSLError: If there is an issue with the SSL connection used to fetch the item collection.
+            OSError: If there is an issue with the file system (e.g., read/write permissions) while trying to write to the log file.
+
+        Returns:
+            None
+        """
+        collections = fetch_and_parse_file(str(self.stac_file))
+        for collection in collections["collections"]:
+            self.schema = ""
+            self.validate_dict(collection)
+
     def validate_item_collection(self) -> None:
         """Validate a STAC item collection.
 
@@ -429,9 +453,9 @@ class StacValidate:
                                 break
         except Exception as e:
             message = {}
-            message[
-                "pagination_error"
-            ] = f"Validating the item collection failed on page {page}: {str(e)}"
+            message["pagination_error"] = (
+                f"Validating the item collection failed on page {page}: {str(e)}"
+            )
             self.message.append(message)
 
     def run(self) -> bool:
@@ -457,7 +481,11 @@ class StacValidate:
         """
         message = {}
         try:
-            if self.stac_file is not None and not self.item_collection:
+            if (
+                self.stac_file is not None
+                and not self.item_collection
+                and not self.collections
+            ):
                 self.stac_content = fetch_and_parse_file(self.stac_file)
 
             stac_type = get_stac_type(self.stac_content).upper()


=====================================
tests/test_assets.py
=====================================
@@ -34,10 +34,9 @@ def test_assets_v090():
                     "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND8.tif",
                 ],
                 "format_invalid": [],
-                "request_valid": [
-                    "https://s3.amazonaws.com/cbers-meta-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106.jpg"
-                ],
+                "request_valid": [],
                 "request_invalid": [
+                    "https://s3.amazonaws.com/cbers-meta-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106.jpg",
                     "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND6.xml",
                     "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND5.tif",
                     "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND6.tif",


=====================================
tests/test_core.py
=====================================
@@ -174,3 +174,39 @@ def test_core_item_local_v100():
             "validation_method": "core",
         }
     ]
+
+
+def test_core_collection_local_v110():
+    stac_file = "tests/test_data/v110/collection.json"
+    stac = stac_validator.StacValidate(stac_file, core=True)
+    stac.run()
+    assert stac.message == [
+        {
+            "version": "1.1.0",
+            "path": "tests/test_data/v110/collection.json",
+            "schema": [
+                "https://schemas.stacspec.org/v1.1.0/collection-spec/json-schema/collection.json"
+            ],
+            "valid_stac": True,
+            "asset_type": "COLLECTION",
+            "validation_method": "core",
+        }
+    ]
+
+
+def test_core_item_local_v110():
+    stac_file = "tests/test_data/v110/simple-item.json"
+    stac = stac_validator.StacValidate(stac_file, core=True)
+    stac.run()
+    assert stac.message == [
+        {
+            "version": "1.1.0",
+            "path": "tests/test_data/v110/simple-item.json",
+            "schema": [
+                "https://schemas.stacspec.org/v1.1.0/item-spec/json-schema/item.json"
+            ],
+            "valid_stac": True,
+            "asset_type": "ITEM",
+            "validation_method": "core",
+        }
+    ]


=====================================
tests/test_data/v110/collection.json
=====================================
@@ -0,0 +1,112 @@
+{
+  "id": "simple-collection",
+  "type": "Collection",
+  "stac_extensions": [
+    "https://stac-extensions.github.io/eo/v2.0.0/schema.json",
+    "https://stac-extensions.github.io/projection/v2.0.0/schema.json",
+    "https://stac-extensions.github.io/view/v1.0.0/schema.json"
+  ],
+  "stac_version": "1.1.0",
+  "description": "A simple collection demonstrating core catalog fields with links to a couple of items",
+  "title": "Simple Example Collection",
+  "keywords": ["simple", "example", "collection"],
+  "providers": [
+    {
+      "name": "Remote Data, Inc",
+      "description": "Producers of awesome spatiotemporal assets",
+      "roles": ["producer", "processor"],
+      "url": "http://remotedata.io"
+    }
+  ],
+  "extent": {
+    "spatial": {
+      "bbox": [
+        [
+          172.91173669923782, 1.3438851951615003, 172.95469614953714,
+          1.3690476620161975
+        ]
+      ]
+    },
+    "temporal": {
+      "interval": [["2020-12-11T22:38:32.125Z", "2020-12-14T18:02:31.437Z"]]
+    }
+  },
+  "license": "CC-BY-4.0",
+  "summaries": {
+    "platform": ["cool_sat1", "cool_sat2"],
+    "constellation": ["ion"],
+    "instruments": ["cool_sensor_v1", "cool_sensor_v2"],
+    "gsd": {
+      "minimum": 0.512,
+      "maximum": 0.66
+    },
+    "eo:cloud_cover": {
+      "minimum": 1.2,
+      "maximum": 1.2
+    },
+    "proj:cpde": ["EPSG:32659"],
+    "view:sun_elevation": {
+      "minimum": 54.9,
+      "maximum": 54.9
+    },
+    "view:off_nadir": {
+      "minimum": 3.8,
+      "maximum": 3.8
+    },
+    "view:sun_azimuth": {
+      "minimum": 135.7,
+      "maximum": 135.7
+    },
+    "statistics": {
+      "type": "object",
+      "properties": {
+        "vegetation": {
+          "description": "Percentage of pixels that are detected as vegetation, e.g. forests, grasslands, etc.",
+          "minimum": 0,
+          "maximum": 100
+        },
+        "water": {
+          "description": "Percentage of pixels that are detected as water, e.g. rivers, oceans and ponds.",
+          "minimum": 0,
+          "maximum": 100
+        },
+        "urban": {
+          "description": "Percentage of pixels that detected as urban, e.g. roads and buildings.",
+          "minimum": 0,
+          "maximum": 100
+        }
+      }
+    }
+  },
+  "links": [
+    {
+      "rel": "root",
+      "href": "./collection.json",
+      "type": "application/json",
+      "title": "Simple Example Collection"
+    },
+    {
+      "rel": "item",
+      "href": "./simple-item.json",
+      "type": "application/geo+json",
+      "title": "Simple Item"
+    },
+    {
+      "rel": "item",
+      "href": "./core-item.json",
+      "type": "application/geo+json",
+      "title": "Core Item"
+    },
+    {
+      "rel": "item",
+      "href": "./extended-item.json",
+      "type": "application/geo+json",
+      "title": "Extended Item"
+    },
+    {
+      "rel": "self",
+      "href": "https://raw.githubusercontent.com/radiantearth/stac-spec/v1.1.0/examples/collection.json",
+      "type": "application/json"
+    }
+  ]
+}


=====================================
tests/test_data/v110/simple-item.json
=====================================
@@ -0,0 +1,60 @@
+{
+  "stac_version": "1.1.0",
+  "stac_extensions": [],
+  "type": "Feature",
+  "id": "20201211_223832_CS2",
+  "bbox": [
+    172.91173669923782, 1.3438851951615003, 172.95469614953714,
+    1.3690476620161975
+  ],
+  "geometry": {
+    "type": "Polygon",
+    "coordinates": [
+      [
+        [172.91173669923782, 1.3438851951615003],
+        [172.95469614953714, 1.3438851951615003],
+        [172.95469614953714, 1.3690476620161975],
+        [172.91173669923782, 1.3690476620161975],
+        [172.91173669923782, 1.3438851951615003]
+      ]
+    ]
+  },
+  "properties": {
+    "datetime": "2020-12-11T22:38:32.125000Z"
+  },
+  "collection": "simple-collection",
+  "links": [
+    {
+      "rel": "collection",
+      "href": "./collection.json",
+      "type": "application/json",
+      "title": "Simple Example Collection"
+    },
+    {
+      "rel": "root",
+      "href": "./collection.json",
+      "type": "application/json",
+      "title": "Simple Example Collection"
+    },
+    {
+      "rel": "parent",
+      "href": "./collection.json",
+      "type": "application/json",
+      "title": "Simple Example Collection"
+    }
+  ],
+  "assets": {
+    "visual": {
+      "href": "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.tif",
+      "type": "image/tiff; application=geotiff; profile=cloud-optimized",
+      "title": "3-Band Visual",
+      "roles": ["visual"]
+    },
+    "thumbnail": {
+      "href": "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.jpg",
+      "title": "Thumbnail",
+      "type": "image/jpeg",
+      "roles": ["thumbnail"]
+    }
+  }
+}


=====================================
tests/test_validate_collections.py
=====================================
@@ -0,0 +1,55 @@
+"""
+Description: Test stac-validator on --collections (/collections validation).
+
+"""
+
+from stac_validator import stac_validator
+
+
+def test_validate_collections_remote():
+    stac_file = "https://earth-search.aws.element84.com/v0/collections"
+    stac = stac_validator.StacValidate(stac_file, collections=True)
+    stac.validate_collections()
+
+    assert stac.message == [
+        {
+            "version": "1.0.0-beta.2",
+            "path": "https://earth-search.aws.element84.com/v0/collections",
+            "schema": [
+                "https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
+            ],
+            "valid_stac": True,
+            "asset_type": "COLLECTION",
+            "validation_method": "default",
+        },
+        {
+            "version": "1.0.0-beta.2",
+            "path": "https://earth-search.aws.element84.com/v0/collections",
+            "schema": [
+                "https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
+            ],
+            "valid_stac": True,
+            "asset_type": "COLLECTION",
+            "validation_method": "default",
+        },
+        {
+            "version": "1.0.0-beta.2",
+            "path": "https://earth-search.aws.element84.com/v0/collections",
+            "schema": [
+                "https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
+            ],
+            "valid_stac": True,
+            "asset_type": "COLLECTION",
+            "validation_method": "default",
+        },
+        {
+            "version": "1.0.0-beta.2",
+            "path": "https://earth-search.aws.element84.com/v0/collections",
+            "schema": [
+                "https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
+            ],
+            "valid_stac": True,
+            "asset_type": "COLLECTION",
+            "validation_method": "default",
+        },
+    ]


=====================================
tests/test_validate_dict.py
=====================================
@@ -56,8 +56,7 @@ def test_correct_validate_dict_return_method():
     stac = stac_validator.StacValidate()
     with open("tests/test_data/1rc2/extensions-collection/collection.json", "r") as f:
         good_stac = json.load(f)
-    if stac.validate_dict(good_stac) is True:
-        return True
+    assert stac.validate_dict(good_stac)
 
 
 def test_incorrect_validate_dict_return_method():
@@ -65,5 +64,4 @@ def test_incorrect_validate_dict_return_method():
     with open("tests/test_data/1rc2/extensions-collection/collection.json", "r") as f:
         good_stac = json.load(f)
         bad_stac = good_stac.pop("type", None)
-    if stac.validate_dict(bad_stac) is False:
-        return True
+    assert stac.validate_dict(bad_stac) is False


=====================================
tests/test_validate_item_collection.py
=====================================
@@ -1,9 +1,8 @@
 """
-Description: Test the validator
+Description: Test stac-validator on item-collection validation.
 
 """
 
-
 from stac_validator import stac_validator
 
 


=====================================
tox.ini
=====================================
@@ -1,5 +1,5 @@
 [tox]
-envlist = py37,py38,py39
+envlist = py38,py39,py310,py311
 
 [testenv]
 deps = pytest



View it on GitLab: https://salsa.debian.org/debian-gis-team/stac-validator/-/commit/c1f82c57f94037f8610ac9265a17b41bf77fb273

-- 
View it on GitLab: https://salsa.debian.org/debian-gis-team/stac-validator/-/commit/c1f82c57f94037f8610ac9265a17b41bf77fb273
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/pkg-grass-devel/attachments/20241013/d0d16d7e/attachment-0001.htm>


More information about the Pkg-grass-devel mailing list