This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch sbp
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git
The following commit(s) were added to refs/heads/sbp by this push:
new f798d55c Fix the precedence of how to determine classification
f798d55c is described below
commit f798d55c53924b438c8ce491379e7b60898041b2
Author: Sean B. Palmer <[email protected]>
AuthorDate: Sun Mar 15 17:56:47 2026 +0000
Fix the precedence of how to determine classification
---
atr/classify.py | 22 +++++++++++++++++++---
atr/storage/readers/releases.py | 14 ++++++++------
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/atr/classify.py b/atr/classify.py
index 020575a0..68b33674 100644
--- a/atr/classify.py
+++ b/atr/classify.py
@@ -22,6 +22,7 @@ from collections.abc import Callable
from typing import Final
import atr.analysis as analysis
+import atr.util as util
_BINARY_STEM: Final[re.Pattern[str]] =
re.compile(r"[-_](binary-assembly|binary|bin)(?=[-_]|$)")
_SOURCE_STEM: Final[re.Pattern[str]] =
re.compile(r"[-_](source-release|sources|source|src)(?=[-_]|$)")
@@ -38,6 +39,7 @@ def classify(
path: pathlib.Path,
base_path: pathlib.Path | None = None,
source_matcher: Callable[[str], bool] | None = None,
+ binary_matcher: Callable[[str], bool] | None = None,
) -> FileType:
if (path.name in analysis.DISALLOWED_FILENAMES) or (path.suffix in
analysis.DISALLOWED_SUFFIXES):
return FileType.DISALLOWED
@@ -52,13 +54,27 @@ def classify(
return FileType.METADATA
if search and search.group("artifact"):
+ abs_str = str(base_path / path) if (base_path is not None) else None
+ if (source_matcher is not None) and (abs_str is not None) and
source_matcher(abs_str):
+ return FileType.SOURCE
+ if (binary_matcher is not None) and (abs_str is not None) and
binary_matcher(abs_str):
+ return FileType.BINARY
stem = path_str[: search.start()]
if _SOURCE_STEM.search(stem):
return FileType.SOURCE
if _BINARY_STEM.search(stem):
return FileType.BINARY
- if (source_matcher is not None) and (base_path is not None):
- if source_matcher(str(base_path / path)):
- return FileType.SOURCE
return FileType.BINARY
+
+
+def matchers_from_policy(
+ source_artifact_paths: list[str],
+ binary_artifact_paths: list[str],
+ base_path: pathlib.Path,
+) -> tuple[Callable[[str], bool] | None, Callable[[str], bool] | None]:
+ # TODO: Arguably this should just go into classify(...)
+ # Then it could take a release policy or None
+ source_matcher = util.create_path_matcher(source_artifact_paths, None,
base_path) if source_artifact_paths else None
+ binary_matcher = util.create_path_matcher(binary_artifact_paths, None,
base_path) if binary_artifact_paths else None
+ return source_matcher, binary_matcher
diff --git a/atr/storage/readers/releases.py b/atr/storage/readers/releases.py
index 502f1109..7d89555c 100644
--- a/atr/storage/readers/releases.py
+++ b/atr/storage/readers/releases.py
@@ -29,7 +29,6 @@ import atr.models.sql as sql
import atr.paths as paths
import atr.storage as storage
import atr.storage.types as types
-import atr.util as util
@dataclasses.dataclass
@@ -63,12 +62,15 @@ class GeneralPublic:
return None
await self.__successes_errors_warnings(release,
release.safe_latest_revision_number, info)
base_path = paths.release_directory(release)
- source_matcher = None
- source_artifact_paths = release.project.policy_source_artifact_paths
- if source_artifact_paths:
- source_matcher = util.create_path_matcher(source_artifact_paths,
None, base_path)
+ source_matcher, binary_matcher = classify.matchers_from_policy(
+ release.project.policy_source_artifact_paths,
+ release.project.policy_binary_artifact_paths,
+ base_path,
+ )
for path in all_paths:
- info.file_types[path] = classify.classify(path,
base_path=base_path, source_matcher=source_matcher)
+ info.file_types[path] = classify.classify(
+ path, base_path=base_path, source_matcher=source_matcher,
binary_matcher=binary_matcher
+ )
self.__compute_checker_stats(info, all_paths)
return info
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]