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 ba948c5  Move collected routes to a separate module
ba948c5 is described below

commit ba948c59a9d9763901f4b22564761ab6a4c77558
Author: Sean B. Palmer <[email protected]>
AuthorDate: Thu Mar 27 14:07:25 2025 +0200

    Move collected routes to a separate module
---
 atr/routes/__init__.py              | 26 --------------------------
 atr/routes/modules.py               | 27 +++++++++++++++++++++++++++
 atr/server.py                       | 15 ++++++---------
 atr/templates/includes/sidebar.html |  8 ++++----
 atr/templates/index.html            |  2 +-
 atr/templates/keys-review.html      |  8 ++++----
 pyproject.toml                      |  1 +
 7 files changed, 43 insertions(+), 44 deletions(-)

diff --git a/atr/routes/__init__.py b/atr/routes/__init__.py
index 16fe06f..e0a8f60 100644
--- a/atr/routes/__init__.py
+++ b/atr/routes/__init__.py
@@ -33,7 +33,6 @@ import quart
 
 if TYPE_CHECKING:
     from collections.abc import Awaitable, Callable, Coroutine
-    from types import ModuleType
 
     import werkzeug.datastructures as datastructures
 
@@ -406,28 +405,3 @@ def _authentication_failed() -> NoReturn:
     """Handle authentication failure with an exception."""
     # NOTE: This is a separate function to fix a problem with analysis flow in 
mypy
     raise base.ASFQuartException("Not authenticated", errorcode=401)
-
-
-def modules() -> dict[str, ModuleType]:
-    """Return a dictionary of all modules in the current package."""
-    import atr.routes.candidate as candidate
-    import atr.routes.candidate_draft as candidate_draft
-    import atr.routes.committees as committees
-    import atr.routes.dev as dev
-    import atr.routes.download as download
-    import atr.routes.keys as keys
-    import atr.routes.projects as projects
-    import atr.routes.release as release
-    import atr.routes.root as root
-
-    return {
-        "candidate": candidate,
-        "candidate_draft": candidate_draft,
-        "committees": committees,
-        "dev": dev,
-        "download": download,
-        "keys": keys,
-        "projects": projects,
-        "release": release,
-        "root": root,
-    }
diff --git a/atr/routes/modules.py b/atr/routes/modules.py
new file mode 100644
index 0000000..2631840
--- /dev/null
+++ b/atr/routes/modules.py
@@ -0,0 +1,27 @@
+# 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.
+
+# These are imported for their side effects and for access in templates
+import atr.routes.candidate as candidate
+import atr.routes.candidate_draft as candidate_draft
+import atr.routes.committees as committees
+import atr.routes.dev as dev
+import atr.routes.download as download
+import atr.routes.keys as keys
+import atr.routes.projects as projects
+import atr.routes.release as release
+import atr.routes.root as root
diff --git a/atr/server.py b/atr/server.py
index 568ecf5..c5cd875 100644
--- a/atr/server.py
+++ b/atr/server.py
@@ -20,6 +20,7 @@
 import logging
 import os
 from collections.abc import Iterable
+from types import ModuleType
 from typing import Any
 
 import asfquart
@@ -55,11 +56,9 @@ class ApiOnlyOpenAPIProvider(quart_schema.OpenAPIProvider):
                 yield rule
 
 
-def register_routes(app: base.QuartApp) -> None:
+def register_routes(app: base.QuartApp) -> ModuleType:
     # NOTE: These imports are for their side effects only
-    import atr.routes as routes
-
-    routes.modules()
+    import atr.routes.modules as modules
 
     # Add a global error handler to show helpful error messages with 
tracebacks.
     @app.errorhandler(Exception)
