pkgmgr-kunrunic 0.1.0.dev7__tar.gz → 0.1.0.dev9__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.dev7/pkgmgr_kunrunic.egg-info → pkgmgr_kunrunic-0.1.0.dev9}/PKG-INFO +1 -1
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/__init__.py +1 -1
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/release.py +20 -13
- pkgmgr_kunrunic-0.1.0.dev9/pkgmgr/shell_integration.py +83 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/snapshot.py +9 -13
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9/pkgmgr_kunrunic.egg-info}/PKG-INFO +1 -1
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/SOURCES.txt +3 -1
- pkgmgr_kunrunic-0.1.0.dev9/tests/test_release.py +160 -0
- pkgmgr_kunrunic-0.1.0.dev9/tests/test_snapshot.py +28 -0
- pkgmgr_kunrunic-0.1.0.dev7/pkgmgr/shell_integration.py +0 -119
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/LICENSE +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/README.md +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/__main__.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/cli.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/collectors/__init__.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/collectors/base.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/collectors/checksums.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/config.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/gitcollect.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/points.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/templates/pkg.yaml.sample +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/templates/pkgmgr.yaml.sample +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/watch.py +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/dependency_links.txt +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/entry_points.txt +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/not-zip-safe +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/requires.txt +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/top_level.txt +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pyproject.toml +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/setup.cfg +0 -0
- {pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/tests/test_config.py +0 -0
|
@@ -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):
|
|
@@ -319,7 +318,7 @@ def _collect_git_hits(pkg_cfg, pkg_root):
|
|
|
319
318
|
# fetch author and full commit message body for richer context
|
|
320
319
|
try:
|
|
321
320
|
info = subprocess.check_output(
|
|
322
|
-
["git", "show", "-s", "--format=%an\t%ae\t%ad%n%
|
|
321
|
+
["git", "show", "-s", "--format=%an\t%ae\t%ad%n%s%n%b", c["hash"]],
|
|
323
322
|
cwd=repo_root,
|
|
324
323
|
stderr=subprocess.STDOUT,
|
|
325
324
|
universal_newlines=True,
|
|
@@ -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,10 @@ 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
|
+
|
|
16
20
|
def _ensure_state_dir():
|
|
17
21
|
if not os.path.exists(STATE_DIR):
|
|
18
22
|
os.makedirs(STATE_DIR)
|
|
@@ -66,7 +70,7 @@ def _scan(root, exclude):
|
|
|
66
70
|
def _maybe_keep_existing_baseline(path, prompt_overwrite):
|
|
67
71
|
"""
|
|
68
72
|
When prompt_overwrite=True and baseline exists, ask user (if tty) whether to overwrite.
|
|
69
|
-
|
|
73
|
+
Raises DuplicateBaselineError when overwrite is declined or non-interactive.
|
|
70
74
|
"""
|
|
71
75
|
if not prompt_overwrite:
|
|
72
76
|
return None
|
|
@@ -74,21 +78,13 @@ def _maybe_keep_existing_baseline(path, prompt_overwrite):
|
|
|
74
78
|
return None
|
|
75
79
|
|
|
76
80
|
if not sys.stdin.isatty():
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
with open(path, "r") as f:
|
|
80
|
-
return json.load(f)
|
|
81
|
-
except Exception:
|
|
82
|
-
return {}
|
|
81
|
+
msg = "[baseline] existing baseline at %s; non-tty -> refusing overwrite" % path
|
|
82
|
+
raise DuplicateBaselineError(msg)
|
|
83
83
|
|
|
84
84
|
ans = input("[baseline] existing baseline at %s; overwrite? [y/N]: " % path).strip().lower()
|
|
85
85
|
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 {}
|
|
86
|
+
msg = "[baseline] keeping existing baseline; skipped overwrite"
|
|
87
|
+
raise DuplicateBaselineError(msg)
|
|
92
88
|
return None
|
|
93
89
|
|
|
94
90
|
|
|
@@ -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
|
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr/templates/pkgmgr.yaml.sample
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/not-zip-safe
RENAMED
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/requires.txt
RENAMED
|
File without changes
|
{pkgmgr_kunrunic-0.1.0.dev7 → pkgmgr_kunrunic-0.1.0.dev9}/pkgmgr_kunrunic.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|