refactor: pass detection and version flags in full

This commit is contained in:
Abdessamad Derraz committed 2026-11-21 16:43:46 +01:00
1 parent 714683d63c
commit 57ee0cdd8f
4 files changed
+50 -57

No files matched your search

+18 -16
View File
@@ -201,23 +201,25 @@ def cited_paths(report: ProfileReport) -> list[str]:
def detect_upstream_changes(
args: argparse.Namespace, profile: dict, report: ProfileReport,
repo: upstream.Repo,
profile: dict, report: ProfileReport, repo: upstream.Repo,
cache_dir: str, offline: bool, files: bool, hashes: bool,
) -> None:
names, hashes = declared_names(profile), declared_hashes(profile)
new_files: list[dict] = []
new_hashes: list[dict] = []
"""Record on the report the undeclared names (files) and the hash
literals added since the pin (hashes) of the cited files at HEAD."""
names, known = declared_names(profile), declared_hashes(profile)
found_files: list[dict] = []
found_hashes: list[dict] = []
for path in cited_paths(report):
head_lines = upstream.fetch_file(
repo, report.head, path, args.cache_dir, args.offline
repo, report.head, path, cache_dir, offline
)
if head_lines is None:
continue
pin_lines = (
upstream.fetch_file(repo, report.pin, path, args.cache_dir, args.offline)
upstream.fetch_file(repo, report.pin, path, cache_dir, offline)
or []
)
if args.detect_new_files:
if files:
found, elided = detect_new_files(head_lines, names, path=path)
at_pin = {
name.casefold()
@@ -225,27 +227,27 @@ def detect_upstream_changes(
pin_lines, names, cap=sys.maxsize, path=path
)[0]
}
new_files.extend(
found_files.extend(
{"path": path, "line": number, "name": name,
"since_pin": name.casefold() not in at_pin}
for number, name in found
)
if elided:
report.new_files_elided[path] = elided
if args.watch_hashes:
if hashes:
added = [
line
for line in difflib.unified_diff(pin_lines, head_lines, n=0)
if line.startswith("+") and not line.startswith("+++")
]
new_hashes.extend(
found_hashes.extend(
{"path": path, "kind": kind, "value": value}
for kind, value in watch_hashes(added, hashes)
for kind, value in watch_hashes(added, known)
)
if args.detect_new_files:
report.new_files = new_files
if args.watch_hashes:
report.new_hashes = new_hashes
if files:
report.new_files = found_files
if hashes:
report.new_hashes = found_hashes
def print_extras(
+11 -8
View File
@@ -222,8 +222,7 @@ def _gained_since_pin(
# A held pin is not advanced at all: bump_commit says so itself.
return False
if report.new_files is None and report.new_hashes is None:
probe = argparse.Namespace(**{**vars(args), "detect_new_files": True, "watch_hashes": True})
_attach_detection(probe, profile, report)
_attach_detection(profile, report, args.cache_dir, args.offline, True, True)
gained = sorted({item["name"] for item in report.new_files or () if item.get("since_pin")})
added = report.new_hashes or []
if not (gained or added or report.detection_skipped):
@@ -240,7 +239,8 @@ def _gained_since_pin(
def _attach_detection(
args: argparse.Namespace, profile: dict, report: ProfileReport
profile: dict, report: ProfileReport, cache_dir: str, offline: bool,
files: bool, hashes: bool,
) -> None:
"""Record undeclared names and hashes of the cited files on the report.
@@ -249,13 +249,13 @@ def _attach_detection(
report already muted it, and one refusal must not end a pass over every
profile. A quota signal still ends the profile.
"""
if not report.head or not (args.detect_new_files or args.watch_hashes):
if not report.head or not (files or hashes):
return
repo = select_repo(profile)
if repo is None:
return
try:
detect_upstream_changes(args, profile, report, repo)
detect_upstream_changes(profile, report, repo, cache_dir, offline, files, hashes)
except upstream.RateLimitError:
raise
except upstream.UpstreamError as exc:
@@ -288,9 +288,9 @@ def _attach_version(
relation = upstream.ancestry(
repo, version.tag_commit, report.pin, args.cache_dir, args.offline
)
passed = latest_passed_release(args, repo, version, report.pin)
passed = latest_passed_release(repo, version, report.pin, args.cache_dir, args.offline)
newer = None if passed or profile.get("pin_frozen") else newer_release(
args, repo, version, report.pin
repo, version, report.pin, args.cache_dir, args.offline
)
except upstream.RateLimitError:
raise
@@ -430,7 +430,10 @@ def _build_full_report(
profile["version_source"].get("no_genuine_copy") or "") or None
if args.check_version:
_attach_version(args, profile, report)
_attach_detection(args, profile, report)
_attach_detection(
profile, report, args.cache_dir, args.offline,
args.detect_new_files, args.watch_hashes,
)
return report
+10 -9
View File
@@ -2,7 +2,6 @@
from __future__ import annotations
import argparse
import re
import sys
from dataclasses import dataclass
@@ -150,10 +149,11 @@ def _later_number(candidate: str, declared: str) -> bool:
def newer_release(
args: argparse.Namespace,
repo: upstream.Repo,
version: VersionReport | None,
pin: str | None,
cache_dir: str,
offline: bool,
) -> str | None:
"""The latest release, when it comes after both the declared tag and the pin.
@@ -166,23 +166,24 @@ def newer_release(
return None
if published == version.declared:
return None
commit = upstream.tag_commit(repo, published, args.cache_dir, args.offline)
commit = upstream.tag_commit(repo, published, cache_dir, offline)
if not commit or commit == pin:
return None
after_tag = upstream.ancestry(repo, version.tag_commit, commit, args.cache_dir, args.offline)
after_tag = upstream.ancestry(repo, version.tag_commit, commit, cache_dir, offline)
if not after_tag or after_tag[0] == 0 or after_tag[1] != 0:
return None
after_pin = upstream.ancestry(repo, pin, commit, args.cache_dir, args.offline)
after_pin = upstream.ancestry(repo, pin, commit, cache_dir, offline)
if not after_pin or after_pin[0] == 0:
return None
return published
def latest_passed_release(
args: argparse.Namespace,
repo: upstream.Repo,
version: VersionReport | None,
pin: str | None,
cache_dir: str,
offline: bool,
) -> str | None:
"""The latest release, when the pin already contains it and core_version
names another one.
@@ -201,18 +202,18 @@ def latest_passed_release(
# version says it is older. "latest", "continuous" or 1.53 under a
# declared 1.61 say nothing.
return None
commit = upstream.tag_commit(repo, published, args.cache_dir, args.offline)
commit = upstream.tag_commit(repo, published, cache_dir, offline)
if not commit:
return None
if version.tag_commit and version.tag_commit != commit:
# A project can publish a release older than its newest tag:
# pcsx2x6's latest release is v0.2.20, its declared tag v0.2.22.
older = upstream.ancestry(repo, commit, version.tag_commit, args.cache_dir, args.offline)
older = upstream.ancestry(repo, commit, version.tag_commit, cache_dir, offline)
if older and older[1] == 0:
return None
if commit == pin:
return published
relation = upstream.ancestry(repo, commit, pin, args.cache_dir, args.offline)
relation = upstream.ancestry(repo, commit, pin, cache_dir, offline)
if relation and relation[1] == 0:
return published
return None