pkgmgr-kunrunic 0.1.2.dev4__tar.gz → 0.1.2.dev7__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 (44) hide show
  1. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/PKG-INFO +1 -1
  2. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/__init__.py +1 -1
  3. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/config.py +53 -5
  4. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/release.py +37 -16
  5. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/templates/pkgmgr.yaml.sample +1 -0
  6. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/PKG-INFO +1 -1
  7. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/SOURCES.txt +2 -0
  8. pkgmgr_kunrunic-0.1.2.dev7/tests/test_encoding.py +72 -0
  9. pkgmgr_kunrunic-0.1.2.dev7/tests/test_release_symlink.py +78 -0
  10. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/LICENSE +0 -0
  11. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/README.md +0 -0
  12. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/__main__.py +0 -0
  13. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/cli.py +0 -0
  14. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/collectors/__init__.py +0 -0
  15. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/collectors/base.py +0 -0
  16. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/collectors/checksums.py +0 -0
  17. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/detection.py +0 -0
  18. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/points.py +0 -0
  19. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/shell_integration.py +0 -0
  20. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/snapshot.py +0 -0
  21. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/templates/pkg.yaml.sample +0 -0
  22. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/watch.py +0 -0
  23. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/dependency_links.txt +0 -0
  24. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/entry_points.txt +0 -0
  25. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/not-zip-safe +0 -0
  26. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/requires.txt +0 -0
  27. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/top_level.txt +0 -0
  28. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/plugin/export_cksum.py +0 -0
  29. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/plugin/export_pkgstore.py +0 -0
  30. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/plugin/export_source_review.py +0 -0
  31. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/plugin/export_trivy_sbom.py +0 -0
  32. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/pyproject.toml +0 -0
  33. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/setup.cfg +0 -0
  34. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_cli_detect.py +0 -0
  35. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_cli_install.py +0 -0
  36. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_cli_telegram.py +0 -0
  37. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_config.py +0 -0
  38. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_detection.py +0 -0
  39. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_export_trivy_sbom.py +0 -0
  40. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_progress.py +0 -0
  41. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_release.py +0 -0
  42. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_snapshot.py +0 -0
  43. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_watch_notify.py +0 -0
  44. {pkgmgr_kunrunic-0.1.2.dev4 → pkgmgr_kunrunic-0.1.2.dev7}/tools/echo_args.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pkgmgr-kunrunic
3
- Version: 0.1.2.dev4
3
+ Version: 0.1.2.dev7
4
4
  Summary: Package management workflow scaffold.
5
5
  Author: pkgmgr maintainers
6
6
  License: MIT License
@@ -14,4 +14,4 @@ __all__ = [
14
14
  "detection",
15
15
  ]
16
16
 
17
- __version__ = "0.1.2.dev4"
17
+ __version__ = "0.1.2.dev7"
@@ -1,7 +1,9 @@
1
1
  from __future__ import print_function
2
2
  """Configuration helpers for the pkg manager scaffold."""
3
3
 
4
+ import codecs
4
5
  import glob
6
+ import locale
5
7
  import os
6
8
  import re
7
9
  import sys
@@ -27,6 +29,7 @@ except Exception:
27
29
 
