minimindslab-env-file-diff 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,10 @@
1
+ """MiniMindsLab Env File Diff."""
2
+
3
+ from .core import compare_env_files, compare_env_mappings, parse_env_file, render_report
4
+
5
+ __all__ = [
6
+ "parse_env_file",
7
+ "compare_env_mappings",
8
+ "compare_env_files",
9
+ "render_report",
10
+ ]
@@ -0,0 +1,33 @@
1
+ from __future__ import annotations
2
+
3
+ import argparse
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ from .core import compare_env_files, render_report
8
+
9
+
10
+ def main(argv: list[str] | None = None) -> int:
11
+ parser = argparse.ArgumentParser(
12
+ prog="miniminds-env-diff",
13
+ description="Deterministically compare two .env-style files.",
14
+ )
15
+ parser.add_argument("old_file")
16
+ parser.add_argument("new_file")
17
+ args = parser.parse_args(argv)
18
+
19
+ old_label = Path(args.old_file).name
20
+ new_label = Path(args.new_file).name
21
+
22
+ try:
23
+ diff = compare_env_files(args.old_file, args.new_file)
24
+ except FileNotFoundError as exc:
25
+ print(str(exc), file=sys.stderr)
26
+ return 2
27
+
28
+ print(render_report(diff, old_label, new_label))
29
+ return 0
30
+
31
+
32
+ if __name__ == "__main__":
33
+ raise SystemExit(main())
@@ -0,0 +1,110 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from pathlib import Path
5
+ from typing import Dict, Tuple
6
+
7
+
8
+ @dataclass(frozen=True)
9
+ class ParseStats:
10
+ comments: int
11
+ blanks: int
12
+ invalid: int
13
+
14
+
15
+ def parse_env_file(path: str | Path) -> Tuple[Dict[str, str], ParseStats]:
16
+ p = Path(path)
17
+ if not p.exists() or not p.is_file():
18
+ raise FileNotFoundError(f"File not found: {p}")
19
+
20
+ mapping: Dict[str, str] = {}
21
+ comments = 0
22
+ blanks = 0
23
+ invalid = 0
24
+
25
+ with p.open("r", encoding="utf-8") as f:
26
+ for raw in f:
27
+ line = raw.strip()
28
+ if not line:
29
+ blanks += 1
30
+ continue
31
+ if line.startswith("#"):
32
+ comments += 1
33
+ continue
34
+ if "=" not in line:
35
+ invalid += 1
36
+ continue
37
+ key, value = line.split("=", 1)
38
+ key = key.strip()
39
+ value = value.strip()
40
+ if not key:
41
+ invalid += 1
42
+ continue
43
+ mapping[key] = value
44
+
45
+ return mapping, ParseStats(comments=comments, blanks=blanks, invalid=invalid)
46
+
47
+
48
+ def compare_env_mappings(old: Dict[str, str], new: Dict[str, str]) -> dict:
49
+ old_keys = set(old)
50
+ new_keys = set(new)
51
+
52
+ added_keys = sorted(new_keys - old_keys)
53
+ removed_keys = sorted(old_keys - new_keys)
54
+ common = sorted(old_keys & new_keys)
55
+ changed_keys = [k for k in common if old[k] != new[k]]
56
+
57
+ return {
58
+ "added": {k: new[k] for k in added_keys},
59
+ "removed": {k: old[k] for k in removed_keys},
60
+ "changed": {k: {"old": old[k], "new": new[k]} for k in changed_keys},
61
+ }
62
+
63
+
64
+ def compare_env_files(old_path: str | Path, new_path: str | Path) -> dict:
65
+ old_map, old_stats = parse_env_file(old_path)
66
+ new_map, new_stats = parse_env_file(new_path)
67
+ diff = compare_env_mappings(old_map, new_map)
68
+ diff["ignored"] = {
69
+ str(Path(old_path).name): {
70
+ "comments": old_stats.comments,
71
+ "blanks": old_stats.blanks,
72
+ "invalid": old_stats.invalid,
73
+ },
74
+ str(Path(new_path).name): {
75
+ "comments": new_stats.comments,
76
+ "blanks": new_stats.blanks,
77
+ "invalid": new_stats.invalid,
78
+ },
79
+ }
80
+ return diff
81
+
82
+
83
+ def render_report(diff: dict, old_label: str, new_label: str) -> str:
84
+ lines: list[str] = []
85
+
86
+ added = diff["added"]
87
+ removed = diff["removed"]
88
+ changed = diff["changed"]
89
+
90
+ lines.append(f"ADDED ({len(added)})")
91
+ for k in sorted(added):
92
+ lines.append(f" + {k}={added[k]}")
93
+
94
+ lines.append(f"REMOVED ({len(removed)})")
95
+ for k in sorted(removed):
96
+ lines.append(f" - {k}={removed[k]}")
97
+
98
+ lines.append(f"CHANGED ({len(changed)})")
99
+ for k in sorted(changed):
100
+ lines.append(f" ~ {k}: {changed[k]['old']} -> {changed[k]['new']}")
101
+
102
+ ignored = diff.get("ignored", {})
103
+ lines.append("IGNORED")
104
+ for label in (old_label, new_label):
105
+ stats = ignored.get(label, {"comments": 0, "blanks": 0, "invalid": 0})
106
+ lines.append(
107
+ f" {label}: comments={stats['comments']} blanks={stats['blanks']} invalid={stats['invalid']}"
108
+ )
109
+
110
+ return "\n".join(lines)
@@ -0,0 +1,64 @@
1
+ Metadata-Version: 2.4
2
+ Name: minimindslab-env-file-diff
3
+ Version: 0.1.0
4
+ Summary: Deterministically compare two .env-style files and report added, removed, changed, and ignored keys with stable ordering.
5
+ Author: MiniMindsLab
6
+ License: MIT
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Dynamic: license-file
11
+
12
+ # MiniMindsLab Env File Diff
13
+
14
+ Deterministically compare two `.env`-style files and report:
15
+
16
+ - Added keys
17
+ - Removed keys
18
+ - Changed keys
19
+ - Ignored lines (comments/blank/invalid)
20
+
21
+ ## Features
22
+
23
+ - Stable ordering (sorted keys in output)
24
+ - Whitespace-tolerant parsing
25
+ - `#` comments and blank lines are ignored
26
+ - Duplicate keys resolve by **last occurrence wins**
27
+ - Pure Python standard library only
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ pip install minimindslab-env-file-diff
33
+ ```
34
+
35
+ ## CLI Usage
36
+
37
+ ```bash
38
+ miniminds-env-diff path/to/old.env path/to/new.env
39
+ ```
40
+
41
+ Example output:
42
+
43
+ ```text
44
+ ADDED (1)
45
+ + NEW_KEY=new
46
+ REMOVED (1)
47
+ - OLD_KEY=old
48
+ CHANGED (1)
49
+ ~ SHARED_KEY: before -> after
50
+ IGNORED
51
+ old.env: comments=1 blanks=1 invalid=0
52
+ new.env: comments=0 blanks=2 invalid=1
53
+ ```
54
+
55
+ ## Library Usage
56
+
57
+ ```python
58
+ from minimindslab_env_file_diff import compare_env_files
59
+
60
+ result = compare_env_files("old.env", "new.env")
61
+ print(result["added"])
62
+ print(result["removed"])
63
+ print(result["changed"])
64
+ ```
@@ -0,0 +1,9 @@
1
+ minimindslab_env_file_diff/__init__.py,sha256=Q-McO8sQ-qe_U0KpF2WF5BS94b9zs0rcuDkCSataJ8s,235
2
+ minimindslab_env_file_diff/__main__.py,sha256=I3cGLcfVs-Lb7ejWtQlx16H3jqa_S6UPaUNnO1yFwHA,823
3
+ minimindslab_env_file_diff/core.py,sha256=ukCitXNNarUThdDCsfjTlI0oYx9TB9TBkSTJOg1QFzU,3226
4
+ minimindslab_env_file_diff-0.1.0.dist-info/licenses/LICENSE,sha256=9SsHAp-rmsco8evLbp-_802okWchTYdG-RZx5d3yddM,1069
5
+ minimindslab_env_file_diff-0.1.0.dist-info/METADATA,sha256=R9TK0vJurNE9IDAhWN2Y6HvdtLiHlEi_a4LoW2KESzU,1316
6
+ minimindslab_env_file_diff-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
7
+ minimindslab_env_file_diff-0.1.0.dist-info/entry_points.txt,sha256=Z_1b5-2u-ASyyVnMjjkxuKD1xJdQeqODCLhwg6YhYwU,80
8
+ minimindslab_env_file_diff-0.1.0.dist-info/top_level.txt,sha256=nqplP7V34k8mCSAKFFA2ZBQe7-VbQCYf9MW2n5coq8A,27
9
+ minimindslab_env_file_diff-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.0.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ miniminds-env-diff = minimindslab_env_file_diff.__main__:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 MiniMindsLab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ minimindslab_env_file_diff