codeyear 0.2.15__py3-none-any.whl → 0.2.16__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.
codeyear/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """CodeYear · 本地优先的年度代码报告生成器."""
2
2
 
3
- __version__ = "0.2.15"
3
+ __version__ = "0.2.16"
codeyear/card.py CHANGED
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import html
6
- from datetime import date, datetime, timedelta
6
+ from datetime import datetime, timedelta
7
7
  from pathlib import Path
8
8
 
9
9
  from .stats import (
@@ -14,6 +14,8 @@ from .stats import (
14
14
  fmt_signed_pair,
15
15
  language_breakdown,
16
16
  parse_daily,
17
+ window_days,
18
+ window_months,
17
19
  )
18
20
 
19
21
  W, H = 640, 1254
@@ -247,9 +249,10 @@ MONTHS = [
247
249
 
248
250
 
249
251
  def build_svg(stats: ReportStats, *, dark: bool = False,
250
- theme: str = "paper", lang: str = "zh") -> str:
252
+ theme: str = "paper", lang: str = "zh",
253
+ palette_override: dict | None = None) -> str:
251
254
  light, dark_theme = THEMES.get(theme, THEMES["paper"])
252
- c = dark_theme if dark else light
255
+ c = palette_override if palette_override is not None else (dark_theme if dark else light)
253
256
  en = lang == "en"
254
257
 
255
258
  def t(zh: str, english: str) -> str:
@@ -300,7 +303,7 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
300
303
  header.append(_rule(142, c["line"]))
301
304
 
302
305
  # ---- six summary tiles (3 x 2) ------------------------------------
303
- active_pct = stats.active_days / (366 if _is_leap(stats.year) else 365)
306
+ active_pct = stats.active_days / window_days(stats)
304
307
  tiles = [
305
308
  (t("COMMITS / 提交", "COMMITS"), fmt_int(stats.commit_count),
306
309
  t("年度提交", "commits this year")),
@@ -343,19 +346,18 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
343
346
 
344
347
  # ---- contribution calendar ---------------------------------------
345
348
  cell, gap_h = 9, 2
346
- grid_start = date(stats.year, 1, 1)
347
- grid_start -= timedelta(days=grid_start.weekday())
348
- grid_end = date(stats.year, 12, 31)
349
- grid_end += timedelta(days=6 - grid_end.weekday())
349
+ start_w, end_w = date_window(stats)
350
+ grid_start = start_w - timedelta(days=start_w.weekday())
351
+ grid_end = end_w + timedelta(days=6 - end_w.weekday())
350
352
  grid_cols = (grid_end - grid_start).days // 7 + 1
351
353
  grid_w = grid_cols * (cell + gap_h) - gap_h
352
354
  grid_x = (W - grid_w) / 2
353
355
 
354
356
  month_ticks = []
355
- for month in range(1, 13):
356
- col = (date(stats.year, month, 1) - grid_start).days // 7
357
+ for m_date, m_label in window_months(stats):
358
+ col = (m_date - grid_start).days // 7
357
359
  mx = grid_x + col * (cell + gap_h)
358
- month_ticks.append(_text(mx, 588, f"{month:02d}", 9.5, c["muted"]))
360
+ month_ticks.append(_text(mx, 588, m_label, 9.5, c["muted"]))
359
361
 
360
362
  charts = [
361
363
  _text(M, 350, "MONTHLY RHYTHM", 10, c["muted"], spacing=1),
@@ -702,10 +704,6 @@ def build_svg(stats: ReportStats, *, dark: bool = False,
702
704
  """
703
705
 
704
706
 
705
- def _is_leap(year: int) -> bool:
706
- return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
707
-
708
-
709
707
  def render(stats: ReportStats, out_path: str | Path, *,
710
708
  theme: str = "paper", lang: str = "zh") -> list[Path]:
711
709
  path = Path(out_path)
codeyear/cli.py CHANGED
@@ -3,9 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import argparse
6
- import json
7
6
  import os
8
- import subprocess
9
7
  import sys
10
8
  import webbrowser
11
9
  from datetime import date
@@ -13,17 +11,25 @@ from pathlib import Path
13
11
 
14
12
  from . import __version__, i18n
15
13
  from .card import THEMES
16
- from .card import render as render_card
17
14
  from .config import load as load_config
18
- from .html_report import render as render_html
19
- from .html_report import render_en as render_html_en
20
- from .poster import render as render_poster
21
- from .poster import render_long
22
- from .runner import discover, report_path, scan
23
- from .stats import fmt_int
15
+ from .runner import detect_identity, discover, render, report_path, scan
16
+ from .stats import fmt_int, window_days
24
17
  from .updater import check_update, cleanup_old_executable, perform_update
25
18
 
26
- _NO_WINDOW = subprocess.CREATE_NO_WINDOW if os.name == "nt" else 0
19
+
20
+ class _CopyAppendAction(argparse.Action):
21
+ """Append action that never mutates a config-provided default list."""
22
+
23
+ def __call__(self, parser, namespace, values, option_string=None):
24
+ items = list(getattr(namespace, self.dest, None) or [])
25
+ if getattr(namespace, f"_cy_copied_{self.dest}", False) is False:
26
+ items = [] if values == "" else list(items)
27
+ setattr(namespace, f"_cy_copied_{self.dest}", True)
28
+ if values == "":
29
+ items = []
30
+ else:
31
+ items.append(values)
32
+ setattr(namespace, self.dest, items)
27
33
 
28
34
 
29
35
  def _build_parser() -> argparse.ArgumentParser:
@@ -88,7 +94,7 @@ def _build_parser() -> argparse.ArgumentParser:
88
94
  scan.add_argument("--rolling", action=argparse.BooleanOptionalAction,
89
95
  default=cfg.get("rolling", False),
90
96
  help="统计过去 365 天(滚动年度),而非自然年")
91
- scan.add_argument("--exclude", action="append", default=cfg.get("exclude", []),
97
+ scan.add_argument("--exclude", action=_CopyAppendAction, default=list(cfg.get("exclude", [])),
92
98
  help="排除指定仓库名或通配符(可重复或逗号分隔)")
93
99
  scan.add_argument("--out", default=cfg.get("out", "codeyear-output"),
94
100
  help="输出目录,默认 ./codeyear-output")
@@ -100,7 +106,7 @@ def _build_parser() -> argparse.ArgumentParser:
100
106
  scan.add_argument("--fallback-previous", action=argparse.BooleanOptionalAction,
101
107
  default=cfg.get("fallback_previous", False),
102
108
  help="当年没有提交时回退到上一年,适合跨年自动更新")
103
- scan.add_argument("--alias", action="append", default=cfg.get("aliases", []),
109
+ scan.add_argument("--alias", action=_CopyAppendAction, default=list(cfg.get("aliases", [])),
104
110
  help="额外作者邮箱或名字,可重复;用于旧提交")
105
111
  scan.add_argument("--no-mailmap", action="store_true",
106
112
  default=cfg.get("no_mailmap", False),
@@ -151,22 +157,7 @@ def _open_path(path: Path) -> None:
151
157
 
152
158
  def _detect_identity() -> tuple[str, str] | None:
153
159
  """The runner's git identity, used to keep only their own commits."""
154
-
155
- def config(key: str) -> str:
156
- try:
157
- proc = subprocess.run(
158
- ["git", "config", "--global", key],
159
- capture_output=True, text=True, encoding="utf-8",
160
- errors="replace", timeout=10, creationflags=_NO_WINDOW,
161
- )
162
- except (OSError, subprocess.TimeoutExpired):
163
- return ""
164
- return (proc.stdout or "").strip()
165
-
166
- email, name = config("user.email"), config("user.name")
167
- if email or name:
168
- return (email, name)
169
- return None
160
+ return detect_identity()
170
161
 
171
162
 
172
163
  def main(argv: list[str] | None = None) -> int:
@@ -296,6 +287,7 @@ def main(argv: list[str] | None = None) -> int:
296
287
  jobs=max(1, args.jobs), progress=progress,
297
288
  compare=args.compare, use_mailmap=not args.no_mailmap,
298
289
  all_branches=args.all_branches,
290
+ rolling=args.rolling,
299
291
  )
300
292
  if previous.commit_count:
301
293
  stats, warnings = previous, prev_warnings
@@ -312,56 +304,31 @@ def main(argv: list[str] | None = None) -> int:
312
304
  return 3
313
305
 
314
306
  out_dir = Path(args.out)
315
- out_dir.mkdir(parents=True, exist_ok=True)
316
- base = out_dir / f"codeyear-{args.year}"
317
-
318
- written: list[tuple[str, Path]] = []
319
-
320
- json_path = base.with_suffix(".json")
321
- json_path.write_text(
322
- json.dumps(stats.as_dict(), ensure_ascii=False, indent=2),
323
- encoding="utf-8",
324
- )
325
- written.append(("JSON", json_path))
326
-
307
+ formats = {"json"}
327
308
  if not args.no_html:
328
- html_path = render_html(stats, base.with_suffix(".html"))
329
- written.append(("HTML", html_path))
330
- en_path = render_html_en(stats, out_dir / f"codeyear-{args.year}-en.html")
331
- written.append(("HTML-EN", en_path))
332
-
309
+ formats.add("html")
333
310
  if not args.no_png:
334
- png_path = render_poster(stats, base.with_suffix(".png"))
335
- written.append(("PNG", png_path))
336
- if i18n.get_lang() == "en":
337
- png_en = render_poster(
338
- stats, out_dir / f"codeyear-{args.year}-en.png", lang="en")
339
- written.append(("PNG-EN", png_en))
311
+ formats.add("png")
340
312
  if not args.no_long:
341
- long_path = render_long(stats, out_dir / f"codeyear-{args.year}-long.png")
342
- written.append(("LONG", long_path))
343
- if i18n.get_lang() == "en":
344
- long_en = render_long(
345
- stats, out_dir / f"codeyear-{args.year}-en-long.png",
346
- lang="en")
347
- written.append(("LONG-EN", long_en))
348
-
349
- card_paths = []
350
- en_cards = []
351
- card_theme = getattr(args, "theme", "paper") or "paper"
313
+ formats.add("long")
352
314
  if not args.no_card:
353
- card_paths = render_card(
354
- stats, out_dir / f"codeyear-{args.year}-card.svg",
355
- theme=card_theme,
356
- )
357
- written.append(("CARD", card_paths[0]))
358
- written.append(("CARD-DARK", card_paths[1]))
359
- en_cards = render_card(
360
- stats, out_dir / f"codeyear-{args.year}-card-en.svg",
361
- theme=card_theme, lang="en",
362
- )
363
- written.append(("CARD-EN", en_cards[0]))
364
- written.append(("CARD-DARK-EN", en_cards[1]))
315
+ formats.add("card")
316
+ card_theme = getattr(args, "theme", "paper") or "paper"
317
+ written = render(
318
+ stats, out_dir, formats=formats,
319
+ card_theme=card_theme, lang=i18n.get_lang(),
320
+ )
321
+ by_label = dict(written)
322
+ card_paths = (
323
+ [by_label["CARD"], by_label["CARD-DARK"]]
324
+ if "CARD" in by_label and "CARD-DARK" in by_label
325
+ else []
326
+ )
327
+ en_cards = (
328
+ [by_label["CARD-EN"], by_label["CARD-DARK-EN"]]
329
+ if "CARD-EN" in by_label and "CARD-DARK-EN" in by_label
330
+ else []
331
+ )
365
332
 
366
333
  exit_code = 0
367
334
  if args.profile_repo:
@@ -398,7 +365,7 @@ def main(argv: list[str] | None = None) -> int:
398
365
  exit_code = 1
399
366
 
400
367
  # Console summary
401
- active_pct = stats.active_days / (366 if _is_leap(args.year) else 365)
368
+ active_pct = stats.active_days / window_days(stats)
402
369
  print()
403
370
  print(i18n.tr(
404
371
  "CodeYear {year} · {title}",
@@ -446,9 +413,5 @@ def main(argv: list[str] | None = None) -> int:
446
413
  return exit_code
447
414
 
448
415
 
449
- def _is_leap(year: int) -> bool:
450
- return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)
451
-
452
-
453
416
  if __name__ == "__main__": # pragma: no cover
454
417
  raise SystemExit(main())
codeyear/config.py CHANGED
@@ -36,6 +36,7 @@ SCHEMA = {
36
36
  "github_user": str,
37
37
  "profile_repo": str,
38
38
  "push_profile": bool,
39
+ "lang": str,
39
40
  }
40
41
 
41
42
 
@@ -76,6 +77,8 @@ def load() -> dict:
76
77
  "paper", "mono", "forest", "ocean",
77
78
  }:
78
79
  continue
80
+ if key == "lang" and value not in {"zh", "en"}:
81
+ continue
79
82
  clean[key] = value
80
83
  if clean.get("max_commits", 1) <= 0:
81
84
  clean.pop("max_commits", None)
@@ -105,6 +108,8 @@ def save(values: dict) -> Path:
105
108
  elif expected is str and isinstance(value, str):
106
109
  if key == "theme" and value not in {"paper", "mono", "forest", "ocean"}:
107
110
  continue
111
+ if key == "lang" and value not in {"zh", "en"}:
112
+ continue
108
113
  clean[key] = value
109
114
  target = path()
110
115
  target.parent.mkdir(parents=True, exist_ok=True)
codeyear/github_public.py CHANGED
@@ -108,6 +108,32 @@ def _load_cache(path: Path | None) -> dict:
108
108
  return details if isinstance(details, dict) else {}
109
109
 
110
110
 
111
+ def _slim_detail(detail: dict) -> dict:
112
+ """Keep only fields needed by CodeYear, dropping multi-KB diff patches."""
113
+ commit = detail.get("commit") or {}
114
+ author = commit.get("author") or {}
115
+ msg_lines = (commit.get("message") or "").splitlines()
116
+ return {
117
+ "parents": [{} for _ in (detail.get("parents") or [])],
118
+ "commit": {
119
+ "author": {"date": author.get("date")},
120
+ "message": msg_lines[0][:200] if msg_lines else "",
121
+ },
122
+ "stats": {
123
+ "additions": int((detail.get("stats") or {}).get("additions", 0)),
124
+ "deletions": int((detail.get("stats") or {}).get("deletions", 0)),
125
+ },
126
+ "files": [
127
+ {
128
+ "filename": f.get("filename") or "",
129
+ "additions": int(f.get("additions", 0)),
130
+ "deletions": int(f.get("deletions", 0)),
131
+ }
132
+ for f in (detail.get("files") or [])
133
+ ],
134
+ }
135
+
136
+
111
137
  def _save_cache(path: Path | None, details: dict) -> None:
112
138
  if path is None:
113
139
  return
@@ -250,6 +276,16 @@ def _commits(
250
276
  since = f"{year - 1}-12-31T00:00:00Z"
251
277
  until = f"{year + 1}-01-02T00:00:00Z"
252
278
  listed = _IncompleteList()
279
+ def _eligible_list_item(item: dict) -> bool:
280
+ if len(item.get("parents") or []) > 1:
281
+ return False
282
+ raw_date = ((item.get("commit") or {}).get("author") or {}).get("date")
283
+ if raw_date:
284
+ d = _dt(raw_date, tz=target_tz)
285
+ if d is not None and d.year != year:
286
+ return False
287
+ return True
288
+
253
289
  # A busy repository can exceed 1,000 commits in one year; keep paging
254
290
  # until the caller's budget is reached or GitHub runs out of pages.
255
291
  for page in range(1, 101):
@@ -259,8 +295,27 @@ def _commits(
259
295
  })
260
296
  if not data:
261
297
  break
262
- listed.extend(data)
263
- if len(data) < 100 or len(listed) >= limit:
298
+ eligible = [item for item in data if _eligible_list_item(item)]
299
+ if len(listed) + len(eligible) > limit:
300
+ listed.extend(eligible[: limit - len(listed)])
301
+ listed.truncated = True
302
+ break
303
+ listed.extend(eligible)
304
+ if len(data) < 100:
305
+ break
306
+ if len(listed) >= limit:
307
+ # At an exact page boundary, completeness cannot be inferred from
308
+ # a full page alone. Probe for another entry rather than warn on a
309
+ # repository whose history ends exactly at the limit.
310
+ if len(listed) == limit and page < 100:
311
+ extra = api.get(f"/repos/{full}/commits", {
312
+ "author": username, "since": since, "until": until,
313
+ "per_page": 100, "page": page + 1,
314
+ }) or []
315
+ extra_eligible = [it for it in extra if _eligible_list_item(it)]
316
+ listed.truncated = bool(extra_eligible or len(extra) == 100)
317
+ else:
318
+ listed.truncated = True
264
319
  break
265
320
  else:
266
321
  listed.truncated = True
@@ -286,7 +341,7 @@ def _commits(
286
341
  idx, item = entry
287
342
  detail = api.get(f"/repos/{full}/commits/{item['sha']}")
288
343
  if cache is not None and detail:
289
- cache[keys[idx]] = detail
344
+ cache[keys[idx]] = _slim_detail(detail)
290
345
  return detail
291
346
 
292
347
  # Commit details are independent; a small pool cuts wall time without
@@ -296,9 +351,13 @@ def _commits(
296
351
  for (index, _item), detail in zip(missing, fetched):
297
352
  details[index] = detail
298
353
 
299
- commits: list[Commit] = []
354
+ commits = _IncompleteList()
355
+ # The list endpoint may have more entries than the detail budget, or may
356
+ # hit our page cap. Preserve that fact even when filtering removes merges.
357
+ commits.truncated = listed.truncated or len(listed) > limit
300
358
  for item, detail in zip(items, details):
301
359
  if not detail:
360
+ commits.truncated = True
302
361
  continue
303
362
  # Match the local scanner's --no-merges behavior.
304
363
  if len(detail.get("parents") or []) > 1:
@@ -307,7 +366,10 @@ def _commits(
307
366
  dt = _dt(author_date, tz=target_tz)
308
367
  if dt is None:
309
368
  dt = _dt((item.get("commit") or {}).get("author", {}).get("date"), tz=target_tz)
310
- if dt is None or dt.year != year:
369
+ if dt is None:
370
+ commits.truncated = True
371
+ continue
372
+ if dt.year != year:
311
373
  continue
312
374
  message = ((detail.get("commit") or {}).get("message") or "").splitlines()
313
375
  subject = message[0].strip() if message else ""
@@ -346,7 +408,7 @@ def _commits(
346
408
 
347
409
 
348
410
  def _total_commits(api: GitHubAPI, full: str, username: str) -> int:
349
- for _ in range(3):
411
+ for attempt in range(2):
350
412
  data = api.get(f"/repos/{full}/stats/contributors")
351
413
  if isinstance(data, list):
352
414
  for contributor in data:
@@ -354,7 +416,8 @@ def _total_commits(api: GitHubAPI, full: str, username: str) -> int:
354
416
  if (author.get("login") or "").lower() == username.lower():
355
417
  return sum(int(week.get("c", 0)) for week in contributor.get("weeks", []))
356
418
  return 0
357
- time.sleep(1)
419
+ if attempt == 0:
420
+ time.sleep(0.35)
358
421
  return 0
359
422
 
360
423
 
@@ -421,18 +484,19 @@ def fetch_stats(
421
484
  except RuntimeError as exc:
422
485
  warnings.append(str(exc))
423
486
  break
487
+ if getattr(commits, "truncated", False):
488
+ warnings.append(i18n.tr(
489
+ "{repo} 的提交数据可能不完整(分页、数量上限或详情缺失)。", repo=full,
490
+ ))
424
491
  if not commits:
425
492
  continue
426
493
  total += len(commits)
427
- if total >= max_commits:
494
+ if total >= max_commits and (
495
+ getattr(commits, "truncated", False) or index < len(repos)
496
+ ):
428
497
  warnings.append(i18n.tr(
429
498
  "已达到 --max-commits 上限({limit})", limit=max_commits,
430
499
  ))
431
- try:
432
- repo_total = _total_commits(api, full, login)
433
- except RuntimeError as exc:
434
- warnings.append(str(exc))
435
- repo_total = 0
436
500
  results.append(RepoResult(
437
501
  path=Path(full),
438
502
  name=full,
@@ -441,10 +505,26 @@ def fetch_stats(
441
505
  readme_line=repo.get("description") or "",
442
506
  root=full,
443
507
  root_dt=_dt(repo.get("created_at"), tz=target_tz),
444
- total_commits=repo_total or len(commits),
508
+ total_commits=len(commits),
445
509
  tags_in_year=0,
446
510
  ))
447
511
 
512
+ if results:
513
+ def _fetch_repo_total(res: RepoResult) -> tuple[int, str | None]:
514
+ try:
515
+ return _total_commits(api, res.name, login), None
516
+ except RuntimeError as exc:
517
+ return 0, str(exc)
518
+
519
+ with ThreadPoolExecutor(
520
+ max_workers=min(len(results), DETAIL_WORKERS)
521
+ ) as pool:
522
+ totals = list(pool.map(_fetch_repo_total, results))
523
+ for res, (repo_total, err) in zip(results, totals):
524
+ if err:
525
+ warnings.append(err)
526
+ res.total_commits = repo_total or len(res.commits)
527
+
448
528
  if not results:
449
529
  _save_cache(cache_path, cache)
450
530
  if warnings:
codeyear/gui.py CHANGED
@@ -239,9 +239,10 @@ class App:
239
239
  self.depth_var = tk.StringVar(
240
240
  value=str(self.cfg.get("max_depth", 6))
241
241
  )
242
- ttk.Entry(
242
+ self.depth_entry = ttk.Entry(
243
243
  options, width=6, textvariable=self.depth_var, style="CY.TEntry",
244
- ).grid(row=1, column=1, sticky="w", padx=(22, 0), pady=(2, 0))
244
+ )
245
+ self.depth_entry.grid(row=1, column=1, sticky="w", padx=(22, 0), pady=(2, 0))
245
246
 
246
247
  tk.Label(options, text=i18n.tr("卡片主题"), bg=PAPER, fg=MUTED,
247
248
  font=("Microsoft YaHei", 9)).grid(
@@ -285,9 +286,10 @@ class App:
285
286
  self.jobs_var = tk.StringVar(
286
287
  value=str(self.cfg.get("jobs", 1))
287
288
  )
288
- ttk.Entry(
289
+ self.jobs_entry = ttk.Entry(
289
290
  advanced, width=4, textvariable=self.jobs_var, style="CY.TEntry",
290
- ).pack(side="left", padx=(6, 20))
291
+ )
292
+ self.jobs_entry.pack(side="left", padx=(6, 20))
291
293
  self.compare_var = tk.BooleanVar(
292
294
  value=bool(self.cfg.get("compare", False))
293
295
  )
@@ -314,17 +316,19 @@ class App:
314
316
  self.alias_var = tk.StringVar(
315
317
  value=", ".join(self.cfg.get("aliases", []))
316
318
  )
317
- ttk.Entry(
319
+ self.alias_entry = ttk.Entry(
318
320
  advanced, width=14, textvariable=self.alias_var, style="CY.TEntry",
319
- ).pack(side="left")
321
+ )
322
+ self.alias_entry.pack(side="left")
320
323
  tk.Label(advanced, text=i18n.tr("排除仓库"), bg=PAPER, fg=MUTED,
321
324
  font=("Microsoft YaHei", 9)).pack(side="left", padx=(14, 6))
322
325
  self.exclude_var = tk.StringVar(
323
326
  value=", ".join(self.cfg.get("exclude", []))
324
327
  )
325
- ttk.Entry(
328
+ self.exclude_entry = ttk.Entry(
326
329
  advanced, width=14, textvariable=self.exclude_var, style="CY.TEntry",
327
- ).pack(side="left")
330
+ )
331
+ self.exclude_entry.pack(side="left")
328
332
 
329
333
  out_row = tk.Frame(body, bg=PAPER)
330
334
  out_row.pack(fill="x", pady=(0, 8))
@@ -422,6 +426,23 @@ class App:
422
426
  command=self.result.yview)
423
427
  rscroll.pack(side="right", fill="y")
424
428
  self.result.configure(yscrollcommand=rscroll.set, state="disabled")
429
+ self.github_var.trace_add("write", lambda *_args: self._sync_mode())
430
+ self._sync_mode()
431
+
432
+ def _sync_mode(self) -> None:
433
+ gh_mode = bool(self.github_var.get().strip())
434
+ local_state = "disabled" if (gh_mode or self.busy) else "normal"
435
+ for entry in (
436
+ self.depth_entry, self.jobs_entry,
437
+ self.alias_entry, self.exclude_entry,
438
+ ):
439
+ entry.configure(state=local_state)
440
+ self._local_checks_disabled = gh_mode
441
+ for redraw in (
442
+ self._identity_draw, self._compare_draw,
443
+ self._branches_draw, self._rolling_draw,
444
+ ):
445
+ redraw()
425
446
 
426
447
  def _button(self, parent, text, command):
427
448
  return ttk.Button(
@@ -598,6 +619,7 @@ class App:
598
619
  "push_profile": bool(self.push_profile_var.get()),
599
620
  "out": self.out_var.get().strip() or "codeyear-output",
600
621
  "theme": self.theme_var.get() or "paper",
622
+ "lang": i18n.get_lang(),
601
623
  }
602
624
  try:
603
625
  save_config(data)
@@ -797,6 +819,8 @@ class App:
797
819
  self.lang_btn.configure(state=state)
798
820
  if hasattr(self, "update_btn"):
799
821
  self.update_btn.configure(state=state)
822
+ if hasattr(self, "depth_entry"):
823
+ self._sync_mode()
800
824
 
801
825
  def _bg_check_update(self, manual: bool) -> None:
802
826
  info = check_update(timeout=5.0 if manual else 2.5)
@@ -889,9 +913,18 @@ class App:
889
913
  )
890
914
  label.pack(side="left")
891
915
 
916
+ def is_disabled() -> bool:
917
+ if not enabled:
918
+ return True
919
+ return bool(
920
+ getattr(self, "_local_checks_disabled", False)
921
+ and variable is not getattr(self, "push_profile_var", None)
922
+ )
923
+
892
924
  def draw() -> None:
893
925
  canvas.delete("all")
894
- if not enabled:
926
+ label.configure(fg=MUTED if is_disabled() else INK)
927
+ if is_disabled():
895
928
  canvas.create_rectangle(1, 1, 15, 15, outline=LINE, fill=PAPER2)
896
929
  return
897
930
  if variable.get():
@@ -904,7 +937,7 @@ class App:
904
937
  canvas.create_rectangle(1, 1, 15, 15, outline=LINE, fill="white")
905
938
 
906
939
  def toggle(_event=None) -> None:
907
- if not enabled or self.busy:
940
+ if is_disabled() or self.busy:
908
941
  return
909
942
  variable.set(not variable.get())
910
943
  draw()
@@ -948,7 +981,14 @@ def _enable_dpi() -> None:
948
981
 
949
982
  def run() -> int:
950
983
  cleanup_old_executable()
951
- i18n.set_lang(i18n.detect(sys.argv[1:]))
984
+ argv = sys.argv[1:]
985
+ has_explicit_lang = (
986
+ "--lang" in argv
987
+ or any(a.startswith("--lang=") for a in argv)
988
+ or bool(os.environ.get("CODEYEAR_LANG"))
989
+ )
990
+ cfg_lang = load_config().get("lang") if not has_explicit_lang else None
991
+ i18n.set_lang(cfg_lang or i18n.detect(argv))
952
992
  _enable_dpi()
953
993
  try:
954
994
  root = tk.Tk()