stac-validator 3.10.2__tar.gz → 3.11.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {stac_validator-3.10.2 → stac_validator-3.11.0}/PKG-INFO +42 -1
- {stac_validator-3.10.2 → stac_validator-3.11.0}/README.md +41 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/pyproject.toml +1 -1
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator/stac_validator.py +17 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator/utilities.py +43 -2
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator.egg-info/PKG-INFO +42 -1
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator.egg-info/SOURCES.txt +1 -0
- stac_validator-3.11.0/tests/test_schema_cache.py +91 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_sys_exit.py +12 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_validate_dict.py +29 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/LICENSE +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/setup.cfg +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator/__init__.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator/validate.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator.egg-info/dependency_links.txt +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator.egg-info/entry_points.txt +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator.egg-info/requires.txt +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator.egg-info/top_level.txt +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_assets.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_config.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_core.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_custom.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_default.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_extensions.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_header.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_links.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_pydantic.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_recursion.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_validate_collections.py +0 -0
- {stac_validator-3.10.2 → stac_validator-3.11.0}/tests/test_validate_item_collection.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stac_validator
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.11.0
|
|
4
4
|
Summary: A package to validate STAC files
|
|
5
5
|
Author: James Banting
|
|
6
6
|
Author-email: Jonathan Healy <jonathan.d.healy@gmail.com>
|
|
@@ -62,6 +62,7 @@ Dynamic: license-file
|
|
|
62
62
|
- [Usage](#usage)
|
|
63
63
|
- [CLI](#cli)
|
|
64
64
|
- [Python](#python)
|
|
65
|
+
- [Schema Cache Settings](#schema-cache-settings)
|
|
65
66
|
- [Examples](#additional-examples)
|
|
66
67
|
- [Core Validation](#--core)
|
|
67
68
|
- [Custom Schema](#--custom)
|
|
@@ -217,6 +218,7 @@ Options:
|
|
|
217
218
|
(local filepath).
|
|
218
219
|
--pydantic Validate using stac-pydantic models for enhanced
|
|
219
220
|
type checking and validation.
|
|
221
|
+
--schema-cache-size INTEGER Max number of schema entries to cache in memory. Use 0 to disable schema caching. Defaults to 16.
|
|
220
222
|
--schema-config TEXT Path to a YAML or JSON schema config file.
|
|
221
223
|
--verbose Enable verbose output. This will output
|
|
222
224
|
additional information during validation.
|
|
@@ -283,6 +285,20 @@ stac.validate_dict(dictionary)
|
|
|
283
285
|
print(stac.message)
|
|
284
286
|
```
|
|
285
287
|
|
|
288
|
+
Set schema cache size
|
|
289
|
+
```python
|
|
290
|
+
from stac_validator import stac_validator
|
|
291
|
+
from stac_validator.utilities import set_schema_cache_size
|
|
292
|
+
|
|
293
|
+
# Set once at app startup (process-wide)
|
|
294
|
+
set_schema_cache_size(16) # use 0 to disable caching
|
|
295
|
+
|
|
296
|
+
stac = stac_validator.StacValidate()
|
|
297
|
+
stac.validate_dict(dictionary)
|
|
298
|
+
print(stac.message)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
|
|
286
302
|
**Item Collection**
|
|
287
303
|
|
|
288
304
|
```python
|
|
@@ -293,6 +309,29 @@ stac.validate_item_collection_dict(item_collection_dict)
|
|
|
293
309
|
print(stac.message)
|
|
294
310
|
```
|
|
295
311
|
|
|
312
|
+
|
|
313
|
+
### Schema Cache Settings
|
|
314
|
+
|
|
315
|
+
- Default schema cache size is 16 entries.
|
|
316
|
+
- Use `--schema-cache-size` in the CLI or `set_schema_cache_size(...)` in Python to override it.
|
|
317
|
+
- Use `0` to disable schema caching.
|
|
318
|
+
|
|
319
|
+
Use `set_schema_cache_size` once at application startup:
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
from stac_validator.utilities import set_schema_cache_size
|
|
323
|
+
|
|
324
|
+
# Examples:
|
|
325
|
+
set_schema_cache_size(16) # small cache for low-memory deployments
|
|
326
|
+
set_schema_cache_size(64) # moderate cache for long-running services
|
|
327
|
+
set_schema_cache_size(0) # disable schema caching
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Notes:
|
|
331
|
+
- `StacValidate()` and `validate_dict()` do not accept a cache-size parameter.
|
|
332
|
+
- Changing cache size at runtime replaces the cache instance and drops existing cached entries.
|
|
333
|
+
- In multi-worker deployments, configure cache size in each worker process.
|
|
334
|
+
|
|
296
335
|
## Deployment
|
|
297
336
|
|
|
298
337
|
### Docker
|
|
@@ -566,11 +605,13 @@ The following organizations have contributed time and/or funding to support the
|
|
|
566
605
|
- [Healy Hyperspatial](https://healy-hyperspatial.github.io/)
|
|
567
606
|
- [Radiant Earth Foundation](https://radiant.earth/)
|
|
568
607
|
- [Sparkgeo](https://sparkgeo.com/)
|
|
608
|
+
- [CloudFerro](https://cloudferro.com/)
|
|
569
609
|
|
|
570
610
|
<p align="left">
|
|
571
611
|
<a href="https://healy-hyperspatial.github.io/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/hh-logo-blue.png" alt="Healy Hyperspatial" height="100" hspace="20"></a>
|
|
572
612
|
<a href="https://radiant.earth/"><img src="assets/radiant-earth.webp" alt="Radiant Earth Foundation" height="100" hspace="20"></a>
|
|
573
613
|
<a href="https://sparkgeo.com/"><img src="assets/sparkgeo_logo.jpeg" alt="Sparkgeo" height="100" hspace="20"></a>
|
|
614
|
+
<a href="https://cloudferro.com/"><img src="assets/cloudferro-logo.png" alt="CloudFerro" height="110" hspace="20"></a>
|
|
574
615
|
</p>
|
|
575
616
|
|
|
576
617
|
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
- [Usage](#usage)
|
|
24
24
|
- [CLI](#cli)
|
|
25
25
|
- [Python](#python)
|
|
26
|
+
- [Schema Cache Settings](#schema-cache-settings)
|
|
26
27
|
- [Examples](#additional-examples)
|
|
27
28
|
- [Core Validation](#--core)
|
|
28
29
|
- [Custom Schema](#--custom)
|
|
@@ -178,6 +179,7 @@ Options:
|
|
|
178
179
|
(local filepath).
|
|
179
180
|
--pydantic Validate using stac-pydantic models for enhanced
|
|
180
181
|
type checking and validation.
|
|
182
|
+
--schema-cache-size INTEGER Max number of schema entries to cache in memory. Use 0 to disable schema caching. Defaults to 16.
|
|
181
183
|
--schema-config TEXT Path to a YAML or JSON schema config file.
|
|
182
184
|
--verbose Enable verbose output. This will output
|
|
183
185
|
additional information during validation.
|
|
@@ -244,6 +246,20 @@ stac.validate_dict(dictionary)
|
|
|
244
246
|
print(stac.message)
|
|
245
247
|
```
|
|
246
248
|
|
|
249
|
+
Set schema cache size
|
|
250
|
+
```python
|
|
251
|
+
from stac_validator import stac_validator
|
|
252
|
+
from stac_validator.utilities import set_schema_cache_size
|
|
253
|
+
|
|
254
|
+
# Set once at app startup (process-wide)
|
|
255
|
+
set_schema_cache_size(16) # use 0 to disable caching
|
|
256
|
+
|
|
257
|
+
stac = stac_validator.StacValidate()
|
|
258
|
+
stac.validate_dict(dictionary)
|
|
259
|
+
print(stac.message)
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
|
|
247
263
|
**Item Collection**
|
|
248
264
|
|
|
249
265
|
```python
|
|
@@ -254,6 +270,29 @@ stac.validate_item_collection_dict(item_collection_dict)
|
|
|
254
270
|
print(stac.message)
|
|
255
271
|
```
|
|
256
272
|
|
|
273
|
+
|
|
274
|
+
### Schema Cache Settings
|
|
275
|
+
|
|
276
|
+
- Default schema cache size is 16 entries.
|
|
277
|
+
- Use `--schema-cache-size` in the CLI or `set_schema_cache_size(...)` in Python to override it.
|
|
278
|
+
- Use `0` to disable schema caching.
|
|
279
|
+
|
|
280
|
+
Use `set_schema_cache_size` once at application startup:
|
|
281
|
+
|
|
282
|
+
```python
|
|
283
|
+
from stac_validator.utilities import set_schema_cache_size
|
|
284
|
+
|
|
285
|
+
# Examples:
|
|
286
|
+
set_schema_cache_size(16) # small cache for low-memory deployments
|
|
287
|
+
set_schema_cache_size(64) # moderate cache for long-running services
|
|
288
|
+
set_schema_cache_size(0) # disable schema caching
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Notes:
|
|
292
|
+
- `StacValidate()` and `validate_dict()` do not accept a cache-size parameter.
|
|
293
|
+
- Changing cache size at runtime replaces the cache instance and drops existing cached entries.
|
|
294
|
+
- In multi-worker deployments, configure cache size in each worker process.
|
|
295
|
+
|
|
257
296
|
## Deployment
|
|
258
297
|
|
|
259
298
|
### Docker
|
|
@@ -527,11 +566,13 @@ The following organizations have contributed time and/or funding to support the
|
|
|
527
566
|
- [Healy Hyperspatial](https://healy-hyperspatial.github.io/)
|
|
528
567
|
- [Radiant Earth Foundation](https://radiant.earth/)
|
|
529
568
|
- [Sparkgeo](https://sparkgeo.com/)
|
|
569
|
+
- [CloudFerro](https://cloudferro.com/)
|
|
530
570
|
|
|
531
571
|
<p align="left">
|
|
532
572
|
<a href="https://healy-hyperspatial.github.io/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/hh-logo-blue.png" alt="Healy Hyperspatial" height="100" hspace="20"></a>
|
|
533
573
|
<a href="https://radiant.earth/"><img src="assets/radiant-earth.webp" alt="Radiant Earth Foundation" height="100" hspace="20"></a>
|
|
534
574
|
<a href="https://sparkgeo.com/"><img src="assets/sparkgeo_logo.jpeg" alt="Sparkgeo" height="100" hspace="20"></a>
|
|
575
|
+
<a href="https://cloudferro.com/"><img src="assets/cloudferro-logo.png" alt="CloudFerro" height="110" hspace="20"></a>
|
|
535
576
|
</p>
|
|
536
577
|
|
|
537
578
|
|
|
@@ -5,6 +5,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
|
|
5
5
|
|
|
6
6
|
import click # type: ignore
|
|
7
7
|
|
|
8
|
+
from .utilities import set_schema_cache_size
|
|
8
9
|
from .validate import StacValidate
|
|
9
10
|
|
|
10
11
|
|
|
@@ -232,6 +233,12 @@ def recursive_validation_summary(message: List[Dict[str, Any]]) -> None:
|
|
|
232
233
|
is_flag=True,
|
|
233
234
|
help="Enable verbose output. This will output additional information during validation.",
|
|
234
235
|
)
|
|
236
|
+
@click.option(
|
|
237
|
+
"--schema-cache-size",
|
|
238
|
+
type=int,
|
|
239
|
+
default=None,
|
|
240
|
+
help="Max number of schema entries to cache in memory. Use 0 to disable schema caching. Defaults to 16.",
|
|
241
|
+
)
|
|
235
242
|
def main(
|
|
236
243
|
stac_file: str,
|
|
237
244
|
collections: bool,
|
|
@@ -253,6 +260,7 @@ def main(
|
|
|
253
260
|
log_file: str,
|
|
254
261
|
pydantic: bool,
|
|
255
262
|
verbose: bool = False,
|
|
263
|
+
schema_cache_size: Optional[int] = None,
|
|
256
264
|
):
|
|
257
265
|
"""Main function for the `stac-validator` command line tool. Validates a STAC file
|
|
258
266
|
against the STAC specification and prints the validation results to the console as JSON.
|
|
@@ -279,6 +287,7 @@ def main(
|
|
|
279
287
|
log_file (str): Path to a log file to save full recursive output.
|
|
280
288
|
pydantic (bool): Whether to validate using stac-pydantic models for enhanced type checking and validation.
|
|
281
289
|
verbose (bool): Whether to enable verbose output. This will output additional information during validation.
|
|
290
|
+
schema_cache_size (Optional[int]): Maximum schema cache size. Use 0 to disable caching. Defaults to 16.
|
|
282
291
|
|
|
283
292
|
Returns:
|
|
284
293
|
None
|
|
@@ -295,6 +304,14 @@ def main(
|
|
|
295
304
|
else:
|
|
296
305
|
schema_map_dict = dict(schema_map)
|
|
297
306
|
|
|
307
|
+
if schema_cache_size is not None:
|
|
308
|
+
if schema_cache_size < 0:
|
|
309
|
+
raise click.BadParameter(
|
|
310
|
+
"must be greater than or equal to 0",
|
|
311
|
+
param_hint="--schema-cache-size",
|
|
312
|
+
)
|
|
313
|
+
set_schema_cache_size(schema_cache_size)
|
|
314
|
+
|
|
298
315
|
stac = StacValidate(
|
|
299
316
|
stac_file=stac_file,
|
|
300
317
|
collections=collections,
|
|
@@ -181,7 +181,44 @@ def fetch_and_parse_file(input_path: str, headers: Optional[Dict] = None) -> Dic
|
|
|
181
181
|
raise e
|
|
182
182
|
|
|
183
183
|
|
|
184
|
-
|
|
184
|
+
DEFAULT_SCHEMA_CACHE_SIZE = 16
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _build_schema_cache(maxsize: int):
|
|
188
|
+
@functools.lru_cache(maxsize=maxsize)
|
|
189
|
+
def _cached_fetch(input_path: str) -> Dict:
|
|
190
|
+
return fetch_and_parse_file(input_path)
|
|
191
|
+
|
|
192
|
+
return _cached_fetch
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
_schema_cache = _build_schema_cache(DEFAULT_SCHEMA_CACHE_SIZE)
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def set_schema_cache_size(maxsize: int) -> None:
|
|
199
|
+
"""Reconfigure the schema cache max size at runtime.
|
|
200
|
+
|
|
201
|
+
Args:
|
|
202
|
+
maxsize: Maximum number of cached schema entries. Use 0 to disable caching.
|
|
203
|
+
|
|
204
|
+
Raises:
|
|
205
|
+
ValueError: If maxsize is negative.
|
|
206
|
+
"""
|
|
207
|
+
if maxsize < 0:
|
|
208
|
+
raise ValueError("schema cache size must be greater than or equal to 0")
|
|
209
|
+
|
|
210
|
+
global _schema_cache
|
|
211
|
+
_schema_cache = _build_schema_cache(maxsize)
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def _fetch_and_parse_schema_cache_info():
|
|
215
|
+
return _schema_cache.cache_info()
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _fetch_and_parse_schema_cache_clear() -> None:
|
|
219
|
+
_schema_cache.cache_clear()
|
|
220
|
+
|
|
221
|
+
|
|
185
222
|
def fetch_and_parse_schema(input_path: str) -> Dict:
|
|
186
223
|
"""Fetches and parses a JSON schema file from a URL or local file using a cache.
|
|
187
224
|
|
|
@@ -201,7 +238,11 @@ def fetch_and_parse_schema(input_path: str) -> Dict:
|
|
|
201
238
|
ValueError: If the input is not a valid URL or local file path.
|
|
202
239
|
requests.exceptions.RequestException: If there is an error while downloading the file.
|
|
203
240
|
"""
|
|
204
|
-
return
|
|
241
|
+
return _schema_cache(input_path)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
fetch_and_parse_schema.cache_info = _fetch_and_parse_schema_cache_info # type: ignore[attr-defined]
|
|
245
|
+
fetch_and_parse_schema.cache_clear = _fetch_and_parse_schema_cache_clear # type: ignore[attr-defined]
|
|
205
246
|
|
|
206
247
|
|
|
207
248
|
def set_schema_addr(version: str, stac_type: str) -> str:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: stac_validator
|
|
3
|
-
Version: 3.
|
|
3
|
+
Version: 3.11.0
|
|
4
4
|
Summary: A package to validate STAC files
|
|
5
5
|
Author: James Banting
|
|
6
6
|
Author-email: Jonathan Healy <jonathan.d.healy@gmail.com>
|
|
@@ -62,6 +62,7 @@ Dynamic: license-file
|
|
|
62
62
|
- [Usage](#usage)
|
|
63
63
|
- [CLI](#cli)
|
|
64
64
|
- [Python](#python)
|
|
65
|
+
- [Schema Cache Settings](#schema-cache-settings)
|
|
65
66
|
- [Examples](#additional-examples)
|
|
66
67
|
- [Core Validation](#--core)
|
|
67
68
|
- [Custom Schema](#--custom)
|
|
@@ -217,6 +218,7 @@ Options:
|
|
|
217
218
|
(local filepath).
|
|
218
219
|
--pydantic Validate using stac-pydantic models for enhanced
|
|
219
220
|
type checking and validation.
|
|
221
|
+
--schema-cache-size INTEGER Max number of schema entries to cache in memory. Use 0 to disable schema caching. Defaults to 16.
|
|
220
222
|
--schema-config TEXT Path to a YAML or JSON schema config file.
|
|
221
223
|
--verbose Enable verbose output. This will output
|
|
222
224
|
additional information during validation.
|
|
@@ -283,6 +285,20 @@ stac.validate_dict(dictionary)
|
|
|
283
285
|
print(stac.message)
|
|
284
286
|
```
|
|
285
287
|
|
|
288
|
+
Set schema cache size
|
|
289
|
+
```python
|
|
290
|
+
from stac_validator import stac_validator
|
|
291
|
+
from stac_validator.utilities import set_schema_cache_size
|
|
292
|
+
|
|
293
|
+
# Set once at app startup (process-wide)
|
|
294
|
+
set_schema_cache_size(16) # use 0 to disable caching
|
|
295
|
+
|
|
296
|
+
stac = stac_validator.StacValidate()
|
|
297
|
+
stac.validate_dict(dictionary)
|
|
298
|
+
print(stac.message)
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
|
|
286
302
|
**Item Collection**
|
|
287
303
|
|
|
288
304
|
```python
|
|
@@ -293,6 +309,29 @@ stac.validate_item_collection_dict(item_collection_dict)
|
|
|
293
309
|
print(stac.message)
|
|
294
310
|
```
|
|
295
311
|
|
|
312
|
+
|
|
313
|
+
### Schema Cache Settings
|
|
314
|
+
|
|
315
|
+
- Default schema cache size is 16 entries.
|
|
316
|
+
- Use `--schema-cache-size` in the CLI or `set_schema_cache_size(...)` in Python to override it.
|
|
317
|
+
- Use `0` to disable schema caching.
|
|
318
|
+
|
|
319
|
+
Use `set_schema_cache_size` once at application startup:
|
|
320
|
+
|
|
321
|
+
```python
|
|
322
|
+
from stac_validator.utilities import set_schema_cache_size
|
|
323
|
+
|
|
324
|
+
# Examples:
|
|
325
|
+
set_schema_cache_size(16) # small cache for low-memory deployments
|
|
326
|
+
set_schema_cache_size(64) # moderate cache for long-running services
|
|
327
|
+
set_schema_cache_size(0) # disable schema caching
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
Notes:
|
|
331
|
+
- `StacValidate()` and `validate_dict()` do not accept a cache-size parameter.
|
|
332
|
+
- Changing cache size at runtime replaces the cache instance and drops existing cached entries.
|
|
333
|
+
- In multi-worker deployments, configure cache size in each worker process.
|
|
334
|
+
|
|
296
335
|
## Deployment
|
|
297
336
|
|
|
298
337
|
### Docker
|
|
@@ -566,11 +605,13 @@ The following organizations have contributed time and/or funding to support the
|
|
|
566
605
|
- [Healy Hyperspatial](https://healy-hyperspatial.github.io/)
|
|
567
606
|
- [Radiant Earth Foundation](https://radiant.earth/)
|
|
568
607
|
- [Sparkgeo](https://sparkgeo.com/)
|
|
608
|
+
- [CloudFerro](https://cloudferro.com/)
|
|
569
609
|
|
|
570
610
|
<p align="left">
|
|
571
611
|
<a href="https://healy-hyperspatial.github.io/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/hh-logo-blue.png" alt="Healy Hyperspatial" height="100" hspace="20"></a>
|
|
572
612
|
<a href="https://radiant.earth/"><img src="assets/radiant-earth.webp" alt="Radiant Earth Foundation" height="100" hspace="20"></a>
|
|
573
613
|
<a href="https://sparkgeo.com/"><img src="assets/sparkgeo_logo.jpeg" alt="Sparkgeo" height="100" hspace="20"></a>
|
|
614
|
+
<a href="https://cloudferro.com/"><img src="assets/cloudferro-logo.png" alt="CloudFerro" height="110" hspace="20"></a>
|
|
574
615
|
</p>
|
|
575
616
|
|
|
576
617
|
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Test schema caching behavior."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from stac_validator.utilities import (
|
|
6
|
+
DEFAULT_SCHEMA_CACHE_SIZE,
|
|
7
|
+
fetch_and_parse_schema,
|
|
8
|
+
set_schema_cache_size,
|
|
9
|
+
)
|
|
10
|
+
from stac_validator.validate import StacValidate
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def test_schema_cache_with_extensions():
|
|
14
|
+
"""Test that extension schemas are cached across validations."""
|
|
15
|
+
original_cache_info = fetch_and_parse_schema.cache_info()
|
|
16
|
+
original_maxsize = original_cache_info.maxsize
|
|
17
|
+
try:
|
|
18
|
+
# Use a sufficiently large cache to avoid evictions during this test
|
|
19
|
+
set_schema_cache_size(256)
|
|
20
|
+
fetch_and_parse_schema.cache_clear()
|
|
21
|
+
stac_file = "tests/test_data/v100/extended-item.json"
|
|
22
|
+
# First validation
|
|
23
|
+
stac1 = StacValidate(stac_file)
|
|
24
|
+
stac1.run()
|
|
25
|
+
cache_info_1 = fetch_and_parse_schema.cache_info()
|
|
26
|
+
hits_after_first = cache_info_1.hits
|
|
27
|
+
misses_after_first = cache_info_1.misses
|
|
28
|
+
size_after_first = cache_info_1.currsize
|
|
29
|
+
# Second validation with same file
|
|
30
|
+
stac2 = StacValidate(stac_file)
|
|
31
|
+
stac2.run()
|
|
32
|
+
cache_info_2 = fetch_and_parse_schema.cache_info()
|
|
33
|
+
hits_after_second = cache_info_2.hits
|
|
34
|
+
misses_after_second = cache_info_2.misses
|
|
35
|
+
size_after_second = cache_info_2.currsize
|
|
36
|
+
# Verify cache is working
|
|
37
|
+
assert (
|
|
38
|
+
size_after_first > 0
|
|
39
|
+
), "Cache should contain schemas after first validation"
|
|
40
|
+
assert (
|
|
41
|
+
size_after_second == size_after_first
|
|
42
|
+
), "Cache size should not grow on second validation"
|
|
43
|
+
assert (
|
|
44
|
+
hits_after_second > hits_after_first
|
|
45
|
+
), "Cache hits should increase on second validation"
|
|
46
|
+
assert (
|
|
47
|
+
misses_after_second == misses_after_first
|
|
48
|
+
), "No new misses on second validation"
|
|
49
|
+
finally:
|
|
50
|
+
set_schema_cache_size(original_maxsize)
|
|
51
|
+
fetch_and_parse_schema.cache_clear()
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_schema_cache_size_can_be_reconfigured():
|
|
55
|
+
"""Cache maxsize can be changed at runtime."""
|
|
56
|
+
try:
|
|
57
|
+
set_schema_cache_size(2)
|
|
58
|
+
fetch_and_parse_schema.cache_clear()
|
|
59
|
+
|
|
60
|
+
fetch_and_parse_schema("local_schemas/v1.0.0/catalog.json")
|
|
61
|
+
fetch_and_parse_schema("local_schemas/v1.0.0/collection.json")
|
|
62
|
+
fetch_and_parse_schema("local_schemas/v1.0.0/item.json")
|
|
63
|
+
|
|
64
|
+
cache_info = fetch_and_parse_schema.cache_info()
|
|
65
|
+
assert cache_info.maxsize == 2
|
|
66
|
+
assert cache_info.currsize == 2
|
|
67
|
+
finally:
|
|
68
|
+
set_schema_cache_size(DEFAULT_SCHEMA_CACHE_SIZE)
|
|
69
|
+
fetch_and_parse_schema.cache_clear()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_schema_cache_size_rejects_negative():
|
|
73
|
+
with pytest.raises(ValueError):
|
|
74
|
+
set_schema_cache_size(-1)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_schema_cache_size_zero_disables_cache():
|
|
78
|
+
try:
|
|
79
|
+
set_schema_cache_size(0)
|
|
80
|
+
fetch_and_parse_schema.cache_clear()
|
|
81
|
+
|
|
82
|
+
fetch_and_parse_schema("local_schemas/v1.0.0/catalog.json")
|
|
83
|
+
fetch_and_parse_schema("local_schemas/v1.0.0/catalog.json")
|
|
84
|
+
|
|
85
|
+
cache_info = fetch_and_parse_schema.cache_info()
|
|
86
|
+
assert cache_info.maxsize == 0
|
|
87
|
+
assert cache_info.hits == 0
|
|
88
|
+
assert cache_info.currsize == 0
|
|
89
|
+
finally:
|
|
90
|
+
set_schema_cache_size(DEFAULT_SCHEMA_CACHE_SIZE)
|
|
91
|
+
fetch_and_parse_schema.cache_clear()
|
|
@@ -30,3 +30,15 @@ def test_false_sys_exit_error_python():
|
|
|
30
30
|
["stac-validator", "tests/test_data/v090/items/good_item_v090.json"],
|
|
31
31
|
check=True,
|
|
32
32
|
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def test_cli_schema_cache_size_option():
|
|
36
|
+
subprocess.run(
|
|
37
|
+
[
|
|
38
|
+
"stac-validator",
|
|
39
|
+
"tests/test_data/v090/items/good_item_v090.json",
|
|
40
|
+
"--schema-cache-size",
|
|
41
|
+
"8",
|
|
42
|
+
],
|
|
43
|
+
check=True,
|
|
44
|
+
)
|
|
@@ -6,6 +6,11 @@ Description: Test the validator
|
|
|
6
6
|
import json
|
|
7
7
|
|
|
8
8
|
from stac_validator import stac_validator
|
|
9
|
+
from stac_validator.utilities import (
|
|
10
|
+
DEFAULT_SCHEMA_CACHE_SIZE,
|
|
11
|
+
fetch_and_parse_schema,
|
|
12
|
+
set_schema_cache_size,
|
|
13
|
+
)
|
|
9
14
|
|
|
10
15
|
|
|
11
16
|
def test_validate_dict_catalog_v1rc2():
|
|
@@ -65,3 +70,27 @@ def test_incorrect_validate_dict_return_method():
|
|
|
65
70
|
good_stac = json.load(f)
|
|
66
71
|
bad_stac = good_stac.pop("type", None)
|
|
67
72
|
assert stac.validate_dict(bad_stac) is False
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_validate_dict_does_not_configure_schema_cache_size():
|
|
76
|
+
try:
|
|
77
|
+
set_schema_cache_size(7)
|
|
78
|
+
fetch_and_parse_schema.cache_clear()
|
|
79
|
+
|
|
80
|
+
stac = stac_validator.StacValidate()
|
|
81
|
+
|
|
82
|
+
# Instantiating StacValidate should not change cache configuration.
|
|
83
|
+
assert fetch_and_parse_schema.cache_info().maxsize == 7
|
|
84
|
+
|
|
85
|
+
with open(
|
|
86
|
+
"tests/test_data/1rc2/extensions-collection/collection.json", "r"
|
|
87
|
+
) as f:
|
|
88
|
+
good_stac = json.load(f)
|
|
89
|
+
|
|
90
|
+
stac.validate_dict(good_stac)
|
|
91
|
+
|
|
92
|
+
# Running validate_dict should use the configured cache size, not override it.
|
|
93
|
+
assert fetch_and_parse_schema.cache_info().maxsize == 7
|
|
94
|
+
finally:
|
|
95
|
+
set_schema_cache_size(DEFAULT_SCHEMA_CACHE_SIZE)
|
|
96
|
+
fetch_and_parse_schema.cache_clear()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{stac_validator-3.10.2 → stac_validator-3.11.0}/stac_validator.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|