haraka 0.2.42__py3-none-any.whl → 0.2.43__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.
@@ -21,9 +21,9 @@ Requires: pip install pathspec PyYAML
21
21
  from __future__ import annotations
22
22
 
23
23
  from pathlib import Path
24
+ from typing import Tuple, List
24
25
 
25
26
  from pathspec import PathSpec
26
- from typing import Tuple, List
27
27
 
28
28
  from haraka.post_gen.service.fileOps.files import FileOps
29
29
  from haraka.utils import Logger, divider
@@ -35,12 +35,6 @@ _MANIFEST_DIR = Path(__file__).resolve().parent.parent.parent / "manifests"
35
35
  # --------------------------------------------------------------------------- #
36
36
  # main purger #
37
37
  # --------------------------------------------------------------------------- #
38
- def is_dir_protected(rel: str, spec: PathSpec) -> bool:
39
- """True if *rel* (or an ancestor) is matched by keep spec."""
40
- # `spec.match_file` already walks ancestors for dirs
41
- return spec.match_file(rel)
42
-
43
-
44
38
  class ResourcePurger:
45
39
  """Filesystem cleaner driven by variant manifest files."""
46
40
 
@@ -48,6 +42,7 @@ class ResourcePurger:
48
42
  self._f = fops
49
43
  self._log = logger or Logger("ResourcePurger")
50
44
  self._log.debug("ResourcePurger initialized with FileOps instance and Logger.")
45
+ self._protected_dirs: List[str] = []
51
46
 
52
47
  # ------------------------------ public API ----------------------------- #
53
48
  def purge(self, variant: str, project_dir: Path) -> None:
@@ -67,12 +62,11 @@ class ResourcePurger:
67
62
 
68
63
  raw_patterns, raw_protected_dirs = config.load_manifest(variant)
69
64
  keep_patterns = [p.rstrip("/") for p in raw_patterns]
70
- protected_dirs = [p.rstrip("/") for p in raw_protected_dirs]
65
+ self._protected_dirs = [p.rstrip("/") for p in raw_protected_dirs]
71
66
 
72
67
  self._log.debug(f"Loaded manifest for variant '{variant}': {keep_patterns}")
73
68
 
74
69
  spec = config.build_spec(keep_patterns)
75
- protected_spec = config.build_spec(protected_dirs)
76
70
  self._log.debug(f"Built PathSpec for keep patterns. Total patterns: {len(keep_patterns)}")
77
71
 
78
72
  self._log.info(f"Keeping {len(keep_patterns)} pattern(s)")
@@ -81,9 +75,15 @@ class ResourcePurger:
81
75
 
82
76
  all_paths = self._walk_tree(project_dir)
83
77
 
84
- matched, non_dirs, non_files, _ = self.classify_paths(all_paths, project_dir, spec)
78
+ matched, non_matched_dirs, non_matched_files, directories_skipped = \
79
+ self.classify_paths(all_paths, project_dir, spec)
85
80
 
86
- self._purge_unrelated(project_dir, matched, non_dirs, non_files, protected_spec, spec)
81
+ self._purge_unrelated(
82
+ project_dir,
83
+ matched,
84
+ non_matched_dirs,
85
+ non_matched_files
86
+ )
87
87
 
88
88
  self._log.debug(f"Finished purging unrelated paths in project directory: {project_dir}")
89
89
 
@@ -108,7 +108,9 @@ class ResourcePurger:
108
108
 
109
109
  def classify_paths(
110
110
  self,
111
- paths: List[Path], root: Path, spec: PathSpec
111
+ paths: List[Path],
112
+ root: Path,
113
+ spec: PathSpec,
112
114
  ) -> Tuple[List[str], List[str], List[str], List[str]]:
113
115
  """Split paths into keep/delete buckets."""
114
116
  matched: List[str] = []
@@ -125,7 +127,8 @@ class ResourcePurger:
125
127
  continue
126
128
 
127
129
  if path.is_dir():
128
- if is_dir_protected(rel, spec):
130
+ # skip deletion if this dir is exactly in protected list
131
+ if rel in self._protected_dirs:
129
132
  self._log.debug(f"⏭️ SKIPPING DELETE: Protected ancestor found: {path}")
130
133
  directories_skipped.append(rel)
131
134
  else:
@@ -148,11 +151,12 @@ class ResourcePurger:
148
151
  self._log.info(" (none)")
149
152
  self._log.info("-" * 70)
150
153
 
151
- def _dir_batch_delete(self, title: str, items: List[str], root: Path, protected_spec: PathSpec, keep_spec: PathSpec) -> None:
154
+ def _dir_batch_delete(self, title: str, items: List[str], root: Path) -> None:
152
155
  self._log.info(f"{title} — {len(items)}")
153
156
  if items:
154
157
  for p in sorted(items):
155
- if protected_spec.match_file(p) and keep_spec.match_file(p):
158
+ # only protect exact matches
159
+ if p in self._protected_dirs:
156
160
  self._log.debug(f" 🛡️ PROTECTED DIRECTORY DIR {p}")
157
161
  else:
158
162
  full_path = root / Path(p)
@@ -162,37 +166,25 @@ class ResourcePurger:
162
166
  self._log.info("-" * 70)
163
167
 
164
168
  def _file_batch_delete(self, title: str, items: List[str], root: Path) -> None:
165
- self._log.info(f"{title} — {len(items)}")
166
- if items:
167
- for p in sorted(items):
168
- full_path = root / Path(p)
169
- self._f.remove_file(full_path)
170
- else:
171
- self._log.info(" (none)")
172
- self._log.info("-" * 70)
169
+ self._log.info(f"{title} — {len(items)}")
170
+ if items:
171
+ for p in sorted(items):
172
+ full_path = root / Path(p)
173
+ self._f.remove_file(full_path)
174
+ else:
175
+ self._log.info(" (none)")
176
+ self._log.info("-" * 70)
173
177
 
