@@ -578,7 +578,7 @@ def is_band_asset(asset: pystac.Asset) -> bool:
578578 for asset_band in asset_bands :
579579 if asset_band .name not in get_band_names (bands ):
580580 bands .append (asset_band )
581- if collection .ext .has ("item_assets" ):
581+ if _PYSTAC_1_9_EXTENSION_INTERFACE and collection .ext .has ("item_assets" ):
582582 # TODO #575 support unordered band names and avoid conversion to a list.
583583 bands = list (_StacMetadataParser ().get_bands_from_item_assets (collection .ext .item_assets ))
584584
@@ -597,6 +597,11 @@ def is_band_asset(asset: pystac.Asset) -> bool:
597597 return metadata
598598
599599
600+ # Sniff for PySTAC extension API since version 1.9.0 (which is not available below Python 3.9)
601+ # TODO: remove this once support for Python 3.7 and 3.8 is dropped
602+ _PYSTAC_1_9_EXTENSION_INTERFACE = hasattr (pystac .Item , "ext" )
603+
604+
600605class _StacMetadataParser :
601606 """
602607 Helper to extract openEO metadata from STAC metadata resource
@@ -635,12 +640,13 @@ def _get_bands_from_item_asset(
635640 self , item_asset : pystac .extensions .item_assets .AssetDefinition
636641 ) -> Union [List [Band ], None ]:
637642 """Get bands from a STAC 'item_assets' asset definition."""
638- if item_asset .ext .has ("eo" ):
643+ if _PYSTAC_1_9_EXTENSION_INTERFACE and item_asset .ext .has ("eo" ):
639644 if item_asset .ext .eo .bands is not None :
640645 return self .get_bands_from_eo_bands (item_asset .ext .eo .bands )
641646 elif "eo:bands" in item_asset .properties :
642647 # TODO: skip this in strict mode?
643- _log .warning ("Extracting band info from 'eo:bands' metadata, but 'eo' STAC extension was not declared." )
648+ if _PYSTAC_1_9_EXTENSION_INTERFACE :
649+ _log .warning ("Extracting band info from 'eo:bands' metadata, but 'eo' STAC extension was not declared." )
644650 return self .get_bands_from_eo_bands (item_asset .properties ["eo:bands" ])
645651
646652 def get_bands_from_item_assets (
0 commit comments