Enable normalize_hrefs to use flexible layouts. #219
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds the
pystac.layout
module which enables STACs to layout their HREFs in several ways. Prior to this change,normalize_href
would always generate object HREFs according to the best practices documentation - catalogs, collections and items would always have their own directory, with no additional or alternate file structure allowed.normalize_hrefs now takes an optional
HrefLayoutStrategy
that can alter its behavior. The default keeps the existing functionality through theBestPracticesLayoutStrategy
. Users can supply functions to modify the behavior of one or all of Catalog, Collection or Item HREFs, with a fallback to the default strategy. Additionally there is aTemplateLayoutStrategy
which allows users to supply a template string to determine HREFs based on properties of the stac objects.This templating is also used in a new method on catalogs,
generate_subcatalogs
. This method uses the same templating logic to generate subdirectories in between an item and its existing parent, which allows for logical grouping of items into subcatalogs based on shared property values.Additionally, normalize_hrefs was rewritten in such a way that made the recursive
fully_resolve
unnecessary. The repeated calls to fully_resolve caused unnecessary walks through the catalog, so this change should speed up calls to normalize_hrefs. The method was removed and replaced withresolve_links
, which resolves STAC object links (as determined by the_object_links()
method on the STAC object, which can be contributed to by extensions) for only that STAC object and does not recurse through the links.normalize_hrefs
was removed from Item, as the method is intended for Catalogs and Collections.Also included are the addition of two convenience methods -
Catalog.add_children
andItem.get_collection
.Catatlog.clear_children
's behavior changes so that the children's parent and root was reset to make it consistent withCatalog.remove_child
.Fixes #151