Skip to content

Commit bd6bcd6

Browse files
committed
modified to pass flake8/ruff
1 parent 5d1f3a8 commit bd6bcd6

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

deep_code/tools/publish.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -333,34 +333,34 @@ def _normalize_name(name: str | None) -> str | None:
333333
def _update_base_catalog(
334334
self, catalog_path: str, item_id: str, self_href: str
335335
) -> Catalog:
336-
"""Update a base catalog by adding a link to a new item.
336+
"""Update a base catalog by adding a unique item link and a single self link.
337337
338338
Args:
339-
catalog_path: Path to the base catalog JSON file.
340-
item_id: ID of the new item (experiment or workflow).
341-
self_href: Self-href for the base catalog.
339+
catalog_path: Path to the base catalog JSON file, relative to the repo root.
340+
item_id: ID (directory name) of the new item (workflow/experiment).
341+
self_href: Absolute self-href for the base catalog.
342342
343343
Returns:
344-
Updated Catalog object.
344+
The updated PySTAC Catalog object (in-memory).
345345
"""
346346
base_catalog = Catalog.from_file(
347347
Path(self.gh_publisher.github_automation.local_clone_dir) / catalog_path
348348
)
349349

350350
item_href = f"./{item_id}/record.json"
351351

352-
# Ensure the "item" link is unique
353-
def link_href(link: Link) -> str | None:
354-
# PySTAC Link may store href in .target or .href; .get_href() resolves if base HREF set
352+
def resolve_href(link: Link) -> str | None:
353+
# PySTAC keeps raw targets; get_href() may resolve relative paths if a base HREF is set
355354
return (
356355
getattr(link, "href", None)
357356
or getattr(link, "target", None)
358357
or (link.get_href() if hasattr(link, "get_href") else None)
359358
)
360359

360+
# 1) Add the "item" link only if it's not already present
361361
has_item = any(
362-
(l.rel == "item") and (link_href(l) == item_href)
363-
for l in base_catalog.links
362+
(link.rel == "item") and (resolve_href(link) == item_href)
363+
for link in base_catalog.links
364364
)
365365
if not has_item:
366366
base_catalog.add_link(
@@ -372,17 +372,17 @@ def link_href(link: Link) -> str | None:
372372
)
373373
)
374374

375-
# Ensure there is exactly one "self" link
376-
base_catalog.links = [l for l in base_catalog.links if l.rel != "self"]
375+
# 2) Ensure there is exactly one "self" link
376+
base_catalog.links = [link for link in base_catalog.links if link.rel != "self"]
377377
base_catalog.set_self_href(self_href)
378378

379-
# deduplicate by (rel, href)
380-
seen = set()
381-
unique_links = []
382-
for l in base_catalog.links:
383-
key = (l.rel, link_href(l))
379+
# 3) Defense-in-depth: deduplicate by (rel, href)
380+
seen: set[tuple[str, str | None]] = set()
381+
unique_links: list[Link] = []
382+
for link in base_catalog.links:
383+
key = (link.rel, resolve_href(link))
384384
if key not in seen:
385-
unique_links.append(l)
385+
unique_links.append(link)
386386
seen.add(key)
387387
base_catalog.links = unique_links
388388

0 commit comments

Comments
 (0)