174
178
  def _purge_unrelated(
175
179
  self,
176
180
  root: Path,
177
181
  matched: List[str],
178
182
  non_matched_dirs: List[str],
179
- non_matched_files: List[str],
180
- protected_spec: PathSpec,
181
- keep_spec: PathSpec,
183
+ non_matched_files: List[str]
182
184
  ) -> None:
183
185
  """Human-friendly digest of keep/delete results."""
184
186
  self._log.info("\n" + "=" * 70)
185
187
  self._print_matches("✅ MATCHED (keep)", matched)
186
- self._dir_batch_delete("🗂️ NON-MATCHED DIRECTORIES (delete)", non_matched_dirs, root, protected_spec, keep_spec)
188
+ self._dir_batch_delete("🗂️ NON-MATCHED DIRECTORIES (delete)", non_matched_dirs, root)
187
189
  self._file_batch_delete("📄 NON-MATCHED FILES (delete)", non_matched_files, root)
188
190
  self._log.info("=" * 70)
189
-
190
- @staticmethod
191
- def _is_dir_protected(relative_path: str, spec: PathSpec) -> bool:
192
- """
193
- Walks from `path` up to `root`, and returns True if any ancestor
194
- is matched by the spec.
195
- """
196
- if spec.match_file(relative_path):
197
- return True
198
- return False
@@ -2,14 +2,12 @@ variant: java-springboot
2
2
 
3
3
  keep:
4
4
  # ── application source ────────────────────────────
5
- - src/src/main
6
5
  - src/main/java/
7
6
  - src/main/java/**
8
7
  - src/main/resources/
9
8
  - src/main/resources/**
10
9
 
11
10
  # ── tests ─────────────────────────────────────────
12
- - src/test
13
11
  - src/test/java/
14
12
  - src/test/java/**
15
13
 
@@ -31,4 +29,6 @@ keep:
31
29
  - infra/**
32
30
 
33
31
  protected:
34
- - src/**
32
+ - src
33
+ - src/main
34
+ - src/test
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: haraka
3
- Version: 0.2.42
3
+ Version: 0.2.43
4
4
  Summary: Reusable post-generation helper for Cookiecutter micro-service templates
5
5
  Author-email: Will Burks <will@example.com>
6
6
  License: MIT
@@ -17,7 +17,7 @@ haraka/post_gen/service/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG
17
17
  haraka/post_gen/service/command.py,sha256=yvEzW9rMSXWeQ_2DXuQNtGH6sRuZnK6viMud-amFQXw,2348
18
18
  haraka/post_gen/service/fileOps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
19
19
  haraka/post_gen/service/fileOps/files.py,sha256=qsNftbLoo8HHARBwNSHe6dUVPCoqzgv1SHUOH56gj00,3058
20
- haraka/post_gen/service/fileOps/purge.py,sha256=dLwQal1uXgZaayTZkbgBSD-dA3mdz1HEYHaxVCjMD-Y,7625
20
+ haraka/post_gen/service/fileOps/purge.py,sha256=HWc9lUtmLtiTp7dVAO0YHXoHbWa6HVstc7XfmONQ470,7132
21
21
  haraka/post_gen/service/gitOps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
22
  haraka/post_gen/service/gitOps/gitops.py,sha256=clWny1m9qB4yr8asba8JwqBjewlMVsJUmIOCLtAL8RI,4052
23
23
  haraka/utils/__init__.py,sha256=3Cp4u0dyAGcmqes-tIr95KFsNsJx5Ji5Yzkto9546Hs,168
@@ -27,9 +27,9 @@ haraka/utils/logging/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
27
27
  haraka/utils/logging/log_util.py,sha256=UQq2E24q3brvXqcyGCjfSxxHH48JF_BMg54TKdl1SHk,1049
28
28
  haraka/utils/manifests/go-grpc-gateway-buf.yml,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
29
  haraka/utils/manifests/go-grpc-protoc.yml,sha256=OaQlfW_S_OguhW_UcpBVdqdEtUMlg-SrT4bqLhQrY7Y,936
30
- haraka/utils/manifests/java-springboot.yml,sha256=rR9SvbqggfCNER_4iMbrg-oOG1fwCMIiqrDUYg2zT6s,981
30
+ haraka/utils/manifests/java-springboot.yml,sha256=AfdfyYFKGg_860RmNhx3kVqffZdoKvpc01sk_ovY45s,974
31
31
  haraka/utils/manifests/python-fastapi.yml,sha256=nhO6S9j_r-S10nM8nuw7PtR247-ePhBXHvaXg74CjWw,922
32
- haraka-0.2.42.dist-info/METADATA,sha256=VdOQtgoaTKrtLDowkuse9yU1pYXfZ6SzgLIPDz-_PIs,579
33
- haraka-0.2.42.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
- haraka-0.2.42.dist-info/top_level.txt,sha256=1khpwypLKWoklVd_CgFiwAfcctVSXRoRPc3BI9lyIXo,7
35
- haraka-0.2.42.dist-info/RECORD,,
32
+ haraka-0.2.43.dist-info/METADATA,sha256=9pOC1_BAmPK5cX2aH_4Dbfi9KPVfL4-dKxEo0sSryDI,579
33
+ haraka-0.2.43.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
+ haraka-0.2.43.dist-info/top_level.txt,sha256=1khpwypLKWoklVd_CgFiwAfcctVSXRoRPc3BI9lyIXo,7
35
+ haraka-0.2.43.dist-info/RECORD,,