Skip to content
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

Add an AsIsLayoutStrategy #919

Merged
merged 2 commits into from
Jan 25, 2023
Merged

Add an AsIsLayoutStrategy #919

merged 2 commits into from
Jan 25, 2023

Conversation

gadomski
Copy link
Member

@gadomski gadomski commented Nov 10, 2022

Related Issue(s):

Description:

Currently, it's impossible to use Catalog.add_item but preserve the self_href of the item. This PR adds a new layout that simply preserves the existing href, or raises a ValueError if one isn't set.

I don't love the name AsIsLayoutStrategy, so improving suggestions are welcome! Other names I considered:

  • NoopLayoutStrategy
  • PassthroughLayoutStrategy

cc @kylemann16

PR Checklist:

  • Code is formatted (run pre-commit run --all-files)
  • Tests pass (run scripts/test)
  • Documentation has been updated to reflect changes, if applicable
  • This PR maintains or improves overall codebase code coverage.
  • Changes are added to the CHANGELOG. See the docs for information about adding to the changelog.

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Base: 90.12% // Head: 90.08% // Decreases project coverage by -0.04% ⚠️

Coverage data is based on head (01b9467) compared to base (f44de3c).
Patch coverage: 62.50% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #919      +/-   ##
==========================================
- Coverage   90.12%   90.08%   -0.04%     
==========================================
  Files          47       47              
  Lines        6063     6079      +16     
  Branches      909      912       +3     
==========================================
+ Hits         5464     5476      +12     
- Misses        420      422       +2     
- Partials      179      181       +2     
Impacted Files Coverage Δ
pystac/layout.py 87.86% <62.50%> (-2.14%) ⬇️
pystac/stac_object.py 91.89% <0.00%> (+1.08%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@kylemann16
Copy link

@gadomski Sorry for the late response here, but thanks for looking at this. Those names look good to me, maybe other options would beExplicitUrlLayoutStrategy, UrlNoopLayoutStrategy, or something to indicate that the user is handling all links themselves?

@gadomski gadomski self-assigned this Dec 30, 2022
@gadomski gadomski added this to the 1.7 milestone Dec 30, 2022
@gadomski
Copy link
Member Author

UrlNoopLayoutStrategy

Yeah, I thought about NoopLayoutStrategy as well -- but then thought that it looked funny :-). I don't really have a strong inclination one way or the other, so will leave it to a reviewer to suggest/approve one of these (or other) options.

@gadomski gadomski force-pushed the issues/875-as-is-layout branch from a7c04d8 to 01b9467 Compare January 23, 2023 16:17
@gadomski gadomski requested a review from pjhartzell January 23, 2023 16:17
@pjhartzell
Copy link
Collaborator

pjhartzell commented Jan 25, 2023

Side note: The add_item() method on the Catalog class indicates the strategy parameter is optional, but it really is required with a default of BestPracticesLayoutStrategy (see the if strategy is None: line). Also, the strategy parameter is not given in the docstring Args list, adding another layer of ambiguity here.

pystac/pystac/catalog.py

Lines 277 to 297 in ea68043

def add_item(
self,
item: "Item_Type",
title: Optional[str] = None,
strategy: Optional[HrefLayoutStrategy] = None,
) -> None:
"""Adds a link to an :class:`~pystac.Item`.
This method will set the item's parent to this object, and its root to
this Catalog's root.
Args:
item : The item to add.
title : Optional title to give to the :class:`~pystac.Link`
"""
# Prevent typo confusion
if isinstance(item, pystac.Catalog):
raise pystac.STACError("Cannot add catalog as item. Use add_child instead.")
if strategy is None:
strategy = BestPracticesLayoutStrategy()

Also, it seems logical for a strategy parameter to be added to the Catalog.add_items() method.

Similar thoughts apply to the Collection class add_item() method.

Copy link
Collaborator

@pjhartzell pjhartzell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good with caveat (in separate PR comment) about the need to better expose the default layout strategy.

@gadomski
Copy link
Member Author

I opened #965 to capture the need to align the function signatures.

@gadomski gadomski enabled auto-merge (rebase) January 25, 2023 16:00
auto-merge was automatically disabled January 25, 2023 16:02

Rebase failed

This simply passes through the existing hrefs, raising a value error if one
doesn't exist.
@gadomski gadomski force-pushed the issues/875-as-is-layout branch from e000b0a to b2ce6d0 Compare January 25, 2023 16:39
@gadomski gadomski enabled auto-merge (rebase) January 25, 2023 16:39
@gadomski gadomski merged commit c63f475 into main Jan 25, 2023
@gadomski gadomski deleted the issues/875-as-is-layout branch January 25, 2023 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add_item changes explicitly set links to fit the assumed structure
4 participants