pkgmgr-kunrunic 0.1.0.dev8__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.
- {pkgmgr_kunrunic-0.1.0.dev8/pkgmgr_kunrunic.egg-info → pkgmgr_kunrunic-0.1.1.dev0}/PKG-INFO +1 -1
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/__init__.py +1 -1
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/cli.py +4 -1
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/release.py +19 -12
- pkgmgr_kunrunic-0.1.1.dev0/pkgmgr/shell_integration.py +83 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/snapshot.py +107 -22
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0/pkgmgr_kunrunic.egg-info}/PKG-INFO +1 -1
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/SOURCES.txt +4 -1
- pkgmgr_kunrunic-0.1.1.dev0/tests/test_progress.py +32 -0
- pkgmgr_kunrunic-0.1.1.dev0/tests/test_release.py +160 -0
- pkgmgr_kunrunic-0.1.1.dev0/tests/test_snapshot.py +28 -0
- pkgmgr_kunrunic-0.1.0.dev8/pkgmgr/shell_integration.py +0 -119
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/LICENSE +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/README.md +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/__main__.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/collectors/__init__.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/collectors/base.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/collectors/checksums.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/config.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/gitcollect.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/points.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/templates/pkg.yaml.sample +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/templates/pkgmgr.yaml.sample +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/watch.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/dependency_links.txt +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/entry_points.txt +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/not-zip-safe +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/requires.txt +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/top_level.txt +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pyproject.toml +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/setup.cfg +0 -0
- {pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/tests/test_config.py +0 -0
|
@@ -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
|
-
|
|
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
|
|
|
@@ -14,10 +14,9 @@ from .collectors import checksums as checksums_module
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
def ensure_environment():
|
|
17
|
-
"""Prepare environment:
|
|
17
|
+
"""Prepare environment: print shell PATH/alias instructions."""
|
|
18
18
|
script_dir = os.path.dirname(sys.executable)
|
|
19
19
|
shell_integration.ensure_path_and_alias(script_dir)
|
|
20
|
-
print("[install] ensured shell PATH/alias for script dir: %s" % script_dir)
|
|
21
20
|
|
|
22
21
|
|
|
23
22
|
def _pkg_dir(cfg, pkg_id):
|
|
@@ -475,19 +474,12 @@ def _prepare_release(pkg_dir, pkg_cfg):
|
|
|
475
474
|
root_dir = os.path.join(release_root, root)
|
|
476
475
|
next_ver, prev_dir = _next_release_version(root_dir)
|
|
477
476
|
release_name = _format_version(next_ver)
|
|
478
|
-
release_dir = os.path.join(root_dir, release_name)
|
|
479
|
-
if not os.path.exists(release_dir):
|
|
480
|
-
os.makedirs(release_dir)
|
|
481
|
-
|
|
482
477
|
prev_hashes = _load_prev_hashes(prev_dir) if prev_dir else {}
|
|
483
478
|
copied = []
|
|
484
479
|
skipped = []
|
|
480
|
+
to_copy = []
|
|
485
481
|
|
|
486
482
|
for src, rel in entries:
|
|
487
|
-
dest = os.path.join(release_dir, rel)
|
|
488
|
-
dest_parent = os.path.dirname(dest)
|
|
489
|
-
if dest_parent and not os.path.exists(dest_parent):
|
|
490
|
-
os.makedirs(dest_parent)
|
|
491
483
|
prev_hash = prev_hashes.get(rel)
|
|
492
484
|
try:
|
|
493
485
|
curr_hash = checksums_module.sha256_of_file(src)
|
|
@@ -497,11 +489,26 @@ def _prepare_release(pkg_dir, pkg_cfg):
|
|
|
497
489
|
if prev_hash and prev_hash == curr_hash:
|
|
498
490
|
skipped.append(rel)
|
|
499
491
|
continue
|
|
500
|
-
shutil.copy2(src, dest)
|
|
501
492
|
copied.append(rel)
|
|
493
|
+
to_copy.append((src, rel))
|
|
494
|
+
|
|
495
|
+
if prev_dir and not copied:
|
|
496
|
+
print("[update-pkg] no changes for %s; skipping release" % root)
|
|
497
|
+
continue
|
|
498
|
+
|
|
499
|
+
release_dir = os.path.join(root_dir, release_name)
|
|
500
|
+
if not os.path.exists(release_dir):
|
|
501
|
+
os.makedirs(release_dir)
|
|
502
|
+
|
|
503
|
+
for src, rel in to_copy:
|
|
504
|
+
dest = os.path.join(release_dir, rel)
|
|
505
|
+
dest_parent = os.path.dirname(dest)
|
|
506
|
+
if dest_parent and not os.path.exists(dest_parent):
|
|
507
|
+
os.makedirs(dest_parent)
|
|
508
|
+
shutil.copy2(src, dest)
|
|
502
509
|
|
|
503
510
|
ts = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
|
|
504
|
-
prev_label =
|
|
511
|
+
prev_label = os.path.basename(prev_dir) if prev_dir else "none"
|
|
505
512
|
readme_lines = [
|
|
506
513
|
"Release root: %s" % root,
|
|
507
514
|
"Release: %s" % release_name,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
from __future__ import print_function
|
|
2
|
+
"""Shell integration helpers: print PATH/alias instructions per shell."""
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
from . import config
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def ensure_path_and_alias(script_dir, alias_name="pkg", command="pkgmgr"):
|
|
10
|
+
"""
|
|
11
|
+
Print PATH/alias instructions for the current shell.
|
|
12
|
+
script_dir: directory where the pkgmgr console script lives (e.g. venv/bin).
|
|
13
|
+
"""
|
|
14
|
+
if not script_dir:
|
|
15
|
+
print("[install] script_dir not provided; skip shell integration")
|
|
16
|
+
return
|
|
17
|
+
shell = os.environ.get("SHELL", "")
|
|
18
|
+
shell_name = os.path.basename(shell) if shell else ""
|
|
19
|
+
|
|
20
|
+
try:
|
|
21
|
+
lines = _instructions_for_shell(shell_name, script_dir, alias_name, command)
|
|
22
|
+
except Exception as e:
|
|
23
|
+
print("[install] shell integration failed for %s: %s" % (shell_name, str(e)))
|
|
24
|
+
return
|
|
25
|
+
|
|
26
|
+
if not lines:
|
|
27
|
+
print("[install] unknown shell '%s'; skipping rc update" % (shell_name or ""))
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
header = "[install] To use pkgmgr, add these lines to your shell rc:"
|
|
31
|
+
for line in _emit_lines_with_header(header, lines):
|
|
32
|
+
print(line)
|
|
33
|
+
readme_path = _write_readme(_emit_lines_with_header(header, lines))
|
|
34
|
+
if readme_path:
|
|
35
|
+
print("[install] Reference saved to: %s" % readme_path)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _instructions_for_shell(shell_name, script_dir, alias_name, command):
|
|
39
|
+
if shell_name == "bash":
|
|
40
|
+
lines = [
|
|
41
|
+
'export PATH="%s:$PATH"' % script_dir,
|
|
42
|
+
'alias %s="%s"' % (alias_name, command),
|
|
43
|
+
]
|
|
44
|
+
return lines
|
|
45
|
+
if shell_name == "zsh":
|
|
46
|
+
lines = [
|
|
47
|
+
'export PATH="%s:$PATH"' % script_dir,
|
|
48
|
+
'alias %s="%s"' % (alias_name, command),
|
|
49
|
+
]
|
|
50
|
+
return lines
|
|
51
|
+
if shell_name in ("csh", "tcsh"):
|
|
52
|
+
lines = [
|
|
53
|
+
"set path = (%s $path)" % script_dir,
|
|
54
|
+
"alias %s %s" % (alias_name, command),
|
|
55
|
+
]
|
|
56
|
+
return lines
|
|
57
|
+
if shell_name == "fish":
|
|
58
|
+
lines = [
|
|
59
|
+
"set -U fish_user_paths %s $fish_user_paths" % script_dir,
|
|
60
|
+
"alias %s %s" % (alias_name, command),
|
|
61
|
+
]
|
|
62
|
+
return lines
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _emit_lines_with_header(header, lines):
|
|
67
|
+
out = [header]
|
|
68
|
+
out.extend(lines)
|
|
69
|
+
return out
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _write_readme(lines):
|
|
73
|
+
readme_path = os.path.join(config.BASE_DIR, "README.txt")
|
|
74
|
+
try:
|
|
75
|
+
base_dir = os.path.dirname(readme_path)
|
|
76
|
+
if base_dir and not os.path.exists(base_dir):
|
|
77
|
+
os.makedirs(base_dir)
|
|
78
|
+
with open(readme_path, "w") as f:
|
|
79
|
+
for line in lines:
|
|
80
|
+
f.write(line + "\n")
|
|
81
|
+
return readme_path
|
|
82
|
+
except Exception:
|
|
83
|
+
return None
|
|
@@ -13,6 +13,73 @@ from . import config
|
|
|
13
13
|
STATE_DIR = config.DEFAULT_STATE_DIR
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
class DuplicateBaselineError(RuntimeError):
|
|
17
|
+
"""Raised when attempting to create a baseline that already exists."""
|
|
18
|
+
|
|
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
|
+
|
|
16
83
|
def _ensure_state_dir():
|
|
17
84
|
if not os.path.exists(STATE_DIR):
|
|
18
85
|
os.makedirs(STATE_DIR)
|
|
@@ -39,12 +106,27 @@ def _should_skip(relpath, patterns):
|
|
|
39
106
|
return False
|
|
40
107
|
|
|
41
108
|
|
|
42
|
-
def
|
|
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):
|
|
43
122
|
res = {}
|
|
44
123
|
root_abs = os.path.abspath(os.path.expanduser(root))
|
|
45
124
|
if not os.path.exists(root_abs):
|
|
46
125
|
print("[snap] skip missing root: %s" % root_abs)
|
|
47
126
|
return res
|
|
127
|
+
if progress and label:
|
|
128
|
+
total = _count_files(root_abs, exclude)
|
|
129
|
+
progress.start(label, total)
|
|
48
130
|
for base, _, files in os.walk(root_abs):
|
|
49
131
|
for name in files:
|
|
50
132
|
abspath = os.path.join(base, name)
|
|
@@ -60,13 +142,17 @@ def _scan(root, exclude):
|
|
|
60
142
|
}
|
|
61
143
|
except Exception as e:
|
|
62
144
|
print("[snap] warn skip %s: %s" % (abspath, str(e)))
|
|
145
|
+
if progress:
|
|
146
|
+
progress.advance()
|
|
147
|
+
if progress and label:
|
|
148
|
+
progress.finish()
|
|
63
149
|
return res
|
|
64
150
|
|
|
65
151
|
|
|
66
152
|
def _maybe_keep_existing_baseline(path, prompt_overwrite):
|
|
67
153
|
"""
|
|
68
154
|
When prompt_overwrite=True and baseline exists, ask user (if tty) whether to overwrite.
|
|
69
|
-
|
|
155
|
+
Raises DuplicateBaselineError when overwrite is declined or non-interactive.
|
|
70
156
|
"""
|
|
71
157
|
if not prompt_overwrite:
|
|
72
158
|
return None
|
|
@@ -74,25 +160,17 @@ def _maybe_keep_existing_baseline(path, prompt_overwrite):
|
|
|
74
160
|
return None
|
|
75
161
|
|
|
76
162
|
if not sys.stdin.isatty():
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
with open(path, "r") as f:
|
|
80
|
-
return json.load(f)
|
|
81
|
-
except Exception:
|
|
82
|
-
return {}
|
|
163
|
+
msg = "[baseline] existing baseline at %s; non-tty -> refusing overwrite" % path
|
|
164
|
+
raise DuplicateBaselineError(msg)
|
|
83
165
|
|
|
84
166
|
ans = input("[baseline] existing baseline at %s; overwrite? [y/N]: " % path).strip().lower()
|
|
85
167
|
if ans not in ("y", "yes"):
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
with open(path, "r") as f:
|
|
89
|
-
return json.load(f)
|
|
90
|
-
except Exception:
|
|
91
|
-
return {}
|
|
168
|
+
msg = "[baseline] keeping existing baseline; skipped overwrite"
|
|
169
|
+
raise DuplicateBaselineError(msg)
|
|
92
170
|
return None
|
|
93
171
|
|
|
94
172
|
|
|
95
|
-
def _scan_artifacts(cfg):
|
|
173
|
+
def _scan_artifacts(cfg, progress=None):
|
|
96
174
|
"""
|
|
97
175
|
Scan artifact roots/targets similar to sources.
|
|
98
176
|
artifacts.root: base path (optional)
|
|
@@ -113,11 +191,12 @@ def _scan_artifacts(cfg):
|
|
|
113
191
|
else:
|
|
114
192
|
target_path = target_str
|
|
115
193
|
target_path = os.path.abspath(os.path.expanduser(target_path))
|
|
116
|
-
|
|
194
|
+
label = "artifact %s" % target_path
|
|
195
|
+
result[target_path] = _scan(target_path, art_exclude, progress=progress, label=label)
|
|
117
196
|
return result
|
|
118
197
|
|
|
119
198
|
|
|
120
|
-
def create_baseline(cfg, prompt_overwrite=False):
|
|
199
|
+
def create_baseline(cfg, prompt_overwrite=False, progress=None):
|
|
121
200
|
"""
|
|
122
201
|
Collect initial baseline snapshot.
|
|
123
202
|
Scans sources and artifacts (if configured).
|
|
@@ -136,9 +215,12 @@ def create_baseline(cfg, prompt_overwrite=False):
|
|
|
136
215
|
}
|
|
137
216
|
|
|
138
217
|
for root in sources:
|
|
139
|
-
|
|
218
|
+
label = "source %s" % root
|
|
219
|
+
snapshot_data["sources"][root] = _scan(
|
|
220
|
+
root, src_exclude, progress=progress, label=label
|
|
221
|
+
)
|
|
140
222
|
|
|
141
|
-
snapshot_data["artifacts"] = _scan_artifacts(cfg)
|
|
223
|
+
snapshot_data["artifacts"] = _scan_artifacts(cfg, progress=progress)
|
|
142
224
|
|
|
143
225
|
path = os.path.join(STATE_DIR, "baseline.json")
|
|
144
226
|
existing = _maybe_keep_existing_baseline(path, prompt_overwrite)
|
|
@@ -154,7 +236,7 @@ def create_baseline(cfg, prompt_overwrite=False):
|
|
|
154
236
|
return snapshot_data
|
|
155
237
|
|
|
156
238
|
|
|
157
|
-
def create_snapshot(cfg):
|
|
239
|
+
def create_snapshot(cfg, progress=None):
|
|
158
240
|
"""
|
|
159
241
|
Collect a fresh snapshot (for updates).
|
|
160
242
|
"""
|
|
@@ -172,9 +254,12 @@ def create_snapshot(cfg):
|
|
|
172
254
|
}
|
|
173
255
|
|
|
174
256
|
for root in sources:
|
|
175
|
-
|
|
257
|
+
label = "source %s" % root
|
|
258
|
+
snapshot_data["sources"][root] = _scan(
|
|
259
|
+
root, src_exclude, progress=progress, label=label
|
|
260
|
+
)
|
|
176
261
|
|
|
177
|
-
snapshot_data["artifacts"] = _scan_artifacts(cfg)
|
|
262
|
+
snapshot_data["artifacts"] = _scan_artifacts(cfg, progress=progress)
|
|
178
263
|
|
|
179
264
|
path = os.path.join(STATE_DIR, "snapshot.json")
|
|
180
265
|
f = open(path, "w")
|
{pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/SOURCES.txt
RENAMED
|
@@ -23,4 +23,7 @@ pkgmgr_kunrunic.egg-info/entry_points.txt
|
|
|
23
23
|
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
|
-
tests/test_config.py
|
|
26
|
+
tests/test_config.py
|
|
27
|
+
tests/test_progress.py
|
|
28
|
+
tests/test_release.py
|
|
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 == ""
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import sys
|
|
4
|
+
import tempfile
|
|
5
|
+
from importlib import import_module, reload
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
9
|
+
if str(ROOT) not in sys.path:
|
|
10
|
+
sys.path.insert(0, str(ROOT))
|
|
11
|
+
|
|
12
|
+
config = import_module("pkgmgr.config")
|
|
13
|
+
release = import_module("pkgmgr.release")
|
|
14
|
+
snapshot = import_module("pkgmgr.snapshot")
|
|
15
|
+
reload(config)
|
|
16
|
+
reload(release)
|
|
17
|
+
reload(snapshot)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _setup_state_dir(monkeypatch, base_dir):
|
|
21
|
+
state_dir = Path(base_dir) / "state"
|
|
22
|
+
monkeypatch.setattr(config, "DEFAULT_STATE_DIR", str(state_dir))
|
|
23
|
+
monkeypatch.setattr(snapshot, "STATE_DIR", str(state_dir))
|
|
24
|
+
return state_dir
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _write_pkg_yaml(pkg_dir, pkg_id, include_releases):
|
|
28
|
+
config.write_pkg_template(
|
|
29
|
+
os.path.join(pkg_dir, "pkg.yaml"),
|
|
30
|
+
pkg_id=pkg_id,
|
|
31
|
+
pkg_root=pkg_dir,
|
|
32
|
+
include_releases=include_releases,
|
|
33
|
+
git_cfg={"keywords": []},
|
|
34
|
+
collectors_enabled=["checksums"],
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def test_create_pkg_existing_dir_keeps_files_and_writes_pkg_yaml(monkeypatch):
|
|
39
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
40
|
+
base = Path(tmp)
|
|
41
|
+
_setup_state_dir(monkeypatch, base)
|
|
42
|
+
pkg_root = base / "pkgs"
|
|
43
|
+
pkg_id = "20240101"
|
|
44
|
+
pkg_dir = pkg_root / pkg_id
|
|
45
|
+
pkg_dir.mkdir(parents=True)
|
|
46
|
+
keep_file = pkg_dir / "keep.txt"
|
|
47
|
+
keep_file.write_text("keep")
|
|
48
|
+
|
|
49
|
+
cfg = {"pkg_release_root": str(pkg_root)}
|
|
50
|
+
release.create_pkg(cfg, pkg_id)
|
|
51
|
+
|
|
52
|
+
assert keep_file.exists()
|
|
53
|
+
assert keep_file.read_text() == "keep"
|
|
54
|
+
assert (pkg_dir / "pkg.yaml").exists()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_create_pkg_missing_dir_creates_dir_and_pkg_yaml(monkeypatch):
|
|
58
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
59
|
+
base = Path(tmp)
|
|
60
|
+
_setup_state_dir(monkeypatch, base)
|
|
61
|
+
pkg_root = base / "pkgs"
|
|
62
|
+
pkg_id = "20240102"
|
|
63
|
+
pkg_dir = pkg_root / pkg_id
|
|
64
|
+
|
|
65
|
+
cfg = {"pkg_release_root": str(pkg_root)}
|
|
66
|
+
release.create_pkg(cfg, pkg_id)
|
|
67
|
+
|
|
68
|
+
assert pkg_dir.exists()
|
|
69
|
+
assert (pkg_dir / "pkg.yaml").exists()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_update_pkg_first_release_includes_all_files(monkeypatch):
|
|
73
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
74
|
+
base = Path(tmp)
|
|
75
|
+
_setup_state_dir(monkeypatch, base)
|
|
76
|
+
pkg_root = base / "pkgs"
|
|
77
|
+
pkg_id = "20240103"
|
|
78
|
+
pkg_dir = pkg_root / pkg_id
|
|
79
|
+
pkg_dir.mkdir(parents=True)
|
|
80
|
+
|
|
81
|
+
src_dir = pkg_dir / "src"
|
|
82
|
+
src_dir.mkdir()
|
|
83
|
+
(src_dir / "a.txt").write_text("alpha")
|
|
84
|
+
(src_dir / "b.txt").write_text("bravo")
|
|
85
|
+
|
|
86
|
+
_write_pkg_yaml(str(pkg_dir), pkg_id, ["src"])
|
|
87
|
+
cfg = {"pkg_release_root": str(pkg_root)}
|
|
88
|
+
|
|
89
|
+
out_path = release.update_pkg(cfg, pkg_id)
|
|
90
|
+
data = json.loads(Path(out_path).read_text())
|
|
91
|
+
|
|
92
|
+
bundles = data["release"]
|
|
93
|
+
assert len(bundles) == 1
|
|
94
|
+
bundle = bundles[0]
|
|
95
|
+
assert set(bundle["copied"]) == {"a.txt", "b.txt"}
|
|
96
|
+
release_dir = Path(bundle["release_dir"])
|
|
97
|
+
assert (release_dir / "a.txt").exists()
|
|
98
|
+
assert (release_dir / "b.txt").exists()
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def test_update_pkg_skips_release_when_no_changes(monkeypatch):
|
|
102
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
103
|
+
base = Path(tmp)
|
|
104
|
+
_setup_state_dir(monkeypatch, base)
|
|
105
|
+
pkg_root = base / "pkgs"
|
|
106
|
+
pkg_id = "20240104"
|
|
107
|
+
pkg_dir = pkg_root / pkg_id
|
|
108
|
+
pkg_dir.mkdir(parents=True)
|
|
109
|
+
|
|
110
|
+
src_dir = pkg_dir / "src"
|
|
111
|
+
src_dir.mkdir()
|
|
112
|
+
(src_dir / "a.txt").write_text("alpha")
|
|
113
|
+
|
|
114
|
+
_write_pkg_yaml(str(pkg_dir), pkg_id, ["src"])
|
|
115
|
+
cfg = {"pkg_release_root": str(pkg_root)}
|
|
116
|
+
|
|
117
|
+
release.update_pkg(cfg, pkg_id)
|
|
118
|
+
out_path = release.update_pkg(cfg, pkg_id)
|
|
119
|
+
data = json.loads(Path(out_path).read_text())
|
|
120
|
+
|
|
121
|
+
assert data["release"] == []
|
|
122
|
+
release_root = pkg_dir / "release" / "src"
|
|
123
|
+
versions = sorted(p.name for p in release_root.iterdir() if p.is_dir())
|
|
124
|
+
assert versions == ["release.v0.0.1"]
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def test_update_pkg_includes_new_and_modified_files(monkeypatch):
|
|
128
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
129
|
+
base = Path(tmp)
|
|
130
|
+
_setup_state_dir(monkeypatch, base)
|
|
131
|
+
pkg_root = base / "pkgs"
|
|
132
|
+
pkg_id = "20240105"
|
|
133
|
+
pkg_dir = pkg_root / pkg_id
|
|
134
|
+
pkg_dir.mkdir(parents=True)
|
|
135
|
+
|
|
136
|
+
src_dir = pkg_dir / "src"
|
|
137
|
+
src_dir.mkdir()
|
|
138
|
+
(src_dir / "a.txt").write_text("alpha")
|
|
139
|
+
(src_dir / "b.txt").write_text("bravo")
|
|
140
|
+
|
|
141
|
+
_write_pkg_yaml(str(pkg_dir), pkg_id, ["src"])
|
|
142
|
+
cfg = {"pkg_release_root": str(pkg_root)}
|
|
143
|
+
|
|
144
|
+
release.update_pkg(cfg, pkg_id)
|
|
145
|
+
|
|
146
|
+
(src_dir / "a.txt").write_text("alpha2")
|
|
147
|
+
(src_dir / "c.txt").write_text("charlie")
|
|
148
|
+
|
|
149
|
+
out_path = release.update_pkg(cfg, pkg_id)
|
|
150
|
+
data = json.loads(Path(out_path).read_text())
|
|
151
|
+
|
|
152
|
+
bundles = data["release"]
|
|
153
|
+
assert len(bundles) == 1
|
|
154
|
+
bundle = bundles[0]
|
|
155
|
+
assert set(bundle["copied"]) == {"a.txt", "c.txt"}
|
|
156
|
+
assert set(bundle["skipped"]) == {"b.txt"}
|
|
157
|
+
release_dir = Path(bundle["release_dir"])
|
|
158
|
+
assert (release_dir / "a.txt").exists()
|
|
159
|
+
assert (release_dir / "c.txt").exists()
|
|
160
|
+
assert not (release_dir / "b.txt").exists()
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import tempfile
|
|
3
|
+
from importlib import import_module, reload
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
ROOT = Path(__file__).resolve().parents[1]
|
|
7
|
+
if str(ROOT) not in sys.path:
|
|
8
|
+
sys.path.insert(0, str(ROOT))
|
|
9
|
+
|
|
10
|
+
snapshot = import_module("pkgmgr.snapshot")
|
|
11
|
+
reload(snapshot)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def test_create_baseline_raises_on_duplicate_install_non_tty(monkeypatch):
|
|
15
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
16
|
+
state_dir = Path(tmp)
|
|
17
|
+
state_dir.mkdir(parents=True, exist_ok=True)
|
|
18
|
+
(state_dir / "baseline.json").write_text("{}")
|
|
19
|
+
|
|
20
|
+
monkeypatch.setattr(snapshot, "STATE_DIR", str(state_dir))
|
|
21
|
+
monkeypatch.setattr(sys.stdin, "isatty", lambda: False)
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
snapshot.create_baseline({"sources": []}, prompt_overwrite=True)
|
|
25
|
+
except snapshot.DuplicateBaselineError as e:
|
|
26
|
+
assert "existing baseline" in str(e)
|
|
27
|
+
else:
|
|
28
|
+
raise AssertionError("Expected DuplicateBaselineError for duplicate install")
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
from __future__ import print_function
|
|
2
|
-
"""Shell integration helpers: add PATH/alias to common shell rc files.
|
|
3
|
-
|
|
4
|
-
Designed to be conservative and idempotent:
|
|
5
|
-
- Only appends when marker text is absent.
|
|
6
|
-
- Creates rc files if they do not exist.
|
|
7
|
-
- Supports bash/zsh/csh/tcsh/fish.
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
import os
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def ensure_path_and_alias(script_dir, alias_name="pkg", command="pkgmgr"):
|
|
14
|
-
"""
|
|
15
|
-
Append PATH export and alias to the user's shell rc file when possible.
|
|
16
|
-
script_dir: directory where the pkgmgr console script lives (e.g. venv/bin).
|
|
17
|
-
"""
|
|
18
|
-
if not script_dir:
|
|
19
|
-
print("[install] script_dir not provided; skip shell integration")
|
|
20
|
-
return
|
|
21
|
-
shell = os.environ.get("SHELL", "")
|
|
22
|
-
shell_name = os.path.basename(shell) if shell else ""
|
|
23
|
-
|
|
24
|
-
handlers = {
|
|
25
|
-
"bash": _update_bash_zsh,
|
|
26
|
-
"zsh": _update_bash_zsh,
|
|
27
|
-
"csh": _update_csh,
|
|
28
|
-
"tcsh": _update_csh,
|
|
29
|
-
"fish": _update_fish,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
handler = handlers.get(shell_name)
|
|
33
|
-
if not handler:
|
|
34
|
-
print("[install] unknown shell '%s'; skipping rc update" % (shell_name or ""))
|
|
35
|
-
return
|
|
36
|
-
|
|
37
|
-
try:
|
|
38
|
-
handler(script_dir, alias_name, command)
|
|
39
|
-
except Exception as e:
|
|
40
|
-
print("[install] shell integration failed for %s: %s" % (shell_name, str(e)))
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
# -------- rc updaters --------
|
|
44
|
-
|
|
45
|
-
def _ensure_lines(path, marker, lines):
|
|
46
|
-
"""
|
|
47
|
-
Append lines to file if marker not present.
|
|
48
|
-
"""
|
|
49
|
-
exists = os.path.exists(path)
|
|
50
|
-
content = ""
|
|
51
|
-
if exists:
|
|
52
|
-
try:
|
|
53
|
-
f = open(path, "r")
|
|
54
|
-
try:
|
|
55
|
-
content = f.read()
|
|
56
|
-
finally:
|
|
57
|
-
f.close()
|
|
58
|
-
except Exception:
|
|
59
|
-
content = ""
|
|
60
|
-
|
|
61
|
-
if marker in content:
|
|
62
|
-
return False
|
|
63
|
-
|
|
64
|
-
parent = os.path.dirname(path)
|
|
65
|
-
if parent and not os.path.exists(parent):
|
|
66
|
-
os.makedirs(parent)
|
|
67
|
-
|
|
68
|
-
f = open(path, "a")
|
|
69
|
-
try:
|
|
70
|
-
if content and not content.endswith("\n"):
|
|
71
|
-
f.write("\n")
|
|
72
|
-
f.write("# %s\n" % marker)
|
|
73
|
-
for line in lines:
|
|
74
|
-
f.write(line + "\n")
|
|
75
|
-
finally:
|
|
76
|
-
f.close()
|
|
77
|
-
return True
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
def _update_bash_zsh(script_dir, alias_name, command):
|
|
81
|
-
rc_path = os.path.expanduser("~/.bashrc")
|
|
82
|
-
shell = os.path.basename(os.environ.get("SHELL", ""))
|
|
83
|
-
if shell == "zsh":
|
|
84
|
-
rc_path = os.path.expanduser("~/.zshrc")
|
|
85
|
-
marker = "added by pkgmgr (sh)"
|
|
86
|
-
lines = [
|
|
87
|
-
'export PATH="%s:$PATH"' % script_dir,
|
|
88
|
-
'alias %s="%s"' % (alias_name, command),
|
|
89
|
-
]
|
|
90
|
-
changed = _ensure_lines(rc_path, marker, lines)
|
|
91
|
-
if changed:
|
|
92
|
-
print("[install] updated %s with PATH/alias" % rc_path)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
def _update_csh(script_dir, alias_name, command):
|
|
96
|
-
rc_path = os.path.expanduser("~/.cshrc")
|
|
97
|
-
shell = os.path.basename(os.environ.get("SHELL", ""))
|
|
98
|
-
if shell == "tcsh":
|
|
99
|
-
rc_path = os.path.expanduser("~/.tcshrc")
|
|
100
|
-
marker = "added by pkgmgr (csh)"
|
|
101
|
-
lines = [
|
|
102
|
-
"set path = (%s $path)" % script_dir,
|
|
103
|
-
"alias %s %s" % (alias_name, command),
|
|
104
|
-
]
|
|
105
|
-
changed = _ensure_lines(rc_path, marker, lines)
|
|
106
|
-
if changed:
|
|
107
|
-
print("[install] updated %s with PATH/alias" % rc_path)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
def _update_fish(script_dir, alias_name, command):
|
|
111
|
-
rc_path = os.path.expanduser("~/.config/fish/config.fish")
|
|
112
|
-
marker = "added by pkgmgr (fish)"
|
|
113
|
-
lines = [
|
|
114
|
-
"set -U fish_user_paths %s $fish_user_paths" % script_dir,
|
|
115
|
-
"alias %s %s" % (alias_name, command),
|
|
116
|
-
]
|
|
117
|
-
changed = _ensure_lines(rc_path, marker, lines)
|
|
118
|
-
if changed:
|
|
119
|
-
print("[install] updated %s with PATH/alias" % rc_path)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr/templates/pkgmgr.yaml.sample
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/requires.txt
RENAMED
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev8 → pkgmgr_kunrunic-0.1.1.dev0}/pkgmgr_kunrunic.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|