Skip to content

Commit 36ad7cb

Browse files
authored
Make stac-validator and stac-check optional (#468)
* feat: make stac-validator and stac-check optional * chore: update changelog
1 parent 149f3c8 commit 36ad7cb

File tree

7 files changed

+38
-10
lines changed

7 files changed

+38
-10
lines changed

.github/workflows/continuous-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
with:
4545
python-version: ${{ matrix.python-version }}
4646
- name: Install with extra_requires
47-
run: pip install .[s3,dev]
47+
run: pip install .[s3,validate,dev]
4848
- name: Test
4949
run: ./scripts/test
5050
minimum-versions:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

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

1213
## [0.5.2] - 2023-09-20
1314

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ If your system GDAL is older than version 3.1, consider using [Docker](#using-do
4848

4949
### Optional dependencies
5050

51-
`stactools` includes one optional dependency:
51+
`stactools` includes two optional dependency:
5252

5353
- `s3`: Enables s3 hrefs via `fsspec` and `s3fs`
54+
- `validate`: Enables `stac validate` and `stac lint`
5455

55-
To install the single optional dependency:
56+
To install optional dependencies:
5657

5758
```sh
58-
pip install stactools[s3]
59+
pip install 'stactools[s3]'
60+
pip install 'stactools[validate]'
5961
```
6062

6163
### Docker

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ dependencies = [
2828
"pystac[validation]>=1.8.2",
2929
"rasterio>=1.3.2",
3030
"shapely>=2.0.1",
31-
"stac-check>=1.3.2",
32-
"stac-validator>=3.1.0",
3331
]
3432
dynamic = ["version"]
3533

@@ -73,6 +71,7 @@ docs = [
7371
"sphinxcontrib-fulltoc~=1.2",
7472
]
7573
s3 = ["s3fs>=2021.7"]
74+
validate = ["stac-check>=1.3.2", "stac-validator>=3.1.0"]
7675

7776
[build-system]
7877
requires = ["setuptools", "wheel"]

src/stactools/cli/__init__.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
import stactools.core
44

5+
try:
6+
import stac_validator as _
7+
except ImportError:
8+
HAS_STAC_VALIDATOR = False
9+
else:
10+
HAS_STAC_VALIDATOR = True
11+
12+
try:
13+
import stac_check as _
14+
except ImportError:
15+
HAS_STAC_CHECK = False
16+
else:
17+
HAS_STAC_CHECK = True
18+
19+
520
stactools.core.use_fsspec()
621

722

@@ -16,13 +31,11 @@ def register_plugin(registry: "Registry") -> None:
1631
create,
1732
info,
1833
layout,
19-
lint,
2034
merge,
2135
migrate,
2236
summary,
2337
update_extent,
2438
update_geometry,
25-
validate,
2639
version,
2740
)
2841

@@ -35,15 +48,23 @@ def register_plugin(registry: "Registry") -> None:
3548
registry.register_subcommand(info.create_info_command)
3649
registry.register_subcommand(info.create_describe_command)
3750
registry.register_subcommand(layout.create_layout_command)
38-
registry.register_subcommand(lint.create_lint_command)
3951
registry.register_subcommand(merge.create_merge_command)
4052
registry.register_subcommand(migrate.create_migrate_command)
4153
registry.register_subcommand(summary.create_summary_command)
42-
registry.register_subcommand(validate.create_validate_command)
4354
registry.register_subcommand(version.create_version_command)
4455
registry.register_subcommand(update_extent.create_update_extent_command)
4556
registry.register_subcommand(update_geometry.create_update_geometry_command)
4657

58+
if HAS_STAC_VALIDATOR:
59+
from stactools.cli.commands import validate
60+
61+
registry.register_subcommand(validate.create_validate_command)
62+
63+
if HAS_STAC_CHECK:
64+
from stactools.cli.commands import lint
65+
66+
registry.register_subcommand(lint.create_lint_command)
67+
4768

4869
from stactools.cli.registry import Registry
4970

tests/cli/commands/test_lint.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import pytest
12
from click.testing import CliRunner
23
from stactools.cli.cli import cli
34

45
from tests import test_data
56

7+
pytest.importorskip("stac_check")
8+
69

710
def test_valid_item() -> None:
811
path = test_data.get_path("data-files/linting/20201211_223832_cs2.json")

tests/cli/commands/test_validate.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from tests import test_data
66

7+
pytest.importorskip("stac_validator")
8+
79

810
def test_valid_item() -> None:
911
path = test_data.get_path(

0 commit comments

Comments
 (0)