28
30
  MAIN_TEMPLATE = """\
29
31
  pkg_release_root: ~/PKG/RELEASE
32
+ encoding: null # 새로 만드는 pkg.yaml 인코딩 (예: utf-8, euc-kr). null 이면 locale. 기존 파일은 그 인코딩 유지
30
33
  git:
31
34
  repo_root: null # optional override; default is git rev-parse from cwd
32
35
  repo_url: "https://github.com/org/repo"
@@ -159,6 +162,7 @@ collectors:
159
162
 
160
163
  MAIN_DEFAULTS = {
161
164
  "pkg_release_root": None,
165
+ "encoding": None,
162
166
  "git": {"repo_root": None, "repo_url": None, "keyword_prefix": None},
163
167
  "sources": [],
164
168
  "source": {"exclude": []},
@@ -463,6 +467,8 @@ def _validate_main_config(data):
463
467
  if not pkg_root or not isinstance(pkg_root, (str, bytes)):
464
468
  raise RuntimeError("pkg_release_root is required (path string)")
465
469
  cfg["pkg_release_root"] = str(pkg_root)
470
+ enc = cfg.get("encoding")
471
+ cfg["encoding"] = str(enc) if enc else None
466
472
 
467
473
  git_cfg = cfg.get("git") if isinstance(cfg.get("git"), dict) else {}
468
474
  repo_root = git_cfg.get("repo_root")
@@ -542,7 +548,51 @@ def write_template(path=None):
542
548
  return True
543
549
 
544
550
 
545
- def write_pkg_template(path, pkg_id=None, pkg_root=None, include_releases=None, git_cfg=None, collectors_enabled=None):
551
+ _DETECT_ENCODINGS = ("utf-8", "euc-kr", "cp949")
552
+
553
+
554
+ def detect_file_encoding(path):
555
+ try:
556
+ with open(path, "rb") as f:
557
+ raw = f.read()
558
+ except (IOError, OSError):
559
+ return None
560
+ for enc in _DETECT_ENCODINGS:
561
+ try:
562
+ raw.decode(enc)
563
+ return enc
564
+ except UnicodeDecodeError:
565
+ continue
566
+ return None
567
+
568
+
569
+ def default_write_encoding(cfg=None):
570
+ enc = (cfg or {}).get("encoding") or locale.getpreferredencoding(False) or "utf-8"
571
+ try:
572
+ name = codecs.lookup(enc).name
573
+ except LookupError:
574
+ return "utf-8"
575
+ # LANG=C 장비는 ascii 로 잡혀 한글 주석을 쓸 수 없다.
576
+ return "utf-8" if name == "ascii" else name
577
+
578
+
579
+ def write_text_keep_encoding(path, text, default_encoding=None):
580
+ """기존 파일은 그 인코딩을 유지한다. 한 파일에 인코딩이 섞이면 편집기 저장 시 한쪽이 깨진다."""
581
+ enc = detect_file_encoding(path) if os.path.exists(path) else None
582
+ enc = enc or default_encoding or default_write_encoding()
583
+ try:
584
+ data = text.encode(enc)
585
+ except (UnicodeEncodeError, LookupError):
586
+ print("[pkgmgr] %s: %s 로 표현할 수 없는 문자가 있어 utf-8 로 씁니다" % (path, enc))
587
+ enc = "utf-8"
588
+ data = text.encode(enc)
589
+ with open(path, "wb") as f:
590
+ f.write(data)
591
+ return enc
592
+
593
+
594
+ def write_pkg_template(path, pkg_id=None, pkg_root=None, include_releases=None, git_cfg=None, collectors_enabled=None,
595
+ encoding=None):
546
596
  """
547
597
  Write a pkg.yaml file. When pkg_id/pkg_root provided, render with those values;
548
598
  otherwise fall back to the static template.
