Skip to content

Commit

Permalink
Update migrate code to handle license updates for v1.1.0 (#1491)
Browse files Browse the repository at this point in the history
* Migrate license from 'various' and 'proprietary' to 'other'

* Update license in 1.1.0 test files

* Remove item-assets extension from v1.1.0 files
  • Loading branch information
jsignell authored Jan 12, 2025
1 parent 24e16e4 commit ab747be
Show file tree
Hide file tree
Showing 32 changed files with 53 additions and 53 deletions.
23 changes: 7 additions & 16 deletions pystac/serialization/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _migrate_catalog(
d: dict[str, Any], version: STACVersionID, info: STACJSONDescription
) -> None:
d["type"] = pystac.STACObjectType.CATALOG
_migrate_license(d)


def _migrate_collection_summaries(
Expand All @@ -38,25 +39,20 @@ def _migrate_collection(
d: dict[str, Any], version: STACVersionID, info: STACJSONDescription
) -> None:
d["type"] = pystac.STACObjectType.COLLECTION
_migrate_license(d)
_migrate_collection_summaries(d, version, info)


def _migrate_item(
d: dict[str, Any], version: STACVersionID, info: STACJSONDescription
) -> None:
# No migrations necessary for supported STAC versions (>=0.8)
pass
_migrate_license(d["properties"])


# Extensions
def _migrate_item_assets(
d: dict[str, Any], version: STACVersionID, info: STACJSONDescription
) -> set[str] | None:
if version < "1.0.0-beta.2":
if info.object_type == pystac.STACObjectType.COLLECTION:
if "assets" in d:
d["item_assets"] = d["assets"]
del d["assets"]
def _migrate_license(d: dict[str, Any]) -> None:
if d.get("license") in ["various", "proprietary"]:
d["license"] = "other"

return None


Expand Down Expand Up @@ -158,11 +154,6 @@ def _get_removed_extension_migrations() -> (
}


# TODO: Item Assets
def _get_extension_renames() -> dict[str, str]:
return {"asset": "item-assets"}


def migrate_to_latest(
json_dict: dict[str, Any], info: STACJSONDescription
) -> dict[str, Any]:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://schemas.stacspec.org/v1.0.0-beta.2/extensions/item-assets/json-schema/schema.json"
"https://stac-extensions.github.io/eo/v1.1.0/schema.json"
],
"providers": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
"https://stac-extensions.github.io/eo/v1.1.0/schema.json"
],
"providers": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
"https://stac-extensions.github.io/eo/v1.1.0/schema.json"
],
"providers": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
}
],
"stac_extensions": [
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
"https://stac-extensions.github.io/eo/v1.1.0/schema.json"
],
"providers": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/catalogs/test-case-4/acc/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@
]
}
},
"license": "various"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/catalogs/test-case-4/dar/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@
]
}
},
"license": "various"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/catalogs/test-case-4/kam/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
]
}
},
"license": "various"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/catalogs/test-case-4/mon/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@
]
}
},
"license": "various"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/catalogs/test-case-4/nia/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@
]
}
},
"license": "various"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/catalogs/test-case-4/ptn/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@
]
}
},
"license": "various"
"license": "other"
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
]
}
},
"license": "proprietary",
"license": "other",
"stac_extensions": [
"https://stac-extensions.github.io/projection/v1.1.0/schema.json",
"https://stac-extensions.github.io/eo/v1.1.0/schema.json",
Expand Down
2 changes: 1 addition & 1 deletion tests/data-files/collections/multi-extent.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/collections/with-assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/invalid/shared-id/test/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
1 change: 0 additions & 1 deletion tests/data-files/item-assets/example-landsat8.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"stac_version": "1.1.0",
"stac_extensions": [
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
"eo"
],
"type": "Collection",
Expand Down
2 changes: 1 addition & 1 deletion tests/data-files/projection/collection-with-summaries.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
2 changes: 1 addition & 1 deletion tests/data-files/storage/collection-naip.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
3 changes: 1 addition & 2 deletions tests/data-files/table/collection-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"description": "desc",
"links": [],
"stac_extensions": [
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
"https://stac-extensions.github.io/table/v1.2.0/schema.json"
],
"extent": {
Expand All @@ -28,7 +27,7 @@
]
}
},
"license": "proprietary",
"license": "other",
"item_assets": {},
"table:columns": []
}
1 change: 0 additions & 1 deletion tests/data-files/table/collection.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"stac_version": "1.1.0",
"stac_extensions": [
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
"https://stac-extensions.github.io/table/v1.2.0/schema.json"
],
"type": "Collection",
Expand Down
1 change: 0 additions & 1 deletion tests/data-files/table/table-collection.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"stac_version": "1.1.0",
"stac_extensions": [
"https://stac-extensions.github.io/item-assets/v1.0.0/schema.json",
"https://stac-extensions.github.io/table/v1.2.0/schema.json"
],
"type": "Collection",
Expand Down
2 changes: 1 addition & 1 deletion tests/data-files/view/collection-with-summaries.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
21 changes: 19 additions & 2 deletions tests/serialization/test_migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def test_migrates_added_extension(self) -> None:
assert view_ext.sun_elevation, 58.8
assert view_ext.off_nadir, 1

def test_migrates_renamed_extension(self) -> None:
def test_migrates_removes_extension(self) -> None:
collection = pystac.Collection.from_file(
TestCases.get_path(
"data-files/examples/0.9.0/extensions/asset/"
Expand All @@ -78,7 +78,8 @@ def test_migrates_renamed_extension(self) -> None:
assert ItemAssetsExtension.get_schema_uri() not in collection.stac_extensions
assert not ItemAssetsExtension.has_extension(collection)
assert "item_assets" in collection.extra_fields
assert collection.item_assets

assert collection.stac_extensions == []
assert collection.item_assets["thumbnail"].title == "Thumbnail"

def test_migrates_pre_1_0_0_rc1_stats_summary(self) -> None:
Expand Down Expand Up @@ -112,3 +113,19 @@ def test_migrate_works_even_if_stac_extensions_is_null(
collection_dict["stac_extensions"] = None

pystac.Collection.from_dict(collection_dict, migrate=True)


def test_migrate_updates_license_from_various() -> None:
path = TestCases.get_path("data-files/examples/1.0.0/collectionless-item.json")

item = pystac.Item.from_file(path)
assert item.properties["license"] == "other"


def test_migrate_updates_license_from_proprietary() -> None:
path = TestCases.get_path(
"data-files/examples/1.0.0/collection-only/collection.json"
)

collection = pystac.Collection.from_file(path)
assert collection.license == "other"
2 changes: 1 addition & 1 deletion tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def test_self_contained_catalog_collection_item_links(self) -> None:
spatial=pystac.SpatialExtent([[-180.0, -90.0, 180.0, 90.0]]),
temporal=pystac.TemporalExtent([[datetime(2021, 11, 1), None]]),
),
license="proprietary",
license="other",
)

item = pystac.Item(
Expand Down

0 comments on commit ab747be

Please sign in to comment.