pkgmgr-kunrunic 0.1.0.dev9__tar.gz → 0.1.1.dev0__tar.gz

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.
Files changed (31) hide show
  1. {pkgmgr_kunrunic-0.1.0.dev9/pkgmgr_kunrunic.egg-info → pkgmgr_kunrunic-0.1.1.dev0}/PKG-INFO +1 -1
  2. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/__init__.py +1 -1
  3. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/cli.py +4 -1
  4. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/snapshot.py +98 -9
  5. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0/pkgmgr_kunrunic.egg-info}/PKG-INFO +1 -1
  6. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/SOURCES.txt +1 -0
  7. pkgmgr_kunrunic-0.1.1.dev0/tests/test_progress.py +32 -0
  8. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/LICENSE +0 -0
  9. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/README.md +0 -0
  10. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/__main__.py +0 -0
  11. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/collectors/__init__.py +0 -0
  12. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/collectors/base.py +0 -0
  13. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/collectors/checksums.py +0 -0
  14. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/config.py +0 -0
  15. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/gitcollect.py +0 -0
  16. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/points.py +0 -0
  17. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/release.py +0 -0
  18. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/shell_integration.py +0 -0
  19. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/templates/pkg.yaml.sample +0 -0
  20. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/templates/pkgmgr.yaml.sample +0 -0
  21. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/watch.py +0 -0
  22. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/dependency_links.txt +0 -0
  23. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/entry_points.txt +0 -0
  24. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/not-zip-safe +0 -0
  25. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/requires.txt +0 -0
  26. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/top_level.txt +0 -0
  27. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/pyproject.toml +0 -0
  28. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/setup.cfg +0 -0
  29. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/tests/test_config.py +0 -0
  30. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/tests/test_release.py +0 -0
  31. {pkgmgr_kunrunic-0.1.0.dev9 → pkgmgr_kunrunic-0.1.1.dev0}/tests/test_snapshot.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pkgmgr-kunrunic
3
- Version: 0.1.0.dev9
3
+ Version: 0.1.1.dev0
4
4
  Summary: Package management workflow scaffold.
5
5
  Author: pkgmgr maintainers
6
6
  License: MIT License
@@ -14,4 +14,4 @@ __all__ = [
14
14
  "points",
15
15
  ]
16
16
 
17
- __version__ = "0.1.0.dev9"
17
+ __version__ = "0.1.1.dev0"
@@ -192,8 +192,11 @@ def _handle_make_config(args):
192
192
 
193
193
  def _handle_install(args):
194
194
  cfg = config.load_main(args.config)
195
+ print("[install] step 1/2: shell integration")
195
196
  release.ensure_environment()
196
- snapshot.create_baseline(cfg, prompt_overwrite=True)
197
+ print("[install] step 2/2: baseline snapshot")
198
+ progress = snapshot.ProgressReporter("scan")
199
+ snapshot.create_baseline(cfg, prompt_overwrite=True, progress=progress)
197
200
  return 0
198
201
 
199
202
 
@@ -17,6 +17,69 @@ class DuplicateBaselineError(RuntimeError):
17
17
  """Raised when attempting to create a baseline that already exists."""
18
18
 
19
19
 