@@ -554,8 +604,7 @@ def write_pkg_template(path, pkg_id=None, pkg_root=None, include_releases=None,
554
604
 
555
605
  if pkg_id is None or pkg_root is None or yaml is None:
556
606
  content = _load_template_file("pkg.yaml.sample", PKG_TEMPLATE)
557
- with open(target, "w", encoding="euc-kr") as f:
558
- f.write(content)
607
+ write_text_keep_encoding(target, content, encoding)
559
608
  else:
560
609
  data = {
561
610
  "pkg": {"id": str(pkg_id), "root": os.path.abspath(os.path.expanduser(pkg_root)), "status": "open"},
@@ -577,8 +626,7 @@ def write_pkg_template(path, pkg_id=None, pkg_root=None, include_releases=None,
577
626
  out_lines.append(" # pkgmgr.yaml 의 repo_root 값으로 자동 생성됩니다.")
578
627
  if line.strip().startswith("releases:"):
579
628
  out_lines.append(" # update-pkg 실행 시 추가 항목은 수동으로 include.releases에 입력 필요")
580
- with open(target, "w", encoding="euc-kr") as f:
581
- f.write("\n".join(out_lines) + "\n")
629
+ write_text_keep_encoding(target, "\n".join(out_lines) + "\n", encoding)
582
630
  print("[create-pkg] wrote pkg config to %s" % target)
583
631
 
584
632
 
@@ -340,6 +340,7 @@ def create_pkg(cfg, pkg_id):
340
340
  include_releases=include_releases,
341
341
  git_cfg=git_cfg,
342
342
  collectors_enabled=collectors_enabled,
343
+ encoding=config.default_write_encoding(cfg),
343
344
  )
344
345
  # initial snapshot placeholder (only if no baseline exists yet)
345
346
  baseline_path = os.path.join(config.DEFAULT_STATE_DIR, "baseline.json")
@@ -756,8 +757,7 @@ def _write_yaml_path(path, data):
756
757
  return False
757
758
  try:
758
759
  dumped = config.yaml.safe_dump(data, allow_unicode=True, sort_keys=True)
759
- with open(path, "w", encoding="euc-kr") as f:
760
- f.write(dumped)
760
+ config.write_text_keep_encoding(path, dumped)
761
761
  return True
762
762
  except Exception:
763
763
  return False
@@ -878,16 +878,37 @@ def _collect_release_sources(pkg_dir, pkg_cfg):
878
878
  return files
879
879
 
880
880
 
881
+ def _is_entry(path):
882
+ return os.path.islink(path) or os.path.isfile(path)
883
+
884
+
885
+ def _entry_hash(path):
886
+ # 링크는 대상 경로 문자열로 비교해야 lib 버전 체인이 대상 파일 변경에 끌려가지 않는다.
887
+ if os.path.islink(path):
888
+ return "symlink:" + os.readlink(path)
889
+ return checksums_module.sha256_of_file(path)
890
+
891
+
892
+ def _copy_entry(src, dest):
893
+ # 링크를 따라가 복사하면 release·tar·장비에서 링크가 실제 파일 사본으로 바뀐다.
894
+ if os.path.islink(dest) or os.path.exists(dest):
895
+ os.remove(dest)
896
+ if os.path.islink(src):
897
+ os.symlink(os.readlink(src), dest)
898
+ else:
899
+ shutil.copy2(src, dest)
900
+
901
+
881
902
  def _load_prev_hashes(prev_release_dir):
882
903
  hashes = {}
883
904
  for base, _, names in os.walk(prev_release_dir):
884
905
  for name in names:
885
906
  abspath = os.path.join(base, name)
886
- if not os.path.isfile(abspath):
907
+ if not _is_entry(abspath):
887
908
  continue
888
909
  rel = os.path.relpath(abspath, prev_release_dir)
889
910
  try:
890
- hashes[rel] = checksums_module.sha256_of_file(abspath)
911
+ hashes[rel] = _entry_hash(abspath)
891
912
  except Exception:
892
913
  continue
893
914
  return hashes
@@ -950,7 +971,7 @@ def _prepare_release(pkg_dir, pkg_cfg):
950
971
  if name in (_PKG_NOTE_NAME, _PKG_LIST_NAME):
951
972
  continue
952
973
  abspath = os.path.join(base, name)
953
- if not os.path.isfile(abspath):
974
+ if not _is_entry(abspath):
954
975
  continue
955
976
  rel = os.path.relpath(abspath, release_dir)
956
977
  existing.add(rel)
@@ -963,7 +984,7 @@ def _prepare_release(pkg_dir, pkg_cfg):
963
984
  if name in (_PKG_NOTE_NAME, _PKG_LIST_NAME):
964
985
  continue
965
986
  abspath = os.path.join(base, name)
966
- if not os.path.isfile(abspath):
987
+ if not _is_entry(abspath):
967
988
  continue
968
989
  rel = os.path.relpath(abspath, prev_dir)
969
990
  prev_existing.add(rel)
@@ -971,7 +992,7 @@ def _prepare_release(pkg_dir, pkg_cfg):
971
992
  for src, rel in entries:
972
993
  baseline_hash = baseline_hashes.get(rel)
973
994
  try:
974
- curr_hash = checksums_module.sha256_of_file(src)
995
+ curr_hash = _entry_hash(src)
975
996
  curr_hashes[rel] = curr_hash
976
997
  except Exception as e:
977
998
  print("[update-pkg] failed to hash %s: %s" % (src, str(e)))
@@ -1025,10 +1046,10 @@ def _prepare_release(pkg_dir, pkg_cfg):
1025
1046
  dest_parent = os.path.dirname(dest)
1026
1047
  if dest_parent and not os.path.exists(dest_parent):
1027
1048
  os.makedirs(dest_parent)
1028
- shutil.copy2(src, dest)
1049
+ _copy_entry(src, dest)
1029
1050
  for rel in sorted(removed):
1030
1051
  abspath = os.path.join(release_dir, rel)
1031
- if os.path.isfile(abspath):
1052
+ if _is_entry(abspath):
1032
1053
  os.remove(abspath)
1033
1054
  for base, dirs, files in os.walk(release_dir, topdown=False):
1034
1055
  if files:
@@ -1066,7 +1087,7 @@ def _prepare_release(pkg_dir, pkg_cfg):
1066
1087
  if name in (_PKG_NOTE_NAME, _PKG_LIST_NAME):
1067
1088
  continue
1068
1089
  abspath = os.path.join(base, name)
1069
- if not os.path.isfile(abspath):
1090
+ if not _is_entry(abspath):
1070
1091
  continue
1071
1092
  rel = os.path.relpath(abspath, release_dir)
1072
1093
  all_files.append(rel)
@@ -1133,12 +1154,12 @@ def _sync_baseline_root(root_dir, entries):
1133
1154
  dest_parent = os.path.dirname(dest)
1134
1155
  if dest_parent and not os.path.exists(dest_parent):
1135
1156
  os.makedirs(dest_parent)
1136
- shutil.copy2(src, dest)
1157
+ _copy_entry(src, dest)
1137
1158
 
1138
1159
  for base, _, names in os.walk(baseline_dir):
1139
1160
  for name in names:
1140
1161
  abspath = os.path.join(base, name)
1141
- if not os.path.isfile(abspath):
1162
+ if not _is_entry(abspath):
1142
1163
  continue
1143
1164
  rel = os.path.relpath(abspath, baseline_dir)
1144
1165
  if rel not in expected:
@@ -1379,7 +1400,7 @@ def _reset_baseline_from_active(root_dir, release_name):
1379
1400
  continue
1380
1401
  src = os.path.join(base, name)
1381
1402
  dest = os.path.join(dest_base, name)
1382
- shutil.copy2(src, dest)
1403
+ _copy_entry(src, dest)
1383
1404
  print("[cancel] baseline reset from active for %s" % root_dir)
1384
1405
 
1385
1406
 
@@ -1406,18 +1427,18 @@ def _revert_baseline_for_bundles(release_root, bundles):
1406
1427
  continue
1407
1428
  for rel in added:
1408
1429
  target = os.path.join(baseline_dir, rel)
1409
- if os.path.isfile(target):
1430
+ if _is_entry(target):
1410
1431
  os.remove(target)
1411
1432
  if prev_release:
1412
1433
  for rel in list(set(updated + removed)):
1413
1434
  src = os.path.join(prev_release, rel)
1414
- if not os.path.isfile(src):
1435
+ if not _is_entry(src):
1415
1436
  continue
1416
1437
  dest = os.path.join(baseline_dir, rel)
1417
1438
  dest_parent = os.path.dirname(dest)
1418
1439
  if dest_parent and not os.path.exists(dest_parent):
1419
1440
  os.makedirs(dest_parent)
1420
- shutil.copy2(src, dest)
1441
+ _copy_entry(src, dest)
1421
1442
  _prune_empty_dirs(baseline_dir)
1422
1443
  print("[cancel] baseline reverted for %s" % root)
1423
1444
 
@@ -1,4 +1,5 @@
1
1
  pkg_release_root: ~/PKG/RELEASE
2
+ encoding: null # 새로 만드는 pkg.yaml 인코딩 (예: utf-8, euc-kr). null 이면 locale. 기존 파일은 그 인코딩 유지
2
3
  git:
3
4
  repo_root: null # 입력하는 경우 create-pkg 시 해당 정보로 자동 설정됩니다.
4
5
  repo_url: "https://github.com/org/repo"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pkgmgr-kunrunic
3
- Version: 0.1.2.dev4
3
+ Version: 0.1.2.dev7
4
4
  Summary: Package management workflow scaffold.
5
5
  Author: pkgmgr maintainers
6
6
  License: MIT License
@@ -32,9 +32,11 @@ tests/test_cli_install.py
32
32
  tests/test_cli_telegram.py
33
33
  tests/test_config.py
34
34
  tests/test_detection.py
35
+ tests/test_encoding.py
35
36
  tests/test_export_trivy_sbom.py
36
37
  tests/test_progress.py
37
38
  tests/test_release.py
39
+ tests/test_release_symlink.py
38
40
  tests/test_snapshot.py
39
41
  tests/test_watch_notify.py
40
42
  tools/echo_args.py
@@ -0,0 +1,72 @@
1
+ import os
2
+ import sys
3
+ import tempfile
4
+ from importlib import import_module, reload
5
+ from pathlib import Path
6
+
7
+ ROOT = Path(__file__).resolve().parents[1]
8
+ if str(ROOT) not in sys.path:
9
+ sys.path.insert(0, str(ROOT))
10
+
11
+ config = import_module("pkgmgr.config")
12
+ release = import_module("pkgmgr.release")
13
+ reload(config)
14
+ reload(release)
15
+
16
+ KO = u"# 한글 주석\n"
17
+
18
+
19
+ def test_existing_euckr_file_keeps_euckr():
20
+ with tempfile.TemporaryDirectory() as tmp:
21
+ p = os.path.join(tmp, "pkg.yaml")
22
+ Path(p).write_bytes(KO.encode("euc-kr"))
23
+ enc = config.write_text_keep_encoding(p, KO + u"# 추가\n", "utf-8")
24
+ assert enc == "euc-kr"
25
+ assert Path(p).read_bytes().decode("euc-kr") == KO + u"# 추가\n"
26
+
27
+
28
+ def test_existing_utf8_file_keeps_utf8():
29
+ with tempfile.TemporaryDirectory() as tmp:
30
+ p = os.path.join(tmp, "pkg.yaml")
31
+ Path(p).write_bytes(KO.encode("utf-8"))
32
+ assert config.write_text_keep_encoding(p, KO, "euc-kr") == "utf-8"
33
+ assert Path(p).read_bytes().decode("utf-8") == KO
34
+
35
+
36
+ def test_new_file_uses_config_then_locale(monkeypatch):
37
+ assert config.default_write_encoding({"encoding": "EUC-KR"}) == "euc_kr"
38
+ monkeypatch.setattr(config.locale, "getpreferredencoding", lambda do_setlocale=True: "UTF-8")
39
+ assert config.default_write_encoding({}) == "utf-8"
40
+ monkeypatch.setattr(config.locale, "getpreferredencoding", lambda do_setlocale=True: "ANSI_X3.4-1968")
41
+ assert config.default_write_encoding({}) == "utf-8"
42
+ assert config.default_write_encoding({"encoding": "no-such-enc"}) == "utf-8"
43
+ with tempfile.TemporaryDirectory() as tmp:
44
+ p = os.path.join(tmp, "new.yaml")
45
+ assert config.write_text_keep_encoding(p, KO, "euc_kr") == "euc_kr"
46
+ assert Path(p).read_bytes() == KO.encode("euc-kr")
47
+
48
+
49
+ def test_unencodable_text_falls_back_to_utf8():
50
+ with tempfile.TemporaryDirectory() as tmp:
51
+ p = os.path.join(tmp, "pkg.yaml")
52
+ Path(p).write_bytes(KO.encode("euc-kr"))
53
+ text = KO + u"# �\n"
54
+ assert config.write_text_keep_encoding(p, text) == "utf-8"
55
+ assert Path(p).read_bytes().decode("utf-8") == text
56
+
57
+
58
+ def test_update_pkg_yaml_status_keeps_encoding():
59
+ with tempfile.TemporaryDirectory() as tmp:
60
+ p = os.path.join(tmp, "pkg.yaml")
61
+ Path(p).write_bytes(u"pkg:\n id: X\n status: open\n note: 한글\n".encode("euc-kr"))
62
+ assert release._update_pkg_yaml_status(tmp, "closed")
63
+ text = Path(p).read_bytes().decode("euc-kr")
64
+ assert "status: closed" in text and u"한글" in text
65
+
66
+
67
+ def test_write_pkg_template_uses_given_encoding():
68
+ with tempfile.TemporaryDirectory() as tmp:
69
+ p = os.path.join(tmp, "pkg.yaml")
70
+ config.write_pkg_template(p, pkg_id="X", pkg_root=tmp, include_releases=["a/lib"],
71
+ git_cfg={"keywords": []}, encoding="utf-8")
72
+ assert u"자동 생성됩니다" in Path(p).read_bytes().decode("utf-8")
@@ -0,0 +1,78 @@
1
+ import json
2
+ import tarfile
3
+ import os
4
+ import sys
5
+ import tempfile
6
+ import shlex
7
+ from importlib import import_module, reload
8
+ from pathlib import Path
9
+
10
+ ROOT = Path(__file__).resolve().parents[1]
11
+ if str(ROOT) not in sys.path:
12
+ sys.path.insert(0, str(ROOT))
13
+
14
+ config = import_module("pkgmgr.config")
15
+ release = import_module("pkgmgr.release")
16
+ snapshot = import_module("pkgmgr.snapshot")
17
+ reload(config)
18
+ reload(release)
19
+ reload(snapshot)
20
+
21
+
22
+ def _setup_state_dir(monkeypatch, base_dir):
23
+ state_dir = Path(base_dir) / "state"
24
+ monkeypatch.setattr(config, "DEFAULT_STATE_DIR", str(state_dir))
25
+ monkeypatch.setattr(snapshot, "STATE_DIR", str(state_dir))
26
+ return state_dir
27
+
28
+
29
+ def _write_pkg_yaml(pkg_dir, pkg_id, include_releases):
30
+ config.write_pkg_template(
31
+ os.path.join(pkg_dir, "pkg.yaml"),
32
+ pkg_id=pkg_id,
33
+ pkg_root=pkg_dir,
34
+ include_releases=include_releases,
35
+ git_cfg={"keywords": []},
36
+ collectors_enabled=["checksums"],
37
+ )
38
+
39
+ def test_update_pkg_keeps_symlinks_in_release_tar_and_baseline(monkeypatch):
40
+ with tempfile.TemporaryDirectory() as tmp:
41
+ base = Path(tmp)
42
+ _setup_state_dir(monkeypatch, base)
43
+ pkg_root = base / "pkgs"
44
+ pkg_id = "20240120"
45
+ pkg_dir = pkg_root / pkg_id
46
+ lib_dir = pkg_dir / "sys" / "lib"
47
+ lib_dir.mkdir(parents=True)
48
+ (lib_dir / "libx-1.0.0.so").write_text("v1")
49
+ os.symlink("libx-1.0.0.so", str(lib_dir / "libx-1.0.so"))
50
+ os.symlink("libx-1.0.so", str(lib_dir / "libx.so"))
51
+
52
+ _write_pkg_yaml(str(pkg_dir), pkg_id, ["sys/lib"])
53
+ cfg = {"pkg_release_root": str(pkg_root)}
54
+ release.update_pkg(cfg, pkg_id)
55
+
56
+ rel_lib = pkg_dir / "release" / "sys" / "release.v0.0.1" / "lib"
57
+ assert os.path.islink(str(rel_lib / "libx-1.0.so"))
58
+ assert os.readlink(str(rel_lib / "libx.so")) == "libx-1.0.so"
59
+ assert not os.path.islink(str(rel_lib / "libx-1.0.0.so"))
60
+
61
+ release.finalize_pkg_release(cfg, pkg_id)
62
+ root = pkg_dir / "release" / "sys"
63
+ with tarfile.open(str(root / "release.v0.0.1.tar"), "r") as tar:
64
+ member = tar.getmember("release.v0.0.1/lib/libx.so")
65
+ assert member.issym() and member.linkname == "libx-1.0.so"
66
+ assert os.path.islink(str(root / "HISTORY" / "BASELINE" / "lib" / "libx.so"))
67
+
68
+ # 대상 파일만 바뀌면 링크는 v0.0.2 에 들어가지 않는다
69
+ (lib_dir / "libx-1.0.0.so").write_text("v2")
70
+ release.update_pkg(cfg, pkg_id)
71
+ v002 = root / "release.v0.0.2" / "lib"
72
+ assert sorted(os.listdir(str(v002))) == ["libx-1.0.0.so"]
73
+
74
+ # 링크 대상이 바뀌면 링크만 변경으로 잡힌다
75
+ os.remove(str(lib_dir / "libx.so"))
76
+ os.symlink("libx-1.0.0.so", str(lib_dir / "libx.so"))
77
+ release.update_pkg(cfg, pkg_id)
78
+ assert os.readlink(str(v002 / "libx.so")) == "libx-1.0.0.so"