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-release.git
The following commit(s) were added to refs/heads/main by this push:
new 57346e0 Add a distribution page with a simple form
57346e0 is described below
commit 57346e0d582da2d6d6f9987b7d40426f5ed55f48
Author: Sean B. Palmer <[email protected]>
AuthorDate: Tue Aug 5 20:27:01 2025 +0100
Add a distribution page with a simple form
---
atr/forms.py | 2 +-
atr/routes/distribute.py | 115 +++++++++++++++++++++++++++++++++++++++++++++++
atr/routes/modules.py | 1 +
3 files changed, 117 insertions(+), 1 deletion(-)
diff --git a/atr/forms.py b/atr/forms.py
index 04150e7..7c7a2c1 100644
--- a/atr/forms.py
+++ b/atr/forms.py
@@ -362,7 +362,7 @@ def string(
return wtforms.StringField(label, validators=validators, **kwargs)
-def submit(label: str, **kwargs: Any) -> wtforms.SubmitField:
+def submit(label: str = "Submit", **kwargs: Any) -> wtforms.SubmitField:
return wtforms.SubmitField(label, **kwargs)
diff --git a/atr/routes/distribute.py b/atr/routes/distribute.py
new file mode 100644
index 0000000..448c544
--- /dev/null
+++ b/atr/routes/distribute.py
@@ -0,0 +1,115 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+from __future__ import annotations
+
+import json
+from typing import Final
+
+import htpy
+import quart
+
+import atr.forms as forms
+import atr.routes as routes
+import atr.template as template
+
+_PLATFORM_OPTIONS: Final[list[tuple[str, str]]] = [
+ ("maven", "Maven Central"),
+ ("pypi", "PyPI"),
+ ("npm", "npm"),
+ ("docker", "Docker"),
+ ("artifacthub", "ArtifactHub (Helm)"),
+ ("github", "GitHub"),
+]
+
+
+class DistributeForm(forms.Typed):
+ platform = forms.select("Platform", choices=_PLATFORM_OPTIONS)
+ owner_namespace = forms.string(
+ "Owner or Namespace",
+ optional=True,
+ placeholder="E.g. com.example or @scope or library",
+ description="Who owns or names the package (Maven groupId, npm @scope,
"
+ "Docker namespace, GitHub owner, ArtifactHub repo). Leave blank if not
used.",
+ )
+ package = forms.string("Package", placeholder="E.g. artifactId or
package-name")
+ version = forms.string("Version", placeholder="E.g. 1.2.3 or v1.2.3")
+ submit = forms.submit()
+
+
[email protected]("/distribute/<project>/<version>", methods=["GET"])
+async def distribute(session: routes.CommitterSession, project: str, version:
str) -> str:
+ return await _distribute_page(project=project, version=version)
+
+
[email protected]("/distribute/<project>/<version>", methods=["POST"])
+async def distribute_post(session: routes.CommitterSession, project: str,
version: str) -> str:
+ form = await DistributeForm.create_form()
+ if await form.validate():
+ return await _distribute_post_validated(form)
+ # TODO: Show errors
+ return await _distribute_page(project=project, version=version)
+
+
+async def _distribute_page(*, project: str, version: str) -> str:
+ form = await DistributeForm.create_form(data={"package": project,
"version": version})
+ form_content = forms.render_columns(form, action=quart.request.path)
+ help_text = htpy.p[
+ htpy.strong["Owner or Namespace"],
+ """: this field in the form below describes who owns or names the
+ package (Maven groupId, npm @scope, Docker namespace, GitHub owner,
+ ArtifactHub repo). Leave blank if not used.""",
+ ]
+ content = _page("Distribute", htpy.div[help_text, form_content])
+ return await template.blank("Distribute", content=content)
+
+
+async def _distribute_post_validated(form: DistributeForm) -> str:
+ data = {
+ "platform": form.platform.data,
+ "owner_namespace": form.owner_namespace.data,
+ "package": form.package.data,
+ "version": form.version.data,
+ }
+ table = _distribute_post_table(data)
+ pre_json_results = htpy.pre[json.dumps(data, indent=2)]
+ content = _page(
+ "Submitted values",
+ htpy.div[
+ table,
+ htpy.h2["As JSON"],
+ pre_json_results,
+ ],
+ )
+ return await template.blank("Distribution Submitted", content=content)
+
+
+def _distribute_post_table(data: dict[str, str]) -> htpy.Element:
+ def row(label: str, value: str) -> htpy.Element:
+ return htpy.tr[htpy.th[label], htpy.td[value]]
+
+ tbody = htpy.tbody[
+ row("Platform", data["platform"]),
+ row("Owner or Namespace", data["owner_namespace"] or "(blank)"),
+ row("Package", data["package"]),
+ row("Version", data["version"]),
+ ]
+ return htpy.table(".table.table-striped.table-bordered")[tbody]
+
+
+def _page(title_str: str, content: htpy.Element) -> htpy.Element:
+ return htpy.div[htpy.h1[title_str], content]
diff --git a/atr/routes/modules.py b/atr/routes/modules.py
index 0f9c9e6..6ea3056 100644
--- a/atr/routes/modules.py
+++ b/atr/routes/modules.py
@@ -20,6 +20,7 @@ import atr.routes.announce as announce
import atr.routes.candidate as candidate
import atr.routes.committees as committees
import atr.routes.compose as compose
+import atr.routes.distribute as distribute
import atr.routes.download as download
import atr.routes.draft as draft
import atr.routes.file as file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]