@@ -85,6 +84,8 @@ def register_routes(app: base.QuartApp) -> None:
     async def handle_not_found(error: Exception) -> Any:
         return await quart.render_template("notfound.html", error="404 Not 
Found", traceback="", status_code=404), 404
 
+    return modules
+
 
 def app_dirs_setup(app_config: type[config.AppConfig]) -> None:
     """Setup application directories."""
@@ -133,13 +134,9 @@ def app_setup_context(app: base.QuartApp) -> None:
     async def app_wide() -> dict[str, Any]:
         import atr.db.service as service
         import atr.metadata as metadata
-        import atr.routes as routes
+        import atr.routes.modules as modules
         import atr.util as util
 
-        modules = routes.modules()
-        # In Jinja, keys is a keyword when used in the form .keys
-        modules["_keys"] = modules["keys"]
-        del modules["keys"]
         return {
             "as_url": util.as_url,
             "commit": metadata.commit,
diff --git a/atr/templates/includes/sidebar.html 
b/atr/templates/includes/sidebar.html
index 40216e3..c62a2d9 100644
--- a/atr/templates/includes/sidebar.html
+++ b/atr/templates/includes/sidebar.html
@@ -62,16 +62,16 @@
       <ul>
         <li>
           <i class="fa-solid fa-key"></i>
-          <a href="{{ as_url(routes._keys.review) }}">Your signing keys</a>
+          <a href="{{ as_url(routes.keys.review) }}">Your signing keys</a>
         </li>
         <li>
-          <a href="{{ as_url(routes._keys.add) }}">Add your signing key</a>
+          <a href="{{ as_url(routes.keys.add) }}">Add your signing key</a>
         </li>
         <li>
-          <a href="{{ as_url(routes._keys.upload) }}">Upload a KEYS file</a>
+          <a href="{{ as_url(routes.keys.upload) }}">Upload a KEYS file</a>
         </li>
         <li>
-          <a href="{{ as_url(routes._keys.ssh_add) }}">Add SSH key</a>
+          <a href="{{ as_url(routes.keys.ssh_add) }}">Add SSH key</a>
         </li>
       </ul>
 
diff --git a/atr/templates/index.html b/atr/templates/index.html
index b69bf2f..2230730 100644
--- a/atr/templates/index.html
+++ b/atr/templates/index.html
@@ -23,7 +23,7 @@
 
   <h2>Getting Started</h2>
   <p>
-    To submit a release candidate, you must be a PMC member of the target 
project. First, <a href="{{ as_url(routes._keys.add) }}">add your signing 
key</a>, then <a href="{{ as_url(routes.candidate.create) }}">create a release 
candidate</a>.
+    To submit a release candidate, you must be a PMC member of the target 
project. First, <a href="{{ as_url(routes.keys.add) }}">add your signing 
key</a>, then <a href="{{ as_url(routes.candidate.create) }}">create a release 
candidate</a>.
   </p>
 
   <h2>Documentation</h2>
diff --git a/atr/templates/keys-review.html b/atr/templates/keys-review.html
index aff8635..41fbbb0 100644
--- a/atr/templates/keys-review.html
+++ b/atr/templates/keys-review.html
@@ -83,7 +83,7 @@
               <pre class="mt-3">{{ key.ascii_armored_key }}</pre>
             </details>
 
-            <form method="post" action="{{ as_url(routes._keys.delete) }}" 
class="mt-3">
+            <form method="post" action="{{ as_url(routes.keys.delete) }}" 
class="mt-3">
               <input type="hidden" name="fingerprint" value="{{ 
key.fingerprint }}" />
               <button type="submit" class="btn btn-danger">Delete key</button>
             </form>
@@ -97,7 +97,7 @@
       <strong>You haven't added any signing keys yet.</strong>
     </p>
     <p>
-      <a href="{{ as_url(routes._keys.add) }}">Add a key</a>
+      <a href="{{ as_url(routes.keys.add) }}">Add a key</a>
     </p>
   {% endif %}
 
@@ -125,7 +125,7 @@
               <pre class="mt-3">{{ key.key }}</pre>
             </details>
 
-            <form method="post" action="{{ as_url(routes._keys.delete) }}" 
class="mt-3">
+            <form method="post" action="{{ as_url(routes.keys.delete) }}" 
class="mt-3">
               <input type="hidden" name="fingerprint" value="{{ 
key.fingerprint }}" />
               <button type="submit" class="btn btn-danger">Delete key</button>
             </form>
@@ -138,7 +138,7 @@
       <strong>You haven't added any SSH keys yet.</strong>
     </p>
     <p>
-      <a href="{{ as_url(routes._keys.ssh_add) }}">Add an SSH key</a>
+      <a href="{{ as_url(routes.keys.ssh_add) }}">Add an SSH key</a>
     </p>
   {% endif %}
 {% endblock content %}
diff --git a/pyproject.toml b/pyproject.toml
index d20810d..d1b5419 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -111,6 +111,7 @@ select = [
 "atr/analysis.py" = ["RUF001"]
 "atr/apache.py" = ["N815", "TC003"]
 "atr/db/__init__.py" = ["C901"]
+"atr/routes/modules.py" = ["F401"]
 "scripts/release_path_parse.py" = ["C901", "RUF001"]
 
 [tool.mypy]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to