Skip to content

Commit e90b945

Browse files
authored
Access scientific extension on item using .ext (#1496)
* Access scientific extension on item using .ext * Update changelog - delinquent
1 parent 1cf7f3f commit e90b945

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
- Use [uv](https://github.com/astral-sh/uv) for development dependencies and docs ([#1439](https://github.com/stac-utils/pystac/pull/1439))
1313
- Correctly detect absolute file path ref on windows, reflecting change in python 3.13 ([#1475](https://github.com/stac-utils/pystac/pull/14750)) (only effects python 3.13)
1414
- Deprecated `ItemAssetExtension` ([#1476](https://github.com/stac-utils/pystac/pull/1476))
15+
- Update Projection Extension to version 2 - proj:epsg -> proj:code ([#1287](https://github.com/stac-utils/pystac/pull/1287))
16+
- Update migrate code to handle license changes in STAC spec 1.1.0 ([#1491](https://github.com/stac-utils/pystac/pull/1491))
17+
- Allow links to have `file://` prefix - but don't write them that way by default ([#1489](https://github.com/stac-utils/pystac/pull/1489))
1518

1619
### Fixed
1720

1821
- Use `application/geo+json` for `item` links ([#1495](https://github.com/stac-utils/pystac/pull/1495))
22+
- Includes the scientific extension in Item's ext interface ([#1496](https://github.com/stac-utils/pystac/pull/1496))
1923

2024
## [v1.11.0] - 2024-09-26
2125

pystac/extensions/ext.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,10 @@ def sar(self) -> SarExtension[Item]:
180180
def sat(self) -> SatExtension[Item]:
181181
return SatExtension.ext(self.stac_object)
182182

183+
@property
184+
def sci(self) -> ScientificExtension[Item]:
185+
return ScientificExtension.ext(self.stac_object)
186+
183187
@property
184188
def storage(self) -> StorageExtension[Item]:
185189
return StorageExtension.ext(self.stac_object)

tests/extensions/test_scientific.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import pystac
99
from pystac import ExtensionTypeError
10+
from pystac.errors import ExtensionNotImplemented
1011
from pystac.extensions import scientific
1112
from pystac.extensions.scientific import (
1213
Publication,
@@ -494,3 +495,26 @@ def test_summaries_adds_uri(self) -> None:
494495
self.assertNotIn(
495496
ScientificExtension.get_schema_uri(), collection.stac_extensions
496497
)
498+
499+
500+
@pytest.fixture
501+
def ext_item() -> pystac.Item:
502+
path = TestCases.get_path("data-files/scientific/item.json")
503+
return pystac.Item.from_file(path)
504+
505+
506+
def test_ext_syntax(ext_item: pystac.Item) -> None:
507+
assert ext_item.ext.sci.doi == "10.5061/dryad.s2v81.2/27.2"
508+
509+
510+
def test_ext_syntax_remove(ext_item: pystac.Item) -> None:
511+
ext_item.ext.remove("sci")
512+
assert ext_item.ext.has("sci") is False
513+
with pytest.raises(ExtensionNotImplemented):
514+
ext_item.ext.sci
515+
516+
517+
def test_ext_syntax_add(item: pystac.Item) -> None:
518+
item.ext.add("sci")
519+
assert item.ext.has("sci") is True
520+
assert isinstance(item.ext.sci, ScientificExtension)

0 commit comments

Comments
 (0)