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 6f91e4a Move the code to get check results for a path
6f91e4a is described below
commit 6f91e4a89774c1f411aa77bfbd08bdaf9e84bf02
Author: Sean B. Palmer <[email protected]>
AuthorDate: Mon May 5 16:25:49 2025 +0100
Move the code to get check results for a path
---
atr/db/__init__.py | 58 +++++++++++++++++++++++++++++++++++++++
atr/routes/compose.py | 56 ++++---------------------------------
atr/templates/check-selected.html | 14 +++++-----
3 files changed, 71 insertions(+), 57 deletions(-)
diff --git a/atr/db/__init__.py b/atr/db/__init__.py
index 56a12e3..5f8e4aa 100644
--- a/atr/db/__init__.py
+++ b/atr/db/__init__.py
@@ -17,8 +17,10 @@
from __future__ import annotations
+import dataclasses
import logging
import os
+import re
from typing import TYPE_CHECKING, Any, Final, Generic, TypeGuard, TypeVar
import sqlalchemy
@@ -33,9 +35,11 @@ import atr.config as config
import atr.db.models as models
import atr.user as user
import atr.util as util
+from atr import analysis
if TYPE_CHECKING:
import datetime
+ import pathlib
from collections.abc import Sequence
import asfquart.base as base
@@ -76,6 +80,17 @@ NOT_SET: Final[NotSet] = NotSet()
type Opt[T] = T | NotSet
[email protected]
+class PathInfo:
+ artifacts: set[pathlib.Path] = dataclasses.field(default_factory=set)
+ errors: dict[pathlib.Path, list[models.CheckResult]] =
dataclasses.field(default_factory=dict)
+ metadata: set[pathlib.Path] = dataclasses.field(default_factory=set)
+ # substitutions: dict[pathlib.Path, str] =
dataclasses.field(default_factory=dict)
+ successes: dict[pathlib.Path, list[models.CheckResult]] =
dataclasses.field(default_factory=dict)
+ # templates: dict[pathlib.Path, str] =
dataclasses.field(default_factory=dict)
+ warnings: dict[pathlib.Path, list[models.CheckResult]] =
dataclasses.field(default_factory=dict)
+
+
class Query(Generic[T]):
def __init__(self, session: Session, query: expression.SelectOfScalar[T]):
self.query = query
@@ -573,6 +588,49 @@ def is_undefined(v: object | NotSet) -> TypeGuard[NotSet]:
# return recent_tasks
+async def path_info(release: models.Release, paths: list[pathlib.Path]) ->
PathInfo:
+ info = PathInfo()
+ for path in paths:
+ # Get template and substitutions
+ # elements = {
+ # "core": release.project.name,
+ # "version": release.version,
+ # "sub": None,
+ # "template": None,
+ # "substitutions": None,
+ # }
+ # template, substitutions = analysis.filename_parse(str(path),
elements)
+ # info.templates[path] = template
+ # info.substitutions[path] =
analysis.substitutions_format(substitutions) or "none"
+
+ # Get artifacts and metadata
+ search = re.search(analysis.extension_pattern(), str(path))
+ if search:
+ if search.group("artifact"):
+ info.artifacts.add(path)
+ elif search.group("metadata"):
+ info.metadata.add(path)
+
+ # Get successes, warnings, and errors
+ async with session() as data:
+ info.successes[path] = list(
+ await data.check_result(
+ release_name=release.name, primary_rel_path=str(path),
status=models.CheckResultStatus.SUCCESS
+ ).all()
+ )
+ info.warnings[path] = list(
+ await data.check_result(
+ release_name=release.name, primary_rel_path=str(path),
status=models.CheckResultStatus.WARNING
+ ).all()
+ )
+ info.errors[path] = list(
+ await data.check_result(
+ release_name=release.name, primary_rel_path=str(path),
status=models.CheckResultStatus.FAILURE
+ ).all()
+ )
+ return info
+
+
def select_in_load(*entities: Any) -> orm.strategy_options._AbstractLoad:
"""Eagerly load the given entities from the query."""
validated_entities = []
diff --git a/atr/routes/compose.py b/atr/routes/compose.py
index 11820f6..5dc69fe 100644
--- a/atr/routes/compose.py
+++ b/atr/routes/compose.py
@@ -15,14 +15,12 @@
# specific language governing permissions and limitations
# under the License.
-import re
from typing import TYPE_CHECKING
import quart
import werkzeug.wrappers.response as response
import wtforms
-import atr.analysis as analysis
import atr.db as db
import atr.db.models as models
import atr.revision as revision
@@ -42,49 +40,13 @@ async def check(
form: wtforms.Form | None = None,
) -> response.Response | str:
base_path = util.release_directory(release)
- paths = [path async for path in util.paths_recursive(base_path)]
- path_templates = {}
- path_substitutions = {}
- path_artifacts = set()
- path_metadata = set()
- path_successes = {}
- path_warnings = {}
- path_errors = {}
- user_ssh_keys: Sequence[models.SSHKey] = []
-
- for path in paths:
- # Get template and substitutions
- elements = {
- "core": release.project.name,
- "version": release.version,
- "sub": None,
- "template": None,
- "substitutions": None,
- }
- template, substitutions = analysis.filename_parse(str(path), elements)
- path_templates[path] = template
- path_substitutions[path] =
analysis.substitutions_format(substitutions) or "none"
- # Get artifacts and metadata
- search = re.search(analysis.extension_pattern(), str(path))
- if search:
- if search.group("artifact"):
- path_artifacts.add(path)
- elif search.group("metadata"):
- path_metadata.add(path)
+ paths = [path async for path in util.paths_recursive(base_path)]
+ info = await db.path_info(release, paths)
- # Get successes, warnings, and errors
- async with db.session() as data:
- path_successes[path] = await data.check_result(
- release_name=release.name, primary_rel_path=str(path),
status=models.CheckResultStatus.SUCCESS
- ).all()
- path_warnings[path] = await data.check_result(
- release_name=release.name, primary_rel_path=str(path),
status=models.CheckResultStatus.WARNING
- ).all()
- path_errors[path] = await data.check_result(
- release_name=release.name, primary_rel_path=str(path),
status=models.CheckResultStatus.FAILURE
- ).all()
- user_ssh_keys = await data.ssh_key(asf_uid=session.uid).all()
+ user_ssh_keys: Sequence[models.SSHKey] = []
+ async with db.session() as data:
+ user_ssh_keys = await data.ssh_key(asf_uid=session.uid).all()
revision_name_from_link, revision_editor, revision_time = await
revision.latest_info(
release.project.name, release.version
@@ -105,13 +67,7 @@ async def check(
version_name=release.version,
release=release,
paths=paths,
- artifacts=path_artifacts,
- metadata=path_metadata,
- successes=path_successes,
- warnings=path_warnings,
- errors=path_errors,
- templates=path_templates,
- substitutions=path_substitutions,
+ info=info,
revision_editor=revision_editor,
revision_time=revision_time,
revision_name_from_link=revision_name_from_link,
diff --git a/atr/templates/check-selected.html
b/atr/templates/check-selected.html
index 195109f..c8baffa 100644
--- a/atr/templates/check-selected.html
+++ b/atr/templates/check-selected.html
@@ -161,8 +161,8 @@
<table class="table table-hover align-middle table-sm mb-0 border">
<tbody>
{% for path in paths %}
- {% set has_errors = errors[path]|length > 0 %}
- {% set has_warnings = warnings[path]|length > 0 %}
+ {% set has_errors = info.errors[path]|length > 0 %}
+ {% set has_warnings = info.warnings[path]|length > 0 %}
{% set row_id = path|string|slugify %}
{# Manual striping for pairs of rows #}
@@ -187,11 +187,11 @@
{% set icon_class = "text-warning" %}
{% endif %}
- {% if path in artifacts %}
+ {% if path in info.artifacts %}
<i class="bi bi-archive {{ icon_class }}"
title="Artifact"
aria-label="Artifact"></i>
- {% elif path in metadata %}
+ {% elif path in info.metadata %}
<i class="bi bi-file-earmark-text {{ icon_class }}"
title="Metadata"
aria-label="Metadata"></i>
@@ -216,11 +216,11 @@
<div class="d-flex justify-content-end align-items-center
gap-2">
{% if has_errors %}
<a href="{{ as_url(routes.report.selected_path,
project_name=project_name, version_name=version_name, rel_path=path) }}"
- class="btn btn-sm btn-outline-danger"><i class="bi
bi-exclamation-triangle me-1"></i> Show {{ errors[path]|length }} {{ "error" if
errors[path]|length == 1 else "errors" }}</a>
+ class="btn btn-sm btn-outline-danger"><i class="bi
bi-exclamation-triangle me-1"></i> Show {{ info.errors[path]|length }} {{
"error" if info.errors[path]|length == 1 else "errors" }}</a>
{% elif has_warnings %}
<a href="{{ as_url(routes.report.selected_path,
project_name=project_name, version_name=version_name, rel_path=path) }}"
- class="btn btn-sm btn-outline-warning">Show {{
warnings[path]|length }} {{ "warning" if warnings[path]|length == 1 else
"warnings" }}</a>
- {% elif successes[path] %}
+ class="btn btn-sm btn-outline-warning">Show {{
info.warnings[path]|length }} {{ "warning" if info.warnings[path]|length == 1
else "warnings" }}</a>
+ {% elif info.successes[path] %}
<a href="{{ as_url(routes.report.selected_path,
project_name=project_name, version_name=version_name, rel_path=path) }}"
class="btn btn-sm btn-outline-success"
title="Show report for {{ path }}">Show report</a>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]