Skip to content

Commit

Permalink
Make stac-validator and stac-check optional (#468)
Browse files Browse the repository at this point in the history
* feat: make stac-validator and stac-check optional

* chore: update changelog
  • Loading branch information
gadomski committed Nov 17, 2023
1 parent 149f3c8 commit 36ad7cb
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
- name: Install with extra_requires
run: pip install .[s3,dev]
run: pip install .[s3,validate,dev]
- name: Test
run: ./scripts/test
minimum-versions:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

- Make computation of statistics and histogram optional for `core.add_raster.add_raster_to_item` ([#467](https://github.com/stac-utils/stactools/pull/467))
- Make **stac-validator** and **stac-check** optional dependencies ([#468](https://github.com/stac-utils/stactools/pull/468))

## [0.5.2] - 2023-09-20

Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ If your system GDAL is older than version 3.1, consider using [Docker](#using-do

### Optional dependencies

`stactools` includes one optional dependency:
`stactools` includes two optional dependency:

- `s3`: Enables s3 hrefs via `fsspec` and `s3fs`
- `validate`: Enables `stac validate` and `stac lint`

To install the single optional dependency:
To install optional dependencies:

```sh
pip install stactools[s3]
pip install 'stactools[s3]'
pip install 'stactools[validate]'
```

### Docker
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ dependencies = [
"pystac[validation]>=1.8.2",
"rasterio>=1.3.2",
"shapely>=2.0.1",
"stac-check>=1.3.2",
"stac-validator>=3.1.0",
]
dynamic = ["version"]

Expand Down Expand Up @@ -73,6 +71,7 @@ docs = [
"sphinxcontrib-fulltoc~=1.2",
]
s3 = ["s3fs>=2021.7"]
validate = ["stac-check>=1.3.2", "stac-validator>=3.1.0"]

[build-system]
requires = ["setuptools", "wheel"]
Expand Down
29 changes: 25 additions & 4 deletions src/stactools/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

import stactools.core

try:
import stac_validator as _
except ImportError:
HAS_STAC_VALIDATOR = False
else:
HAS_STAC_VALIDATOR = True

try:
import stac_check as _
except ImportError:
HAS_STAC_CHECK = False
else:
HAS_STAC_CHECK = True


stactools.core.use_fsspec()


Expand All @@ -16,13 +31,11 @@ def register_plugin(registry: "Registry") -> None:
create,
info,
layout,
lint,
merge,
migrate,
summary,
update_extent,
update_geometry,
validate,
version,
)

Expand All @@ -35,15 +48,23 @@ def register_plugin(registry: "Registry") -> None:
registry.register_subcommand(info.create_info_command)
registry.register_subcommand(info.create_describe_command)
registry.register_subcommand(layout.create_layout_command)
registry.register_subcommand(lint.create_lint_command)
registry.register_subcommand(merge.create_merge_command)
registry.register_subcommand(migrate.create_migrate_command)
registry.register_subcommand(summary.create_summary_command)
registry.register_subcommand(validate.create_validate_command)
registry.register_subcommand(version.create_version_command)
registry.register_subcommand(update_extent.create_update_extent_command)
registry.register_subcommand(update_geometry.create_update_geometry_command)

if HAS_STAC_VALIDATOR:
from stactools.cli.commands import validate

registry.register_subcommand(validate.create_validate_command)

if HAS_STAC_CHECK:
from stactools.cli.commands import lint

registry.register_subcommand(lint.create_lint_command)


from stactools.cli.registry import Registry

Expand Down
3 changes: 3 additions & 0 deletions tests/cli/commands/test_lint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import pytest
from click.testing import CliRunner
from stactools.cli.cli import cli

from tests import test_data

pytest.importorskip("stac_check")


def test_valid_item() -> None:
path = test_data.get_path("data-files/linting/20201211_223832_cs2.json")
Expand Down
2 changes: 2 additions & 0 deletions tests/cli/commands/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from tests import test_data

pytest.importorskip("stac_validator")


def test_valid_item() -> None:
path = test_data.get_path(
Expand Down

0 comments on commit 36ad7cb

Please sign in to comment.