Skip to content

Update migrate code to handle license updates for v1.1.0 #1491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions pystac/serialization/migrate.py
Original file line number Diff line number Diff line change
@@ -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(
@@ -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


@@ -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]:
Original file line number Diff line number Diff line change
@@ -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": [
{
Original file line number Diff line number Diff line change
@@ -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": [
{
Original file line number Diff line number Diff line change
@@ -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": [
{
Original file line number Diff line number Diff line change
@@ -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": [
{
Original file line number Diff line number Diff line change
@@ -46,5 +46,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -46,5 +46,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -46,5 +46,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -46,5 +46,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -47,5 +47,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -53,5 +53,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -56,5 +56,5 @@
]
}
},
"license": "various"
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -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",
2 changes: 1 addition & 1 deletion tests/data-files/collections/multi-extent.json
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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",
2 changes: 1 addition & 1 deletion tests/data-files/projection/collection-with-summaries.json
Original file line number Diff line number Diff line change
@@ -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
@@ -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
@@ -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": {
@@ -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",
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",
2 changes: 1 addition & 1 deletion tests/data-files/view/collection-with-summaries.json
Original file line number Diff line number Diff line change
@@ -65,5 +65,5 @@
]
}
},
"license": "proprietary"
"license": "other"
}
Original file line number Diff line number Diff line change
@@ -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
@@ -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/"
@@ -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:
@@ -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
@@ -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(