pkgmgr-kunrunic 0.1.2.dev5__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.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/PKG-INFO +1 -1
  2. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/__init__.py +1 -1
  3. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/config.py +53 -5
  4. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/release.py +2 -2
  5. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/templates/pkgmgr.yaml.sample +1 -0
  6. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/PKG-INFO +1 -1
  7. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/SOURCES.txt +1 -0
  8. pkgmgr_kunrunic-0.1.2.dev7/tests/test_encoding.py +72 -0
  9. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/LICENSE +0 -0
  10. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/README.md +0 -0
  11. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/__main__.py +0 -0
  12. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/cli.py +0 -0
  13. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/collectors/__init__.py +0 -0
  14. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/collectors/base.py +0 -0
  15. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/collectors/checksums.py +0 -0
  16. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/detection.py +0 -0
  17. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/points.py +0 -0
  18. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/shell_integration.py +0 -0
  19. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/snapshot.py +0 -0
  20. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/templates/pkg.yaml.sample +0 -0
  21. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr/watch.py +0 -0
  22. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/dependency_links.txt +0 -0
  23. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/entry_points.txt +0 -0
  24. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/not-zip-safe +0 -0
  25. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/requires.txt +0 -0
  26. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pkgmgr_kunrunic.egg-info/top_level.txt +0 -0
  27. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/plugin/export_cksum.py +0 -0
  28. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/plugin/export_pkgstore.py +0 -0
  29. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/plugin/export_source_review.py +0 -0
  30. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/plugin/export_trivy_sbom.py +0 -0
  31. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/pyproject.toml +0 -0
  32. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/setup.cfg +0 -0
  33. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_cli_detect.py +0 -0
  34. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_cli_install.py +0 -0
  35. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_cli_telegram.py +0 -0
  36. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_config.py +0 -0
  37. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_detection.py +0 -0
  38. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_export_trivy_sbom.py +0 -0
  39. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_progress.py +0 -0
  40. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_release.py +0 -0
  41. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_release_symlink.py +0 -0
  42. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_snapshot.py +0 -0
  43. {pkgmgr_kunrunic-0.1.2.dev5 → pkgmgr_kunrunic-0.1.2.dev7}/tests/test_watch_notify.py +0 -0
  44. {pkgmgr_kunrunic-0.1.2.dev5 → 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.dev5
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.dev5"
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
@@ -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.dev5
3
+ Version: 0.1.2.dev7
4
4
  Summary: Package management workflow scaffold.
5
5
  Author: pkgmgr maintainers
6
6
  License: MIT License
@@ -32,6 +32,7 @@ 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
@@ -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")