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

Let non-hierarchical links to hierachical elements be relative paths for self-contained catalogs #1169

Merged
merged 12 commits into from
Jun 27, 2023

Conversation

jpolchlo
Copy link
Contributor

@jpolchlo jpolchlo commented Jun 21, 2023

Related Issue(s):
Closes #1112

Description:
This is an attempt to address the unexpected and maybe undesirable behavior identified in #1112. For this, we consider the case of a catalog tree which is defined using hierarchical links. When serialized out as a self-contained catalog, using to_dict yields relative links for all elements. Now, when we add additional links that have non-hierarchical rel types, but refer to entities which are in the hierarchical tree, the non-standard links are serialized with absolute hrefs.

For the following tree

flowchart TD
    root -- child --> A
    root --child--> B
    A -. sibling .-> B
Loading

When we serialize A, we want to see

{
    "type": "Catalog",
    "id": "a",
    "stac_version": "1.0.0",
    "description": "a",
    "links": [
        {
            "rel": "root",
            "href": "../catalog.json",
            "type": "application/json"
        },
        {
            "rel": "sibling",
            "href": "../b/catalog.json"
        },
        {
            "rel": "parent",
            "href": "../catalog.json",
            "type": "application/json"
        },
        {
            "rel": "self",
            "href": "/opt/data/stac/a/catalog.json",
            "type": "application/json"
        }
    ]
}

because the referent of the sibling link has been serialized elsewhere in the catalog tree using a relative link. This is the result that is delivered by this PR. Whether this should be the default behavior is a separate concern, and we can have that discussion below.

PR Checklist:

  • pre-commit hooks pass locally
  • 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
Copy link

codecov bot commented Jun 21, 2023

Codecov Report

Patch coverage: 95.23% and project coverage change: +0.01 🎉

Comparison is base (ba74fd5) 91.99% compared to head (27b733c) 92.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1169      +/-   ##
==========================================
+ Coverage   91.99%   92.00%   +0.01%     
==========================================
  Files          51       51              
  Lines        6792     6808      +16     
  Branches     1000     1007       +7     
==========================================
+ Hits         6248     6264      +16     
  Misses        368      368              
  Partials      176      176              
Impacted Files Coverage Δ
pystac/link.py 91.54% <80.00%> (+0.04%) ⬆️
pystac/stac_object.py 95.13% <100.00%> (+0.34%) ⬆️
pystac/validation/local_validator.py 95.23% <100.00%> (ø)

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

Copy link
Member

@gadomski gadomski left a comment

Choose a reason for hiding this comment

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

Can you add a test case that mirrors the example in the PR description? Thanks!

pystac/link.py Outdated Show resolved Hide resolved
@jpolchlo jpolchlo changed the title Feature/non hierarchical links Let non-hierarchical links to hierachical elements be relative paths for self-contained catalogs Jun 22, 2023
@jpolchlo jpolchlo force-pushed the feature/non-hierarchical-links branch from 1cfea0c to 2fafeaa Compare June 23, 2023 18:06
@jpolchlo jpolchlo requested a review from gadomski June 23, 2023 18:10
pystac/stac_object.py Outdated Show resolved Hide resolved
pystac/stac_object.py Outdated Show resolved Hide resolved
@jpolchlo jpolchlo force-pushed the feature/non-hierarchical-links branch from 2fafeaa to 1cda6f0 Compare June 26, 2023 20:37
@jpolchlo jpolchlo force-pushed the feature/non-hierarchical-links branch 2 times, most recently from b275f65 to c49c9d9 Compare June 27, 2023 15:09
@jpolchlo jpolchlo force-pushed the feature/non-hierarchical-links branch from c49c9d9 to ed1f446 Compare June 27, 2023 15:14
@jpolchlo jpolchlo requested a review from gadomski June 27, 2023 15:20
pystac/stac_object.py Outdated Show resolved Hide resolved
pystac/stac_object.py Outdated Show resolved Hide resolved
@gadomski gadomski enabled auto-merge June 27, 2023 22:23
@gadomski gadomski added this pull request to the merge queue Jun 27, 2023
Merged via the queue into stac-utils:main with commit 5b6622c Jun 27, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Adding custom links between sibling catalogs creates absolute HREFs
2 participants