mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-24 18:26:28 +01:00
Compare commits
3 Commits
c98da93339
...
98c013ea3f
| Author | SHA1 | Date | |
|---|---|---|---|
| 98c013ea3f | |||
| 213537d0ef | |||
| 11c5b2e32b |
@ -64,6 +64,11 @@ MAVEN_REPOS: Final = (
|
||||
"https://repo1.maven.org/maven2/",
|
||||
"https://plugins.gradle.org/m2/",
|
||||
)
|
||||
# Asked only when none of the above knows an artifact AND the group is not
|
||||
# `com.github.*` (whose metadata is the 401 above): JitPack also hosts
|
||||
# artifacts under their own group, e.g. `cz.adaptech.tesseract4android`,
|
||||
# whose metadata answers 200 with the full release list.
|
||||
JITPACK_REPO: Final = "https://jitpack.io/"
|
||||
UTILS_TAG_REMOTE: Final = "https://github.com/kuhyx/utils"
|
||||
# JitPack coordinates: `com.github.<owner>:<repo>` or
|
||||
# `com.github.<owner>.<repo>:<module>`; the GitHub repo is what "HEAD" means.
|
||||
|
||||
@ -16,7 +16,9 @@ artifacts published nowhere else (PhotoView, DirectionalViewPager). Since
|
||||
themselves still download, so a `com.github.<owner>:<repo>` name that no
|
||||
repository knows is answered from the GitHub repo's tags over `git
|
||||
ls-remote` (unmetered, no token). JitPack's version IS the tag name, `v`
|
||||
prefix included, so the tags are compared as they are.
|
||||
prefix included, so the tags are compared as they are. Artifacts JitPack
|
||||
hosts under their OWN group (`cz.adaptech.tesseract4android`) still get
|
||||
200 metadata there, so JitPack is the last resort for any other name.
|
||||
|
||||
`<latest>` and `<release>` in the metadata are not trusted: AndroidX writes
|
||||
`1.2.0-alpha03` into `<latest>` routinely. The full `<versions>` list goes
|
||||
@ -32,7 +34,12 @@ from __future__ import annotations
|
||||
|
||||
from xml.etree import ElementTree
|
||||
|
||||
from dep_freshness._tables import GITHUB_REMOTE, MAVEN_REPOS
|
||||
from dep_freshness._tables import (
|
||||
GITHUB_REMOTE,
|
||||
JITPACK_GROUP_PREFIX,
|
||||
JITPACK_REPO,
|
||||
MAVEN_REPOS,
|
||||
)
|
||||
from dep_freshness.registries._git import ls_remote
|
||||
from dep_freshness.registries.gitcommit import source_repo
|
||||
from dep_freshness.registries.http import get_text
|
||||
@ -69,6 +76,15 @@ def github_tags(name: str) -> list[str]:
|
||||
return [line.rpartition("refs/tags/")[2] for line in lines if "refs/tags/" in line]
|
||||
|
||||
|
||||
def _jitpack_versions(name: str) -> list[str]:
|
||||
"""What only JitPack knows: tags for `com.github.*`, metadata otherwise."""
|
||||
if name.startswith(JITPACK_GROUP_PREFIX):
|
||||
return github_tags(name)
|
||||
url = metadata_url(JITPACK_REPO, name)
|
||||
body = get_text(url) if url else None
|
||||
return versions_in(body) if body is not None else []
|
||||
|
||||
|
||||
def latest(name: str) -> str | None:
|
||||
seen: list[str] = []
|
||||
for repo in MAVEN_REPOS:
|
||||
@ -79,5 +95,5 @@ def latest(name: str) -> str | None:
|
||||
if body is not None:
|
||||
seen.extend(versions_in(body))
|
||||
if not seen:
|
||||
seen.extend(github_tags(name))
|
||||
seen.extend(_jitpack_versions(name))
|
||||
return reference(seen) or newest_per_generation(seen)
|
||||
|
||||
@ -147,6 +147,47 @@ def test_a_tagless_repo_and_a_non_jitpack_name_are_none(repos, monkeypatch):
|
||||
assert calls == [("https://github.com/o/r", "--tags", "--refs")]
|
||||
|
||||
|
||||
JITPACK = maven.JITPACK_REPO
|
||||
TESSERACT = "cz.adaptech.tesseract4android:tesseract4android"
|
||||
|
||||
|
||||
def test_a_jitpack_only_artifact_is_answered_by_jitpack_metadata(repos):
|
||||
"""Tesseract4Android is published on JitPack under its own group, not
|
||||
`com.github.*`, so there is no source repo to read tags from; JitPack's
|
||||
metadata for it answers 200 and lists every release."""
|
||||
repos[maven.metadata_url(JITPACK, TESSERACT)] = metadata(
|
||||
"4.7.0", "4.9.0", "4.1.1a", latest="4.9.0"
|
||||
)
|
||||
assert maven.latest(TESSERACT) == "4.9.0"
|
||||
|
||||
|
||||
def test_jitpack_is_asked_last_and_only_when_nobody_else_knows_the_name(
|
||||
repos, monkeypatch
|
||||
):
|
||||
asked: list[str] = []
|
||||
monkeypatch.setattr(
|
||||
maven, "get_text", lambda url, *a, **k: asked.append(url) or repos.get(url)
|
||||
)
|
||||
repos[maven.metadata_url(CENTRAL, "io.coil-kt:coil")] = metadata("2.7.0")
|
||||
assert maven.latest("io.coil-kt:coil") == "2.7.0"
|
||||
assert not any(url.startswith(JITPACK) for url in asked)
|
||||
|
||||
|
||||
def test_a_github_jitpack_name_never_asks_jitpack_metadata(repos, monkeypatch):
|
||||
"""That endpoint answers 401 for `com.github.*`; the tags are the answer."""
|
||||
asked: list[str] = []
|
||||
monkeypatch.setattr(
|
||||
maven, "get_text", lambda url, *a, **k: asked.append(url) or None
|
||||
)
|
||||
tags(monkeypatch, {"o/r": ["1.0.0"]})
|
||||
assert maven.latest("com.github.o:r") == "1.0.0"
|
||||
assert not any(url.startswith(JITPACK) for url in asked)
|
||||
|
||||
|
||||
def test_a_name_jitpack_does_not_know_either_is_none(repos):
|
||||
assert maven.latest(TESSERACT) is None
|
||||
|
||||
|
||||
def test_an_unreachable_repo_is_offline(repos, monkeypatch):
|
||||
tags(monkeypatch, {})
|
||||
with pytest.raises(Offline):
|
||||
|
||||
@ -189,14 +189,14 @@ How far to trust a gate is computed from its ledger, never listed by name:
|
||||
`workout_match` counts a `runnerup_tcx` row by `completed_at`, a `rest_day` row
|
||||
on its `day` only if `detail.declared_at` predates that day (else logged, no).
|
||||
|
||||
## The focus project (0.19.0)
|
||||
## The focus project (0.19.0, cut 180 since 0.20.0)
|
||||
|
||||
While `focus_project.active(day)` returns a project, `earners_for` drops the
|
||||
gates it `replaces` (`book` = `reading`) and adds one counted `focus` earner
|
||||
(`max_units` = the day's `daily_on`) paying what they paid (shutdown by their rungs,
|
||||
gaming by `max_gaming_minutes`: 60+60+60 over 120 min = 1.5/min):
|
||||
`floor(summed minutes * pay / daily_minutes)`, never per row. The penalty runs
|
||||
from the start day, cutting what the replaced gates cost; maturity never delays it. Ledger `~/.local/share/focus_project/ledger.json`:
|
||||
from the start day, cutting all of it, 180 with LeetCode's formerly free hour (0.20.0); maturity never delays it. Ledger `~/.local/share/focus_project/ledger.json`:
|
||||
signed `credit` rows, `entry_id` `<project>-<YYYYMMDD>-m<n>`, `detail.minutes` (positive int),
|
||||
`detail.ended_at` (else `day`). `focus_project` unusable = no project (logged).
|
||||
|
||||
@ -243,7 +243,7 @@ signed `credit` rows, `entry_id` `<project>-<YYYYMMDD>-m<n>`, `detail.minutes` (
|
||||
## Install
|
||||
|
||||
```console
|
||||
pip install --user --break-system-packages --no-deps "earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.19.0#subdirectory=earned_time"
|
||||
pip install --user --break-system-packages --no-deps "earned-time @ git+https://github.com/kuhyx/utils@earned-time-v0.20.0#subdirectory=earned_time"
|
||||
```
|
||||
|
||||
The root `steam-backlog-enforcer.service` sets `HOME=/home/kuhy` and imports from
|
||||
|
||||
@ -31,11 +31,9 @@ _warned: set[str] = set()
|
||||
class FocusEarner(Earner):
|
||||
"""Counted; ``gaming_minutes``/``shutdown_minutes`` pay a FULL day.
|
||||
|
||||
``cut_gaming_minutes``: the base cut, what the replaced penalised gates cost.
|
||||
The gaming base cut is all of it, LeetCode's free hour too (kuhy 2026-11-02).
|
||||
"""
|
||||
|
||||
cut_gaming_minutes: int = 0
|
||||
|
||||
def gaming_for(self, units: int) -> int:
|
||||
"""Gaming minutes of ``units`` focused minutes, floored."""
|
||||
return self.capped(units) * self.gaming_minutes // (self.max_units or 1)
|
||||
@ -73,9 +71,6 @@ def focus_earner(project: Any, dropped: tuple[Earner, ...], day: date) -> Earner
|
||||
name="focus",
|
||||
label="Focus",
|
||||
gaming_minutes=sum(e.max_gaming_minutes for e in dropped),
|
||||
cut_gaming_minutes=sum(
|
||||
e.max_gaming_minutes for e in dropped if e.penalty_from is not None
|
||||
),
|
||||
shutdown_minutes=sum(
|
||||
shutdown_units_minutes(e, e.max_units or 1, day) for e in dropped
|
||||
),
|
||||
|
||||
@ -25,7 +25,6 @@ from datetime import UTC, date, datetime
|
||||
import logging
|
||||
from typing import TYPE_CHECKING, Final
|
||||
|
||||
from earned_time._focus import FocusEarner
|
||||
from earned_time._ladder import on_ladder, shutdown_ceiling_for
|
||||
from earned_time._leisure import base_minutes, ceiling_minutes, is_leisure
|
||||
from earned_time._maturity import confirmed_start, penalty_start
|
||||
@ -46,16 +45,6 @@ def _today() -> date:
|
||||
return datetime.now(tz=UTC).astimezone().date()
|
||||
|
||||
|
||||
def _gaming_cut(item: Earner) -> int:
|
||||
"""The gaming base cut of a penalised earner: what it can pay.
|
||||
|
||||
A focus earner cuts only what the gates it replaced cost (LeetCode's was free).
|
||||
"""
|
||||
if isinstance(item, FocusEarner):
|
||||
return item.cut_gaming_minutes
|
||||
return item.max_gaming_minutes
|
||||
|
||||
|
||||
def _penalised(
|
||||
item: Earner, day: date, first_credits: Mapping[str, date | None] | None
|
||||
) -> bool:
|
||||
@ -128,7 +117,7 @@ def _base(
|
||||
penalised = [e for e in registry if _penalised(e, target, first_credits)]
|
||||
return Base(
|
||||
gaming_minutes=base_minutes(leisure=on)
|
||||
- sum(_gaming_cut(e) for e in penalised),
|
||||
- sum(e.max_gaming_minutes for e in penalised),
|
||||
shutdown_minutes=_shutdown_floor(target, registry, penalised),
|
||||
)
|
||||
|
||||
|
||||
@ -92,28 +92,41 @@ def test_many_small_rows_pay_what_one_row_pays(
|
||||
def test_resolve_prices_base_terms_and_ceiling(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
activate(monkeypatch, project())
|
||||
nothing = resolve({"workout": 0, "focus": 0}, DAY, leisure=False)
|
||||
assert nothing.base.gaming_minutes == 300 - 120
|
||||
assert nothing.base.gaming_minutes == 300 - 180
|
||||
assert nothing.base.shutdown_minutes == 18 * 60
|
||||
half = resolve({"workout": 0, "focus": 60}, DAY, leisure=False)
|
||||
assert half.gaming_minutes == 180 + 90
|
||||
assert half.gaming_minutes == 120 + 90
|
||||
assert half.shutdown_minutes == 18 * 60 + 90
|
||||
full = resolve({"workout": 1, "focus": 120}, DAY, leisure=False)
|
||||
assert full.shutdown_minutes == 23 * 60
|
||||
|
||||
|
||||
def test_a_project_day_is_neutral_against_the_gates_it_replaced(
|
||||
def test_a_full_project_day_pays_what_the_replaced_gates_paid(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""Shutdown matches the old full day; gaming loses LeetCode's free hour."""
|
||||
activate(monkeypatch, project())
|
||||
done = {"workout": 1, "leetcode": 1, "reading": 1, "tutor": 60, "focus": 120}
|
||||
old = resolve(done, DAY, TUTOR_EARNERS, leisure=False)
|
||||
new = resolve(done, DAY, leisure=False)
|
||||
assert new.shutdown_minutes == old.shutdown_minutes
|
||||
# kuhy 2026-11-02: LeetCode's bonus hour was free on top of the base; the
|
||||
# project day cuts it and pays it back, so the full day nets 60 less.
|
||||
assert new.gaming_minutes == old.gaming_minutes - 60
|
||||
unsolved = resolve({**done, "leetcode": 0}, DAY, TUTOR_EARNERS, leisure=False)
|
||||
assert new.gaming_minutes == unsolved.gaming_minutes
|
||||
|
||||
|
||||
def test_an_idle_project_day_also_cuts_the_free_leetcode_hour(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
"""kuhy 2026-11-02: a project day cuts all it can pay (180), not 120."""
|
||||
activate(monkeypatch, project())
|
||||
zero = {"workout": 0, "leetcode": 0, "reading": 0, "tutor": 0, "focus": 0}
|
||||
done = {"workout": 1, "leetcode": 1, "reading": 1, "tutor": 60, "focus": 120}
|
||||
for answers in (zero, done):
|
||||
old = resolve(answers, DAY, TUTOR_EARNERS, leisure=False)
|
||||
new = resolve(answers, DAY, leisure=False)
|
||||
assert (new.gaming_minutes, new.shutdown_minutes) == (
|
||||
old.gaming_minutes,
|
||||
old.shutdown_minutes,
|
||||
)
|
||||
old = resolve(zero, DAY, TUTOR_EARNERS, leisure=False)
|
||||
new = resolve(zero, DAY, leisure=False)
|
||||
assert new.gaming_minutes == old.gaming_minutes - 60
|
||||
assert new.shutdown_minutes == old.shutdown_minutes
|
||||
|
||||
|
||||
def test_the_penalty_is_not_delayed_by_the_first_credit(
|
||||
@ -125,7 +138,7 @@ def test_the_penalty_is_not_delayed_by_the_first_credit(
|
||||
plain = resolve(answers, START, leisure=False)
|
||||
paid = resolve(answers, START, first_credits={"focus": START}, leisure=False)
|
||||
assert paid.base == plain.base
|
||||
assert plain.base.gaming_minutes == 300 - 120
|
||||
assert plain.base.gaming_minutes == 300 - 180
|
||||
|
||||
|
||||
def test_maturity_reads_the_focus_ledger(
|
||||
|
||||
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "earned-time"
|
||||
version = "0.19.1"
|
||||
version = "0.20.0"
|
||||
description = "Penalty-then-reward registry: what every gate app earns in gaming time and shutdown time"
|
||||
requires-python = ">=3.14"
|
||||
dependencies = []
|
||||
|
||||
@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "sickdays"
|
||||
version = "0.3.0"
|
||||
version = "0.4.0"
|
||||
description = "Shared sick-day pool: per-date, uncapped, synced; every gate respects it"
|
||||
requires-python = ">=3.14"
|
||||
# Deliberately NOT gatelock (its __init__ imports tkinter); the HMAC lives in
|
||||
|
||||
@ -45,6 +45,7 @@ from sickdays._constants import (
|
||||
LOCKER_ALARM,
|
||||
LOCKER_BOOK,
|
||||
LOCKER_DIET,
|
||||
LOCKER_FOCUS,
|
||||
LOCKER_LEETCODE,
|
||||
LOCKER_WORKOUT,
|
||||
LOCKERS,
|
||||
@ -70,6 +71,7 @@ __all__ = [
|
||||
"LOCKER_ALARM",
|
||||
"LOCKER_BOOK",
|
||||
"LOCKER_DIET",
|
||||
"LOCKER_FOCUS",
|
||||
"LOCKER_LEETCODE",
|
||||
"LOCKER_WORKOUT",
|
||||
"AlreadySickError",
|
||||
|
||||
@ -68,10 +68,13 @@ LOCKER_DIET: Final = "diet"
|
||||
#: The phone ring, the PC fallback ring, the RTC self-wake and the
|
||||
#: missed-alarm penalty -- one switch, because they are one alarm.
|
||||
LOCKER_ALARM: Final = "alarm"
|
||||
#: The focus-project daily-minutes lock (focus-guard).
|
||||
LOCKER_FOCUS: Final = "focus"
|
||||
LOCKERS: Final = (
|
||||
LOCKER_WORKOUT,
|
||||
LOCKER_LEETCODE,
|
||||
LOCKER_BOOK,
|
||||
LOCKER_DIET,
|
||||
LOCKER_ALARM,
|
||||
LOCKER_FOCUS,
|
||||
)
|
||||
|
||||
@ -18,6 +18,7 @@ from sickdays._constants import (
|
||||
LOCKER_ALARM,
|
||||
LOCKER_BOOK,
|
||||
LOCKER_DIET,
|
||||
LOCKER_FOCUS,
|
||||
LOCKER_LEETCODE,
|
||||
LOCKER_WORKOUT,
|
||||
)
|
||||
@ -34,6 +35,7 @@ LOCKER_LABELS: Final = {
|
||||
LOCKER_BOOK: "Book",
|
||||
LOCKER_DIET: "Diet",
|
||||
LOCKER_ALARM: "Wake alarm",
|
||||
LOCKER_FOCUS: "Focus",
|
||||
}
|
||||
|
||||
SHEET_HELP: Final = (
|
||||
|
||||
@ -26,6 +26,7 @@ def test_labels_match_the_phone() -> None:
|
||||
"Book",
|
||||
"Diet",
|
||||
"Wake alarm",
|
||||
"Focus",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@ -200,3 +200,11 @@ def test_the_keep_edit_refusals() -> None:
|
||||
remove_sick_day(TOMORROW, now=TODAY)
|
||||
with pytest.raises(NotSickError):
|
||||
set_kept_lockers(TOMORROW, ["book"], now=TODAY)
|
||||
|
||||
|
||||
def test_focus_is_a_locker_a_sick_day_stands_down_unless_kept() -> None:
|
||||
add_sick_day(TOMORROW, now=TODAY)
|
||||
assert stands_down("focus", TOMORROW)
|
||||
set_kept_lockers(TOMORROW, ["focus"], now=TODAY)
|
||||
assert not stands_down("focus", TOMORROW)
|
||||
assert stands_down("workout", TOMORROW)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user