This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/main by this push:
new 296b1e8 Add a helper to generate lists of links
296b1e8 is described below
commit 296b1e869f6b422d98759c5ab91b8c0aefbf554d
Author: Sean B. Palmer <[email protected]>
AuthorDate: Mon Oct 27 16:30:05 2025 +0000
Add a helper to generate lists of links
---
atr/get/distribution.py | 6 +--
atr/htm.py | 107 +++++++++++++++++++++++++-----------------------
atr/routes/root.py | 30 ++++++--------
3 files changed, 69 insertions(+), 74 deletions(-)
diff --git a/atr/get/distribution.py b/atr/get/distribution.py
index aacd13d..29a737d 100644
--- a/atr/get/distribution.py
+++ b/atr/get/distribution.py
@@ -63,11 +63,7 @@ async def list_get(session: web.Committer, project: str,
version: str) -> str:
block.p["Here are all of the distributions recorded for this release."]
block.p[record_a_distribution]
# Table of contents
- ul_toc = htm.Block(htm.ul)
- for dist in distributions:
- a = htm.a(href=f"#distribution-{dist.identifier}")[dist.title]
- ul_toc.li[a]
- block.append(ul_toc)
+ block.append(htm.ul_links(*[(f"#distribution-{dist.identifier}",
dist.title) for dist in distributions]))
## Distributions
block.h2["Distributions"]
diff --git a/atr/htm.py b/atr/htm.py
index ca35ce1..b2c5c76 100644
--- a/atr/htm.py
+++ b/atr/htm.py
@@ -27,12 +27,40 @@ if TYPE_CHECKING:
from collections.abc import Callable
+type Element = htpy.Element
+
+a = htpy.a
+button = htpy.button
+code = htpy.code
+details = htpy.details
+div = htpy.div
+em = htpy.em
+form = htpy.form
+h1 = htpy.h1
+h2 = htpy.h2
+h3 = htpy.h3
+li = htpy.li
+p = htpy.p
+pre = htpy.pre
+script = htpy.script
+span = htpy.span
+strong = htpy.strong
+summary = htpy.summary
+table = htpy.table
+tbody = htpy.tbody
+td = htpy.td
+th = htpy.th
+thead = htpy.thead
+tr = htpy.tr
+ul = htpy.ul
+
+
class BlockElementGetable:
- def __init__(self, block: Block, element: htpy.Element):
+ def __init__(self, block: Block, element: Element):
self.block = block
self.element = element
- def __getitem__(self, *items: htpy.Element | str | tuple[htpy.Element |
str, ...]) -> htpy.Element:
+ def __getitem__(self, *items: Element | str | tuple[Element | str, ...])
-> Element:
element = self.element[*items]
for i in range(len(self.block.elements) - 1, -1, -1):
if self.block.elements[i] is self.element:
@@ -43,7 +71,7 @@ class BlockElementGetable:
class BlockElementCallable:
- def __init__(self, block: Block, constructor: Callable[..., htpy.Element]):
+ def __init__(self, block: Block, constructor: Callable[..., Element]):
self.block = block
self.constructor = constructor
@@ -52,7 +80,7 @@ class BlockElementCallable:
self.block.append(element)
return BlockElementGetable(self.block, element)
- def __getitem__(self, *items: Any) -> htpy.Element:
+ def __getitem__(self, *items: Any) -> Element:
element = self.constructor()[*items]
self.block.append(element)
return element
@@ -61,9 +89,9 @@ class BlockElementCallable:
class Block:
__match_args__ = ("elements",)
- def __init__(self, element: htpy.Element | None = None, *elements:
htpy.Element):
+ def __init__(self, element: Element | None = None, *elements: Element):
self.element = element
- self.elements: list[htpy.Element | str] = list(elements)
+ self.elements: list[Element | str] = list(elements)
def __str__(self) -> str:
return f"{self.element}{self.elements}"
@@ -71,7 +99,7 @@ class Block:
def __repr__(self) -> str:
return f"{self.element!r}[*{self.elements!r}]"
- def append(self, eob: Block | htpy.Element) -> None:
+ def append(self, eob: Block | Element) -> None:
match eob:
case Block():
# TODO: Does not support separator
@@ -79,18 +107,18 @@ class Block:
case htpy.Element():
self.elements.append(eob)
- def collect(self, separator: str | None = None, depth: int = 1) ->
htpy.Element:
+ def collect(self, separator: str | None = None, depth: int = 1) -> Element:
src = log.caller_name(depth=depth)
if separator is not None:
- separated: list[htpy.Element | str] = [separator] * (2 *
len(self.elements) - 1)
+ separated: list[Element | str] = [separator] * (2 *
len(self.elements) - 1)
separated[::2] = self.elements
elements = separated
else:
elements = self.elements
if self.element is None:
- return htpy.div(data_src=src)[*elements]
+ return div(data_src=src)[*elements]
new_element = self.element.__class__(
self.element._name,
@@ -106,91 +134,68 @@ class Block:
@property
def a(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.a)
+ return BlockElementCallable(self, a)
@property
def code(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.code)
+ return BlockElementCallable(self, code)
@property
def details(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.details)
+ return BlockElementCallable(self, details)
@property
def div(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.div)
+ return BlockElementCallable(self, div)
@property
def h1(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.h1)
+ return BlockElementCallable(self, h1)
@property
def h2(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.h2)
+ return BlockElementCallable(self, h2)
@property
def h3(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.h3)
+ return BlockElementCallable(self, h3)
@property
def li(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.li)
+ return BlockElementCallable(self, li)
@property
def p(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.p)
+ return BlockElementCallable(self, p)
@property
def pre(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.pre)
+ return BlockElementCallable(self, pre)
@property
def span(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.span)
+ return BlockElementCallable(self, span)
@property
def strong(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.strong)
+ return BlockElementCallable(self, strong)
@property
def summary(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.summary)
+ return BlockElementCallable(self, summary)
@property
def table(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.table)
+ return BlockElementCallable(self, table)
def text(self, text: str) -> None:
self.elements.append(text)
@property
def ul(self) -> BlockElementCallable:
- return BlockElementCallable(self, htpy.ul)
-
+ return BlockElementCallable(self, ul)
-type Element = htpy.Element
-a = htpy.a
-button = htpy.button
-code = htpy.code
-details = htpy.details
-div = htpy.div
-em = htpy.em
-form = htpy.form
-h1 = htpy.h1
-h2 = htpy.h2
-h3 = htpy.h3
-li = htpy.li
-p = htpy.p
-pre = htpy.pre
-script = htpy.script
-span = htpy.span
-strong = htpy.strong
-summary = htpy.summary
-table = htpy.table
-tbody = htpy.tbody
-td = htpy.td
-th = htpy.th
-thead = htpy.thead
-tr = htpy.tr
-ul = htpy.ul
+def ul_links(*items: tuple[str, str]) -> Element:
+ li_items = [li[a(href=item[0])[item[1]]] for item in items]
+ return ul[*li_items]
diff --git a/atr/routes/root.py b/atr/routes/root.py
index 0645ea7..2744e15 100644
--- a/atr/routes/root.py
+++ b/atr/routes/root.py
@@ -45,25 +45,19 @@ _POLICIES: Final = htm.div[
any of the following policies."""
],
htm.h2["Standard ASF policies"],
- htm.ul[
-
htm.li[htm.a(href="https://www.apache.org/legal/release-policy.html")["Release
policy"],],
-
htm.li[htm.a(href="https://www.apache.org/legal/src-headers.html")["Source
headers"],],
- htm.li[htm.a(href="https://www.apache.org/legal/resolved.html")["Third
party license"],],
-
htm.li[htm.a(href="https://www.apache.org/foundation/voting.html")["Voting
process"],],
-
htm.li[htm.a(href="https://infra.apache.org/release-publishing.html")["Release
process"],],
- ],
+ htm.ul_links(
+ ("https://www.apache.org/legal/release-policy.html", "Release policy"),
+ ("https://www.apache.org/legal/src-headers.html", "Source headers"),
+ ("https://www.apache.org/legal/resolved.html", "Third party license"),
+ ("https://www.apache.org/foundation/voting.html", "Voting process"),
+ ("https://infra.apache.org/release-publishing.html", "Release
process"),
+ ),
htm.h2["Additional incubator policies"],
- htm.ul[
- htm.li[
-
htm.a(href="https://incubator.apache.org/policy/incubation.html#releases")["Incubator
release process"],
- ],
- htm.li[
-
htm.a(href="https://incubator.apache.org/guides/releasemanagement.html#podling_constraints")[
- "Incubator constraints"
- ],
- ],
-
htm.li[htm.a(href="https://incubator.apache.org/policy/incubation.html#disclaimers")["Incubation
disclaimer"],],
- ],
+ htm.ul_links(
+ ("https://incubator.apache.org/policy/incubation.html#releases",
"Incubator release process"),
+
("https://incubator.apache.org/guides/releasemanagement.html#podling_constraints",
"Incubator constraints"),
+ ("https://incubator.apache.org/policy/incubation.html#disclaimers",
"Incubation disclaimer"),
+ ),
]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]