20
+ class ProgressReporter(object):
21
+ """TTY-friendly one-line progress reporter (no-op when stdout is not a TTY)."""
22
+
23
+ def __init__(self, prefix):
24
+ self.prefix = prefix
25
+ self._is_tty = sys.stdout.isatty()
26
+ self._last_len = 0
27
+ self._label = None
28
+ self._total = 0
29
+ self._current = 0
30
+
31
+ def start(self, label, total):
32
+ if not self._is_tty:
33
+ return
34
+ self._label = label
35
+ self._total = int(total or 0)
36
+ self._current = 0
37
+ self._render()
38
+
39
+ def advance(self, step=1):
40
+ if not self._is_tty:
41
+ return
42
+ self._current += int(step or 0)
43
+ if self._current > self._total:
44
+ self._current = self._total
45
+ self._render()
46
+
47
+ def finish(self):
48
+ if not self._is_tty:
49
+ return
50
+ if self._total == 0:
51
+ self._current = 0
52
+ else:
53
+ self._current = self._total
54
+ self._render(final=True)
55
+ sys.stdout.write("\n")
56
+ sys.stdout.flush()
57
+
58
+ def _render(self, final=False):
59
+ total = self._total
60
+ current = self._current
61
+ denom = total if total > 0 else 1
62
+ pct = int((float(current) / float(denom)) * 100)
63
+ if total == 0 and final:
64
+ pct = 100
65
+ bar_len = 30
66
+ filled = int((float(current) / float(denom)) * bar_len)
67
+ bar = "#" * filled + "-" * (bar_len - filled)
68
+ label = self._label or ""
69
+ line = "[%s] %s %d/%d %3d%% [%s]" % (
70
+ self.prefix,
71
+ label,
72
+ current,
73
+ total,
74
+ pct,
75
+ bar,
76
+ )
77
+ pad = " " * max(0, self._last_len - len(line))
78
+ sys.stdout.write("\r" + line + pad)
79
+ sys.stdout.flush()
80
+ self._last_len = len(line)
81
+
82
+
20
83
  def _ensure_state_dir():
21
84
  if not os.path.exists(STATE_DIR):
22
85
  os.makedirs(STATE_DIR)
@@ -43,12 +106,27 @@ def _should_skip(relpath, patterns):
43
106
  return False
44
107
 
45
108
 
46
- def _scan(root, exclude):
109
+ def _count_files(root_abs, exclude):
110
+ total = 0
111
+ for base, _, files in os.walk(root_abs):
112
+ for name in files:
113
+ abspath = os.path.join(base, name)
114
+ rel = os.path.relpath(abspath, root_abs).replace("\\", "/")
115
+ if _should_skip(rel, exclude):
116
+ continue
117
+ total += 1
118
+ return total
119
+
120
+
121
+ def _scan(root, exclude, progress=None, label=None):
47
122
  res = {}
48
123
  root_abs = os.path.abspath(os.path.expanduser(root))
49
124
  if not os.path.exists(root_abs):
50
125
  print("[snap] skip missing root: %s" % root_abs)
51
126
  return res
127
+ if progress and label:
128
+ total = _count_files(root_abs, exclude)
129
+ progress.start(label, total)
52
130
  for base, _, files in os.walk(root_abs):
53
131
  for name in files:
54
132
  abspath = os.path.join(base, name)
@@ -64,6 +142,10 @@ def _scan(root, exclude):
64
142
  }
65
143
  except Exception as e:
66
144
  print("[snap] warn skip %s: %s" % (abspath, str(e)))
145
+ if progress:
146
+ progress.advance()
147
+ if progress and label:
148
+ progress.finish()
67
149
  return res
68
150
 
69
151
 
@@ -88,7 +170,7 @@ def _maybe_keep_existing_baseline(path, prompt_overwrite):
88
170
  return None
89
171
 
90
172
 
91
- def _scan_artifacts(cfg):
173
+ def _scan_artifacts(cfg, progress=None):
92
174
  """
93
175
  Scan artifact roots/targets similar to sources.
94
176
  artifacts.root: base path (optional)
@@ -109,11 +191,12 @@ def _scan_artifacts(cfg):
109
191
  else:
110
192
  target_path = target_str
111
193
  target_path = os.path.abspath(os.path.expanduser(target_path))
112
- result[target_path] = _scan(target_path, art_exclude)
194
+ label = "artifact %s" % target_path
195
+ result[target_path] = _scan(target_path, art_exclude, progress=progress, label=label)
113
196
  return result
114
197
 
115
198
 
116
- def create_baseline(cfg, prompt_overwrite=False):
199
+ def create_baseline(cfg, prompt_overwrite=False, progress=None):
117
200
  """
