gitrings 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gitrings/story.py ADDED
@@ -0,0 +1,85 @@
1
+ import json
2
+ from datetime import date, timedelta
3
+ from importlib.resources import files
4
+
5
+ from gitrings.rings import Profile, Ring, boundaries
6
+
7
+ TREES = [
8
+ (9000, "Sequoia"),
9
+ (4000, "Redwood"),
10
+ (2000, "Cedar"),
11
+ (1000, "Oak"),
12
+ (500, "Birch"),
13
+ (200, "Sapling"),
14
+ (50, "Sprout"),
15
+ (0, "Seed"),
16
+ ]
17
+
18
+
19
+ def summarize(profile: Profile, rings: list[Ring]) -> dict[str, object]:
20
+ ring = rings[-1]
21
+ start = date(ring.year, 1, 1)
22
+ months, weekdays = [0] * 12, [0] * 7
23
+ run, streak = 0, (0, 0)
24
+ for offset, count in enumerate(ring.days):
25
+ day = start + timedelta(offset)
26
+ months[day.month - 1] += count
27
+ weekdays[day.weekday()] += count
28
+ run = run + 1 if count else 0
29
+ streak = max(streak, (run, -offset))
30
+ end = start + timedelta(-streak[1])
31
+ weeks = [sum(ring.days[i : i + 7]) for i in range(0, len(ring.days), 7)]
32
+ late = sum(ring.days[(date(ring.year, 7, 1) - start).days :]) / max(1, ring.total)
33
+ active_weeks = sum(1 for week in weeks if week)
34
+ persona = (
35
+ "dormant"
36
+ if not ring.total
37
+ else "evergreen"
38
+ if active_weeks >= 0.75 * len(weeks)
39
+ else "late"
40
+ if late >= 0.65
41
+ else "early"
42
+ if late <= 0.35
43
+ else "steady"
44
+ )
45
+ best = max(range(len(ring.days)), key=ring.days.__getitem__)
46
+ edges = boundaries(rings, pith=0.05, span=0.95, min_width=0.035, samples=180)
47
+ return {
48
+ "login": profile.login,
49
+ "name": profile.name,
50
+ "avatar": profile.avatar,
51
+ "year": ring.year,
52
+ "joined": rings[0].year,
53
+ "total": ring.total,
54
+ "previous": rings[-2].total if len(rings) > 1 else None,
55
+ "rings": [
56
+ {"year": r.year, "total": r.total, "edge": [round(x, 4) for x in edge]}
57
+ for r, edge in zip(rings, edges, strict=True)
58
+ ],
59
+ "days": ring.days,
60
+ "months": months,
61
+ "weekdays": weekdays,
62
+ "streak": {
63
+ "days": streak[0],
64
+ "start": (end - timedelta(streak[0] - 1)).isoformat(),
65
+ "end": end.isoformat(),
66
+ },
67
+ "best": {"date": (start + timedelta(best)).isoformat(), "count": ring.days[best]},
68
+ "activeDays": sum(1 for count in ring.days if count),
69
+ "activeWeeks": active_weeks,
70
+ "weeks": len(weeks),
71
+ "late": round(late, 3),
72
+ "persona": persona,
73
+ "tree": next(name for floor, name in TREES if ring.total >= floor),
74
+ "kinds": profile.kinds,
75
+ "privateCommits": profile.private_commits,
76
+ "languages": [
77
+ {"name": name, "color": color, "commits": commits}
78
+ for name, color, commits in profile.languages
79
+ ],
80
+ }
81
+
82
+
83
+ def render(profile: Profile, rings: list[Ring]) -> str:
84
+ data = json.dumps(summarize(profile, rings), separators=(",", ":")).replace("</", "<\\/")
85
+ return files("gitrings").joinpath("story.html").read_text().replace("__GITRINGS__", data)
gitrings/svg.py ADDED
@@ -0,0 +1,147 @@
1
+ from math import ceil, cos, pi, sin, sqrt
2
+
3
+ from gitrings.rings import Ring, boundaries
4
+
5
+ WIDTH = 480
6
+ HEIGHT = 600
7
+ CX = 240
8
+ CY = 300
9
+ PITH = 6.0
10
+ SPAN = 168.0
11
+ MIN_WIDTH = 5.0
12
+ SAMPLES = 360
13
+ FONT = "ui-sans-serif, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"
14
+ MONO = "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"
15
+
16
+ THEMES = {
17
+ "light": {"bg": "#E8ECE1", "line": "#0F1712", "accent": "#F2552C"},
18
+ "dark": {"bg": "#0C1410", "line": "#E8ECE1", "accent": "#FFB23E"},
19
+ }
20
+
21
+ STYLE = """<style>
22
+ .edge { stroke-dasharray: 1; stroke-dashoffset: 1; }
23
+ .edge { animation: draw 1.6s cubic-bezier(.22,1,.36,1) forwards; }
24
+ .grain { opacity: 0; animation: fade 1.2s ease-out forwards; }
25
+ @keyframes draw { to { stroke-dashoffset: 0; } }
26
+ @keyframes fade { to { opacity: 1; } }
27
+ @media (prefers-reduced-motion: reduce) {
28
+ .edge, .grain { animation: none; stroke-dashoffset: 0; opacity: 1; }
29
+ }
30
+ </style>"""
31
+
32
+
33
+ def _path(radii: list[float], cx: float, cy: float) -> str:
34
+ step = 2 * pi / len(radii)
35
+ points = (
36
+ f"{cx + r * sin(j * step):.1f},{cy - r * cos(j * step):.1f}" for j, r in enumerate(radii)
37
+ )
38
+ return "M" + " L".join(points) + " Z"
39
+
40
+
41
+ def _trunk(
42
+ rings: list[Ring], span: float, cx: float, cy: float, colors: dict[str, str]
43
+ ) -> list[str]:
44
+ edges = boundaries(rings, PITH, span, MIN_WIDTH, SAMPLES)
45
+ parts = [
46
+ f'<path d="{_path(edges[-1], cx, cy)}" fill="{colors["line"]}" opacity="0.05"/>',
47
+ f'<g fill="none" stroke="{colors["line"]}" stroke-linejoin="round">',
48
+ ]
49
+ previous = [PITH] * SAMPLES
50
+ for index, (ring, edge) in enumerate(zip(rings, edges, strict=True)):
51
+ delay = index * 0.22
52
+ width = sum(e - p for e, p in zip(edge, previous, strict=True)) / SAMPLES
53
+ count = min(10, int(width / 5))
54
+ for n in range(1, count + 1):
55
+ grain = [p + (e - p) * n / (count + 1) for p, e in zip(previous, edge, strict=True)]
56
+ parts.append(
57
+ f'<path class="grain" d="{_path(grain, cx, cy)}" stroke-width="0.6" '
58
+ f'stroke-opacity="0.32" style="animation-delay:{delay + 0.5:.2f}s"/>'
59
+ )
60
+ latest = index == len(rings) - 1
61
+ stroke = (
62
+ f' stroke="{colors["accent"]}" stroke-width="2.4"' if latest else ' stroke-width="1.4"'
63
+ )
64
+ parts.append(
65
+ f'<path class="edge" d="{_path(edge, cx, cy)}" pathLength="1"{stroke} '
66
+ f'style="animation-delay:{delay:.2f}s">'
67
+ f"<title>{ring.year} · {ring.total:,} contributions</title></path>"
68
+ )
69
+ previous = edge
70
+ parts += ["</g>", f'<circle cx="{cx}" cy="{cy}" r="{PITH - 1}"/>']
71
+ return parts
72
+
73
+
74
+ def _stat(x: int, label: str, value: str, top: int = 0) -> str:
75
+ return (
76
+ f'<text x="{x}" y="{top + 530}" font-size="12" opacity="0.6">{label}</text>'
77
+ f'<text x="{x}" y="{top + 558}" font-size="20" font-weight="700">{value}</text>'
78
+ )
79
+
80
+
81
+ def render(login: str, rings: list[Ring], theme: str = "light") -> str:
82
+ colors = THEMES[theme]
83
+ total = sum(ring.total for ring in rings)
84
+ widest = max(rings, key=lambda ring: ring.total)
85
+ summary = ", ".join(f"{ring.year}: {ring.total:,} contributions" for ring in rings)
86
+ noun = "ring" if len(rings) == 1 else "rings"
87
+ parts = [
88
+ f'<svg xmlns="http://www.w3.org/2000/svg" width="{WIDTH}" height="{HEIGHT}" '
89
+ f'viewBox="0 0 {WIDTH} {HEIGHT}" role="img" font-family="{FONT}" fill="{colors["line"]}">',
90
+ f"<title>@{login}'s GitHub years as tree rings</title>",
91
+ f"<desc>{summary}</desc>",
92
+ STYLE,
93
+ f'<rect width="{WIDTH}" height="{HEIGHT}" rx="24" fill="{colors["bg"]}"/>',
94
+ f'<g font-family="{MONO}" font-size="12" opacity="0.6">'
95
+ f'<text x="32" y="44">@{login}</text>'
96
+ f'<text x="{WIDTH - 32}" y="44" text-anchor="end">gitrings</text></g>',
97
+ f'<text x="30" y="88" font-size="30" font-weight="700" letter-spacing="-0.6">'
98
+ f"{len(rings)} {noun} since {rings[0].year}</text>",
99
+ *_trunk(rings, SPAN, CX, CY, colors),
100
+ f'<line x1="32" y1="500" x2="{WIDTH - 32}" y2="500" stroke="{colors["line"]}" '
101
+ 'stroke-opacity="0.18"/>',
102
+ _stat(32, "Contributions", f"{total:,}"),
103
+ _stat(184, "Widest ring", f"{widest.year} · {widest.total:,}"),
104
+ _stat(352, "First ring", f"{rings[0].year}"),
105
+ "</svg>",
106
+ ]
107
+ return "\n".join(parts)
108
+
109
+
110
+ def forest(trees: list[tuple[str, list[Ring]]], theme: str = "light") -> str:
111
+ """Trees on one scale, four to a row: the busier history draws the wider trunk."""
112
+ colors = THEMES[theme]
113
+ cell, cols = WIDTH - 40, min(len(trees), 4)
114
+ width, height = cell * cols, HEIGHT * ceil(len(trees) / cols)
115
+ weights = [sum(sqrt(ring.total) for ring in rings) for _, rings in trees]
116
+ spare = SPAN - MIN_WIDTH * max(len(rings) for _, rings in trees)
117
+ names = ", ".join(f"@{login}" for login, _ in trees)
118
+ vs = f'<text x="{width / 2}" y="84">vs</text>' if len(trees) == 2 else ""
119
+ parts = [
120
+ f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" '
121
+ f'viewBox="0 0 {width} {height}" role="img" font-family="{FONT}" fill="{colors["line"]}">',
122
+ f"<title>{names}: GitHub years as tree rings</title>",
123
+ STYLE,
124
+ f'<rect width="{width}" height="{height}" rx="24" fill="{colors["bg"]}"/>',
125
+ f'<g font-family="{MONO}" font-size="12" opacity="0.6" text-anchor="middle">'
126
+ f'<text x="{width / 2}" y="44">gitrings</text>{vs}</g>',
127
+ ]
128
+ for index, ((login, rings), weight) in enumerate(zip(trees, weights, strict=True)):
129
+ x, y = cell * (index % cols), HEIGHT * (index // cols)
130
+ span = MIN_WIDTH * len(rings) + spare * weight / (max(weights) or 1.0)
131
+ widest = max(rings, key=lambda ring: ring.total)
132
+ parts += [
133
+ f'<text x="{x + 32}" y="{y + 88}" font-size="26" font-weight="700" '
134
+ f'letter-spacing="-0.5">@{login}</text>',
135
+ *_trunk(rings, span, x + cell / 2, y + CY, colors),
136
+ f'<line x1="{x + 32}" y1="{y + 500}" x2="{x + cell - 32}" y2="{y + 500}" '
137
+ f'stroke="{colors["line"]}" stroke-opacity="0.18"/>',
138
+ _stat(x + 32, "Contributions", f"{sum(ring.total for ring in rings):,}", y),
139
+ _stat(x + 184, "Widest ring", f"{widest.year} · {widest.total:,}", y),
140
+ ]
141
+ if index % cols:
142
+ parts.append(
143
+ f'<line x1="{x}" y1="{y + 120}" x2="{x}" y2="{y + 480}" '
144
+ f'stroke="{colors["line"]}" stroke-opacity="0.12"/>'
145
+ )
146
+ parts.append("</svg>")
147
+ return "\n".join(parts)
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.5
2
+ Name: gitrings
3
+ Version: 0.1.0
4
+ Summary: Your GitHub years as tree rings: counted honestly, private work included, nothing leaked.
5
+ Project-URL: Repository, https://github.com/cengizhandemiir/gitrings
6
+ Author: Cengizhan Demir
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Python: >=3.12
10
+ Description-Content-Type: text/markdown
11
+
12
+ # gitrings
13
+
14
+ Your GitHub years as tree rings: counted honestly, private work included, nothing leaked.
15
+
16
+ ## How to read the rings
17
+
18
+ | In a tree | In gitrings |
19
+ |---|---|
20
+ | The pith at the centre | The year you joined GitHub |
21
+ | One growth ring per year | One ring per calendar year |
22
+ | A wide ring is a good growing season | Ring width grows with that year's contributions, square-root scaled so one huge year does not flatten the rest |
23
+ | An uneven ring edge | Busy weeks push the ring outward, quiet weeks keep it thin. The edge is your year's daily rhythm, clockwise from January at 12 o'clock |
24
+ | Earlywood and latewood bands | Fine grain lines fill each ring, more of them in a wider year |
25
+ | Bark | The outermost ring, in the accent colour, is the current year, still growing: the days ahead stay thin until they happen |
26
+
27
+ ## Why
28
+
29
+ Hosted "wrapped" sites add up the whole contribution calendar and call it commits, miss private work, and keep serving stale cached zeros. gitrings runs with your own token, on your machine or your own Actions runner. The image only ever contains daily counts and yearly totals, never repository, organisation or branch names.
30
+
31
+ ## Usage
32
+
33
+ ```bash
34
+ pip install gitrings
35
+ gitrings <login> --theme dark --out rings.svg --story year.html
36
+ ```
37
+
38
+ The card draws itself ring by ring when the README loads, and holds still for readers who ask for reduced motion.
39
+
40
+ `--vs <login>` also writes `rings-vs-<login>.svg`: your tree next to someone else's, both on one scale, so the busier history draws the wider trunk. The other tree shows only what GitHub makes public for that account.
41
+
42
+ `--forest <login> [<login> ...]` also writes `rings-forest.svg`: your tree and theirs on that same shared scale, four to a row, for a team page or a team README. Put `--forest` after your own login. Each account costs one GitHub request for every three years it has existed, so a team of five long-time users takes under a minute.
43
+
44
+ `--gitlab <user>` adds that GitLab account's events to the same rings, day by day, counted the way GitLab's own calendar counts them. GitLab deletes events older than three years, so older rings stay GitHub-only. `GITLAB_URL` points at a self-managed instance (default `https://gitlab.com`), and `GITLAB_TOKEN`, a token with `read_user`, counts private projects too; without it GitLab shows only public events, and GitLab.com blocks anonymous requests from an IP address for an hour after a few dozen.
45
+
46
+ `--story` also writes `year.html`, a tap-through story of the current year: your ring, its size class, the month and weekday it grew most, its shape, your longest run, what it is made of and which languages fed it, ending in a card studio: four layouts (Trunk, Bento, Headline and a 1600×900 Wide one) in five colourways, saved, copied or shared as a PNG, plus the workflow and the snippet that keep the animated card in your profile README. The soundtrack starts off; the sound button cycles through three moods (Forest, Lofi, Pulse), all generated in the browser with the Web Audio API, and in each the melody follows your weekly contribution counts, so there is nothing to download or license. The page holds the same daily counts and totals as the card, plus language names and your avatar URL; it loads fonts from Fontshare and Bunny Fonts and icons from unpkg.
47
+
48
+ The token comes from `GITHUB_TOKEN`, or from `gh auth token` when that is unset. For private contributions to be counted in detail, a classic token needs the `repo` and `user` scopes; without the user scope GitHub reports private work only as an anonymous total.
49
+
50
+ `gitrings --doctor` checks what keeps work out of the rings: whether the token has `repo` and `read:user`, whether an organisation's SAML SSO is still waiting for the token to be authorised, and whether `git config user.email` is a verified email on your account (GitHub only counts commits from those; the check needs `user:email`). It prints `ok` or `fix` per line and exits 1 if anything needs fixing.
51
+
52
+ ### Daily card in your profile README
53
+
54
+ Save this as `.github/workflows/gitrings.yml` in your profile repository (`<login>/<login>`):
55
+
56
+ ```yaml
57
+ name: gitrings
58
+ on:
59
+ schedule:
60
+ - cron: '17 4 * * *'
61
+ workflow_dispatch:
62
+ permissions:
63
+ contents: write
64
+ jobs:
65
+ rings:
66
+ runs-on: ubuntu-latest
67
+ steps:
68
+ - uses: cengizhandemiir/gitrings@main
69
+ with:
70
+ token: ${{ secrets.GITRINGS_TOKEN }}
71
+ ```
72
+
73
+ Every day it draws `gitrings.svg` and `gitrings-dark.svg` and force-pushes them as the only commit on a `gitrings` branch, so the repository does not grow. Without a `GITRINGS_TOKEN` secret it reads with the workflow's own token, which counts what your public profile shows: private work too, as daily counts, when "Private contributions" is on in your profile settings. With that setting off, a classic token with `repo` and `read:user` as the secret still counts it. Inputs: `login` (default: the repository owner), `token`, `branch` (default: `gitrings`). Then put the card in your README, dark or light to match the reader:
74
+
75
+ ```html
76
+ <picture>
77
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/<login>/<login>/gitrings/gitrings-dark.svg">
78
+ <img alt="@<login>'s GitHub years as tree rings" src="https://raw.githubusercontent.com/<login>/<login>/gitrings/gitrings.svg">
79
+ </picture>
80
+ ```
81
+
82
+ ## License
83
+
84
+ MIT
@@ -0,0 +1,13 @@
1
+ gitrings/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ gitrings/cli.py,sha256=S8z3uiea-P5yCufYZp3yBBvP-mhdE1JPQ_IZaqguvSE,2716
3
+ gitrings/github.py,sha256=a8jAWEjMNZt4n-EskP7RP7gHsi2HR_toYiQgVUEch6Y,5915
4
+ gitrings/gitlab.py,sha256=UxLBal_1YXCOAWT3yP7wntantGfp7fuYLwvGwsTGEng,1071
5
+ gitrings/rings.py,sha256=uq-SxzDufUfonOBsh3MZ4kZsjfJ45HnnNJhrVzR4LzE,2022
6
+ gitrings/story.html,sha256=HMUpQ48u9fWTC0xn0Edxz1SxvFqt-lZnuO3oghr6bwo,74881
7
+ gitrings/story.py,sha256=Lq2knNGe3Cur53IXwuySp6guu3_lYDaeqTffVhXzHFg,2946
8
+ gitrings/svg.py,sha256=UyxlSO6chSFFsvFrIypY4o0wyW6YEoGndHxJDdUWKpo,6606
9
+ gitrings-0.1.0.dist-info/METADATA,sha256=_AsyGG0w2LnET7yukwoEHE1ffAPxs8bE_BL2iQ3DyPM,5689
10
+ gitrings-0.1.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
11
+ gitrings-0.1.0.dist-info/entry_points.txt,sha256=Gr6mYCcfi-9Q84JH9sXTbMhD9s28N6wVlLkLU9dYZ1s,47
12
+ gitrings-0.1.0.dist-info/licenses/LICENSE,sha256=3IoQ7XaTaFvSSiwGDiRy3VXn0MKcATzyNC21LlhgssE,1072
13
+ gitrings-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ gitrings = gitrings.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cengizhan Demir
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.