118
201
  Collect initial baseline snapshot.
119
202
  Scans sources and artifacts (if configured).
@@ -132,9 +215,12 @@ def create_baseline(cfg, prompt_overwrite=False):
132
215
  }
133
216
 
134
217
  for root in sources:
135
- snapshot_data["sources"][root] = _scan(root, src_exclude)
218
+ label = "source %s" % root
219
+ snapshot_data["sources"][root] = _scan(
220
+ root, src_exclude, progress=progress, label=label
221
+ )
136
222
 
137
- snapshot_data["artifacts"] = _scan_artifacts(cfg)
223
+ snapshot_data["artifacts"] = _scan_artifacts(cfg, progress=progress)
138
224
 
139
225
  path = os.path.join(STATE_DIR, "baseline.json")
140
226
  existing = _maybe_keep_existing_baseline(path, prompt_overwrite)
@@ -150,7 +236,7 @@ def create_baseline(cfg, prompt_overwrite=False):
150
236
  return snapshot_data
151
237
 
152
238
 
153
- def create_snapshot(cfg):
239
+ def create_snapshot(cfg, progress=None):
154
240
  """
155
241
  Collect a fresh snapshot (for updates).
156
242
  """
@@ -168,9 +254,12 @@ def create_snapshot(cfg):
168
254
  }
169
255
 
170
256
  for root in sources:
171
- snapshot_data["sources"][root] = _scan(root, src_exclude)
257
+ label = "source %s" % root
258
+ snapshot_data["sources"][root] = _scan(
259
+ root, src_exclude, progress=progress, label=label
260
+ )
172
261
 
173
- snapshot_data["artifacts"] = _scan_artifacts(cfg)
262
+ snapshot_data["artifacts"] = _scan_artifacts(cfg, progress=progress)
174
263
 
175
264
  path = os.path.join(STATE_DIR, "snapshot.json")
176
265
  f = open(path, "w")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pkgmgr-kunrunic
3
- Version: 0.1.0.dev9
3
+ Version: 0.1.1.dev0
4
4
  Summary: Package management workflow scaffold.
5
5
  Author: pkgmgr maintainers
6
6
  License: MIT License
@@ -24,5 +24,6 @@ pkgmgr_kunrunic.egg-info/not-zip-safe
24
24
  pkgmgr_kunrunic.egg-info/requires.txt
25
25
  pkgmgr_kunrunic.egg-info/top_level.txt
26
26
  tests/test_config.py
27
+ tests/test_progress.py
27
28
  tests/test_release.py
28
29
  tests/test_snapshot.py
@@ -0,0 +1,32 @@
1
+ import sys
2
+ from importlib import import_module, reload
3
+
4
+ snapshot = import_module("pkgmgr.snapshot")
5
+ reload(snapshot)
6
+
7
+
8
+ def test_progress_reporter_tty_outputs_single_line(capsys, monkeypatch):
9
+ monkeypatch.setattr(sys.stdout, "isatty", lambda: True)
10
+ reporter = snapshot.ProgressReporter("scan")
11
+
12
+ reporter.start("source /tmp", 3)
13
+ reporter.advance()
14
+ reporter.advance()
15
+ reporter.finish()
16
+
17
+ out = capsys.readouterr().out
18
+ assert "\r[scan]" in out
19
+ assert "source /tmp" in out
20
+ assert out.endswith("\n")
21
+
22
+
23
+ def test_progress_reporter_non_tty_is_silent(capsys, monkeypatch):
24
+ monkeypatch.setattr(sys.stdout, "isatty", lambda: False)
25
+ reporter = snapshot.ProgressReporter("scan")
26
+
27
+ reporter.start("source /tmp", 3)
28
+ reporter.advance()
29
+ reporter.finish()
30
+
31
+ out = capsys.readouterr().out
32
+ assert out == ""