filesweep-cli 3.0.0__tar.gz → 3.0.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: filesweep-cli
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: Safe, reversible Windows command-line file organiser.
5
5
  Author: Emmanuelaudu
6
6
  License-Expression: MIT
@@ -54,11 +54,11 @@ To upgrade an existing installation:
54
54
  pip install --upgrade filesweep-cli
55
55
  ```
56
56
 
57
- From a local clone, you can also run `python sweep.py` directly or install in editable mode with `pip install -e .` (which loads `rules.json` from the repository directory).
57
+ From a local clone, you can also run `python -m filesweep.sweep` directly or install in editable mode with `pip install -e .` (which loads `filesweep/rules.json` from the package directory).
58
58
 
59
59
  ## Quick Start
60
60
 
61
- Run `sweep` from any folder (or `python sweep.py` from the repository root):
61
+ Run `sweep` from any folder (or `python -m filesweep.sweep` from the repository root):
62
62
 
63
63
  ```powershell
64
64
  # Launch the interactive menu (when run with no arguments in a terminal)
@@ -93,7 +93,7 @@ sweep --version
93
93
 
94
94
  ### Interactive Mode
95
95
 
96
- Running `sweep` (or `python sweep.py`) with no arguments in an interactive terminal runs an immediate read-only scan and displays a compact dashboard (target folders, scan summary, top extensions, any smart file groups spotted, and the active naming mode, which defaults to `Original names (kebab-case: OFF)`), followed by a 6-option menu:
96
+ Running `sweep` (or `python -m filesweep.sweep`) with no arguments in an interactive terminal runs an immediate read-only scan and displays a compact dashboard (target folders, scan summary, top extensions, any smart file groups spotted, and the active naming mode, which defaults to `Original names (kebab-case: OFF)`), followed by a 6-option menu:
97
97
 
98
98
  1. Guided sort (review groups, preview plan, then apply)
99
99
  2. Switch folder (`Downloads`, `Desktop`, `Documents`, all defaults, or a custom path)
@@ -114,7 +114,7 @@ Redirected or piped output (`sweep > plan.txt`) automatically bypasses interacti
114
114
  | `--rename-only` | Rename eligible loose files in place to lowercase kebab-case without moving into category folders | Off (sort into folders) |
115
115
  | `--rename-folders` | Opt-in: rename safe top-level subfolders (and eligible files inside them when combined with `--rename-only`) to lowercase kebab-case | Off (never rename folders) |
116
116
  | `--target <path>` | Target folder to scan (repeatable) | `Downloads`, `Desktop`, `Documents` |
117
- | `--rules <path>` | Path to `rules.json` | `rules.json` alongside `sweep.py` |
117
+ | `--rules <path>` | Path to `rules.json` | Bundled `filesweep/rules.json` |
118
118
  | `--log-dir <path>` | Directory for write-ahead undo logs | `%USERPROFILE%\.sweep\logs` |
119
119
  | `undo` | Reverse the latest non-undone run | Latest active log |
120
120
  | `undo --run <id>` | Reverse a specific logged run ID | Latest active log |
@@ -145,7 +145,7 @@ Sweep evaluates eligible loose files in four ordered stages:
145
145
 
146
146
  ## Customising `rules.json`
147
147
 
148
- Edit [rules.json](rules.json) to adjust sorting without changing Python code:
148
+ Edit [filesweep/rules.json](filesweep/rules.json) to adjust sorting without changing Python code:
149
149
 
150
150
  * `title_rules`: Ordered list of `{"bucket": "<FolderName>", "keywords": ["..."]}` entries evaluated first against filename stems (multi-word keywords match across spaces, hyphens, and underscores).
151
151
  * `rules`: Ordered list of `{"category": "<FolderName>", "extensions": [".ext", ...]}` entries evaluated when no title rule matches, ending with `"*"` as a catch-all.
@@ -164,10 +164,12 @@ python -m unittest discover -s tests -v
164
164
  filesweep-cli/
165
165
  ├── LICENSE
166
166
  ├── README.md
167
- ├── clustering.py
167
+ ├── filesweep/
168
+ │ ├── __init__.py
169
+ │ ├── clustering.py
170
+ │ ├── rules.json
171
+ │ └── sweep.py
168
172
  ├── pyproject.toml
169
- ├── rules.json
170
- ├── sweep.py
171
173
  └── tests/
172
174
  └── test_sweep.py
173
175
  ```
@@ -32,11 +32,11 @@ To upgrade an existing installation:
32
32
  pip install --upgrade filesweep-cli
33
33
  ```
34
34
 
35
- From a local clone, you can also run `python sweep.py` directly or install in editable mode with `pip install -e .` (which loads `rules.json` from the repository directory).
35
+ From a local clone, you can also run `python -m filesweep.sweep` directly or install in editable mode with `pip install -e .` (which loads `filesweep/rules.json` from the package directory).
36
36
 
37
37
  ## Quick Start
38
38
 
39
- Run `sweep` from any folder (or `python sweep.py` from the repository root):
39
+ Run `sweep` from any folder (or `python -m filesweep.sweep` from the repository root):
40
40
 
41
41
  ```powershell
42
42
  # Launch the interactive menu (when run with no arguments in a terminal)
@@ -71,7 +71,7 @@ sweep --version
71
71
 
72
72
  ### Interactive Mode
73
73
 
74
- Running `sweep` (or `python sweep.py`) with no arguments in an interactive terminal runs an immediate read-only scan and displays a compact dashboard (target folders, scan summary, top extensions, any smart file groups spotted, and the active naming mode, which defaults to `Original names (kebab-case: OFF)`), followed by a 6-option menu:
74
+ Running `sweep` (or `python -m filesweep.sweep`) with no arguments in an interactive terminal runs an immediate read-only scan and displays a compact dashboard (target folders, scan summary, top extensions, any smart file groups spotted, and the active naming mode, which defaults to `Original names (kebab-case: OFF)`), followed by a 6-option menu:
75
75
 
76
76
  1. Guided sort (review groups, preview plan, then apply)
77
77
  2. Switch folder (`Downloads`, `Desktop`, `Documents`, all defaults, or a custom path)
@@ -92,7 +92,7 @@ Redirected or piped output (`sweep > plan.txt`) automatically bypasses interacti
92
92
  | `--rename-only` | Rename eligible loose files in place to lowercase kebab-case without moving into category folders | Off (sort into folders) |
93
93
  | `--rename-folders` | Opt-in: rename safe top-level subfolders (and eligible files inside them when combined with `--rename-only`) to lowercase kebab-case | Off (never rename folders) |
94
94
  | `--target <path>` | Target folder to scan (repeatable) | `Downloads`, `Desktop`, `Documents` |
95
- | `--rules <path>` | Path to `rules.json` | `rules.json` alongside `sweep.py` |
95
+ | `--rules <path>` | Path to `rules.json` | Bundled `filesweep/rules.json` |
96
96
  | `--log-dir <path>` | Directory for write-ahead undo logs | `%USERPROFILE%\.sweep\logs` |
97
97
  | `undo` | Reverse the latest non-undone run | Latest active log |
98
98
  | `undo --run <id>` | Reverse a specific logged run ID | Latest active log |
@@ -123,7 +123,7 @@ Sweep evaluates eligible loose files in four ordered stages:
123
123
 
124
124
  ## Customising `rules.json`
125
125
 
126
- Edit [rules.json](rules.json) to adjust sorting without changing Python code:
126
+ Edit [filesweep/rules.json](filesweep/rules.json) to adjust sorting without changing Python code:
127
127
 
128
128
  * `title_rules`: Ordered list of `{"bucket": "<FolderName>", "keywords": ["..."]}` entries evaluated first against filename stems (multi-word keywords match across spaces, hyphens, and underscores).
129
129
  * `rules`: Ordered list of `{"category": "<FolderName>", "extensions": [".ext", ...]}` entries evaluated when no title rule matches, ending with `"*"` as a catch-all.
@@ -142,10 +142,12 @@ python -m unittest discover -s tests -v
142
142
  filesweep-cli/
143
143
  ├── LICENSE
144
144
  ├── README.md
145
- ├── clustering.py
145
+ ├── filesweep/
146
+ │ ├── __init__.py
147
+ │ ├── clustering.py
148
+ │ ├── rules.json
149
+ │ └── sweep.py
146
150
  ├── pyproject.toml
147
- ├── rules.json
148
- ├── sweep.py
149
151
  └── tests/
150
152
  └── test_sweep.py
151
153
  ```
@@ -0,0 +1,2 @@
1
+ """Sweep: safe, reversible Windows command-line file organiser."""
2
+
@@ -0,0 +1,150 @@
1
+ {
2
+ "title_rules": [
3
+ {
4
+ "bucket": "Receipts",
5
+ "keywords": [
6
+ "receipt",
7
+ "invoice"
8
+ ]
9
+ },
10
+ {
11
+ "bucket": "Presentations",
12
+ "keywords": [
13
+ "slide",
14
+ "slides",
15
+ "presentation",
16
+ "deck"
17
+ ]
18
+ },
19
+ {
20
+ "bucket": "Transcripts",
21
+ "keywords": [
22
+ "transcription",
23
+ "transcript"
24
+ ]
25
+ },
26
+ {
27
+ "bucket": "Diagrams",
28
+ "keywords": [
29
+ "dfd",
30
+ "flowchart",
31
+ "architecture",
32
+ "schematic"
33
+ ]
34
+ },
35
+ {
36
+ "bucket": "Projects",
37
+ "keywords": [
38
+ "cabanca",
39
+ "vccn",
40
+ "nocopo"
41
+ ]
42
+ }
43
+ ],
44
+ "rules": [
45
+ {
46
+ "category": "Documents",
47
+ "extensions": [
48
+ ".pdf",
49
+ ".doc",
50
+ ".docx",
51
+ ".txt",
52
+ ".rtf",
53
+ ".odt",
54
+ ".xls",
55
+ ".xlsx",
56
+ ".csv",
57
+ ".ppt",
58
+ ".pptx",
59
+ ".ods",
60
+ ".odp",
61
+ ".md",
62
+ ".epub",
63
+ ".html",
64
+ ".htm",
65
+ ".drawio",
66
+ ".thmx"
67
+ ]
68
+ },
69
+ {
70
+ "category": "Images",
71
+ "extensions": [
72
+ ".jpg",
73
+ ".jpeg",
74
+ ".jfif",
75
+ ".png",
76
+ ".gif",
77
+ ".bmp",
78
+ ".webp",
79
+ ".svg",
80
+ ".ico",
81
+ ".tif",
82
+ ".tiff",
83
+ ".heic",
84
+ ".raw"
85
+ ]
86
+ },
87
+ {
88
+ "category": "Video",
89
+ "extensions": [
90
+ ".mp4",
91
+ ".mkv",
92
+ ".avi",
93
+ ".mov",
94
+ ".wmv",
95
+ ".flv",
96
+ ".webm",
97
+ ".m4v",
98
+ ".mpeg",
99
+ ".mpg",
100
+ ".srt"
101
+ ]
102
+ },
103
+ {
104
+ "category": "Audio",
105
+ "extensions": [
106
+ ".mp3",
107
+ ".wav",
108
+ ".flac",
109
+ ".aac",
110
+ ".ogg",
111
+ ".wma",
112
+ ".m4a",
113
+ ".opus"
114
+ ]
115
+ },
116
+ {
117
+ "category": "Archives",
118
+ "extensions": [
119
+ ".zip",
120
+ ".rar",
121
+ ".7z",
122
+ ".tar",
123
+ ".gz",
124
+ ".bz2",
125
+ ".xz",
126
+ ".iso"
127
+ ]
128
+ },
129
+ {
130
+ "category": "Installers",
131
+ "extensions": [
132
+ ".exe",
133
+ ".msi",
134
+ ".msix",
135
+ ".msixbundle",
136
+ ".appx",
137
+ ".apk",
138
+ ".apkm",
139
+ ".whl"
140
+ ]
141
+ },
142
+ {
143
+ "category": "Other",
144
+ "extensions": [
145
+ "*"
146
+ ]
147
+ }
148
+ ]
149
+ }
150
+
@@ -8,6 +8,7 @@ from ctypes import wintypes
8
8
  from dataclasses import dataclass
9
9
  from datetime import datetime, timezone
10
10
  import importlib.metadata
11
+ import importlib.resources
11
12
  import io
12
13
  import json
13
14
  import os
@@ -18,7 +19,7 @@ import sys
18
19
  import tempfile
19
20
  import uuid
20
21
 
21
- from clustering import (
22
+ from .clustering import (
22
23
  CandidateCluster,
23
24
  FOLDER_PROJECT_MARKERS,
24
25
  PROJECT_MARKER_EXTS,
@@ -62,7 +63,57 @@ _kernel32.CreateFileW.restype = wintypes.HANDLE
62
63
  _kernel32.CloseHandle.argtypes = [wintypes.HANDLE]
63
64
  _kernel32.CloseHandle.restype = wintypes.BOOL
64
65
  INVALID_HANDLE_VALUE = wintypes.HANDLE(-1).value
65
- FALLBACK_VERSION = "3.0.0"
66
+ FALLBACK_VERSION = "3.0.1"
67
+
68
+ DEFAULT_RULES_DATA: dict[str, list[dict[str, object]]] = {
69
+ "title_rules": [
70
+ {"bucket": "Receipts", "keywords": ["receipt", "invoice"]},
71
+ {"bucket": "Presentations", "keywords": ["slide", "slides", "presentation", "deck"]},
72
+ {"bucket": "Transcripts", "keywords": ["transcription", "transcript"]},
73
+ {"bucket": "Diagrams", "keywords": ["dfd", "flowchart", "architecture", "schematic"]},
74
+ {"bucket": "Projects", "keywords": ["cabanca", "vccn", "nocopo"]},
75
+ ],
76
+ "rules": [
77
+ {
78
+ "category": "Documents",
79
+ "extensions": [
80
+ ".pdf", ".doc", ".docx", ".txt", ".rtf", ".odt", ".xls", ".xlsx",
81
+ ".csv", ".ppt", ".pptx", ".ods", ".odp", ".md", ".epub", ".html",
82
+ ".htm", ".drawio", ".thmx",
83
+ ],
84
+ },
85
+ {
86
+ "category": "Images",
87
+ "extensions": [
88
+ ".jpg", ".jpeg", ".jfif", ".png", ".gif", ".bmp", ".webp",
89
+ ".svg", ".ico", ".tif", ".tiff", ".heic", ".raw",
90
+ ],
91
+ },
92
+ {
93
+ "category": "Video",
94
+ "extensions": [
95
+ ".mp4", ".mkv", ".avi", ".mov", ".wmv", ".flv", ".webm",
96
+ ".m4v", ".mpeg", ".mpg", ".srt",
97
+ ],
98
+ },
99
+ {
100
+ "category": "Audio",
101
+ "extensions": [".mp3", ".wav", ".flac", ".aac", ".ogg", ".wma", ".m4a", ".opus"],
102
+ },
103
+ {
104
+ "category": "Archives",
105
+ "extensions": [".zip", ".rar", ".7z", ".tar", ".gz", ".bz2", ".xz", ".iso"],
106
+ },
107
+ {
108
+ "category": "Installers",
109
+ "extensions": [".exe", ".msi", ".msix", ".msixbundle", ".appx", ".apk", ".apkm", ".whl"],
110
+ },
111
+ {
112
+ "category": "Other",
113
+ "extensions": ["*"],
114
+ },
115
+ ],
116
+ }
66
117
 
67
118
 
68
119
  def get_version() -> str:
@@ -203,9 +254,8 @@ def _collision_key(path: Path) -> str:
203
254
  return os.path.normcase(str(path)).casefold()
204
255
 
205
256
 
206
- def load_rules(rules_path: Path) -> RuleSet:
207
- """Load ordered title and extension rules from a JSON file."""
208
- data = json.loads(rules_path.read_text(encoding="utf-8"))
257
+ def _parse_rules_data(data: dict) -> RuleSet:
258
+ """Validate and compile ordered title and extension rules from a parsed mapping."""
209
259
  raw_ext = data.get("rules")
210
260
  if not isinstance(raw_ext, list):
211
261
  raise ValueError("rules.json must contain a 'rules' list.")
@@ -236,6 +286,24 @@ def load_rules(rules_path: Path) -> RuleSet:
236
286
  return RuleSet(title_rules=title_rules, ext_rules=ext_rules)
237
287
 
238
288
 
289
+ def load_default_rules() -> RuleSet:
290
+ """Load bundled rules.json via importlib.resources, falling back to embedded defaults."""
291
+ try:
292
+ resource = importlib.resources.files("filesweep").joinpath("rules.json")
293
+ data = json.loads(resource.read_text(encoding="utf-8"))
294
+ return _parse_rules_data(data)
295
+ except (FileNotFoundError, ModuleNotFoundError, OSError, json.JSONDecodeError, KeyError, TypeError, ValueError):
296
+ return _parse_rules_data(DEFAULT_RULES_DATA)
297
+
298
+
299
+ def load_rules(rules_path: Path | None = None) -> RuleSet:
300
+ """Load ordered title and extension rules from rules_path or bundled defaults."""
301
+ if rules_path is None:
302
+ return load_default_rules()
303
+ data = json.loads(rules_path.read_text(encoding="utf-8"))
304
+ return _parse_rules_data(data)
305
+
306
+
239
307
  def match_title_rule(path: Path, rules: RuleSet | list[tuple[str, list[str]]]) -> tuple[str | None, str]:
240
308
  """Evaluate custom title_rules and return (bucket, rule_label) or (None, '-')."""
241
309
  if isinstance(rules, RuleSet):
@@ -1592,7 +1660,7 @@ def _interactive_batch_rename(
1592
1660
 
1593
1661
  def run_interactive(
1594
1662
  targets: list[Path],
1595
- rules_path: Path,
1663
+ rules_path: Path | None,
1596
1664
  log_dir: Path,
1597
1665
  allow_temp_sandbox: bool = False,
1598
1666
  kebab_case: bool = False,
@@ -1601,6 +1669,7 @@ def run_interactive(
1601
1669
  current_targets = list(targets)
1602
1670
  allow_temp = allow_temp_sandbox
1603
1671
  kebab_enabled = bool(kebab_case)
1672
+ effective_rules_path = rules_path if rules_path is not None else default_rules_path()
1604
1673
  while True:
1605
1674
  try:
1606
1675
  rules = load_rules(rules_path)
@@ -1625,7 +1694,7 @@ def run_interactive(
1625
1694
 
1626
1695
  if choice == "1":
1627
1696
  _interactive_guided_sort(
1628
- items, notices, discovered, current_targets, rules_path, log_dir, kebab_enabled
1697
+ items, notices, discovered, current_targets, effective_rules_path, log_dir, kebab_enabled
1629
1698
  )
1630
1699
  elif choice == "2":
1631
1700
  current_targets, allow_temp = _interactive_change_target(current_targets, allow_temp)
@@ -1635,7 +1704,7 @@ def run_interactive(
1635
1704
  elif choice == "4":
1636
1705
  _interactive_undo(log_dir)
1637
1706
  elif choice == "5":
1638
- _interactive_batch_rename(current_targets, allow_temp, rules_path, log_dir)
1707
+ _interactive_batch_rename(current_targets, allow_temp, effective_rules_path, log_dir)
1639
1708
  elif choice == "6":
1640
1709
  print("Goodbye.")
1641
1710
  return 0
@@ -1649,7 +1718,12 @@ def build_parser() -> argparse.ArgumentParser:
1649
1718
  parser.add_argument("--version", action="version", version=f"%(prog)s {get_version()}")
1650
1719
  parser.add_argument("--apply", action="store_true", help="Execute planned moves (default is dry-run).")
1651
1720
  parser.add_argument("--target", action="append", dest="targets", help="Target folder to scan (repeatable).")
1652
- parser.add_argument("--rules", type=Path, default=default_rules_path(), help="Path to rules.json.")
1721
+ parser.add_argument(
1722
+ "--rules",
1723
+ type=Path,
1724
+ default=None,
1725
+ help="Path to rules.json (defaults to bundled rules.json).",
1726
+ )
1653
1727
  parser.add_argument("--log-dir", type=Path, default=None, help="Override directory for undo logs.")
1654
1728
  parser.add_argument(
1655
1729
  "--kebab",
@@ -1693,7 +1767,7 @@ def main(argv: list[str] | None = None) -> int:
1693
1767
 
1694
1768
  raw_argv = sys.argv[1:] if argv is None else argv
1695
1769
  if _is_interactive_session(raw_argv):
1696
- return run_interactive(default_targets(), default_rules_path(), default_log_dir())
1770
+ return run_interactive(default_targets(), None, default_log_dir())
1697
1771
 
1698
1772
  args = build_parser().parse_args(raw_argv)
1699
1773
  log_dir = args.log_dir if getattr(args, "log_dir", None) else default_log_dir()
@@ -1765,7 +1839,8 @@ def main(argv: list[str] | None = None) -> int:
1765
1839
  return 0
1766
1840
 
1767
1841
  apply_mode = "Batch rename" if (args.rename_only or args.rename_folders) else "Sort"
1768
- run_id, summary = apply_plan(items, targets, args.rules, log_dir, mode=apply_mode)
1842
+ effective_rules_path = args.rules if args.rules is not None else default_rules_path()
1843
+ run_id, summary = apply_plan(items, targets, effective_rules_path, log_dir, mode=apply_mode)
1769
1844
  print("")
1770
1845
  if run_id is None:
1771
1846
  print(f"Apply complete: 0 moved, {summary['skipped']} skipped, 0 failed.")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: filesweep-cli
3
- Version: 3.0.0
3
+ Version: 3.0.1
4
4
  Summary: Safe, reversible Windows command-line file organiser.
5
5
  Author: Emmanuelaudu
6
6
  License-Expression: MIT
@@ -54,11 +54,11 @@ To upgrade an existing installation:
54
54
  pip install --upgrade filesweep-cli
55
55
  ```
56
56
 
57
- From a local clone, you can also run `python sweep.py` directly or install in editable mode with `pip install -e .` (which loads `rules.json` from the repository directory).
57
+ From a local clone, you can also run `python -m filesweep.sweep` directly or install in editable mode with `pip install -e .` (which loads `filesweep/rules.json` from the package directory).
58
58
 
59
59
  ## Quick Start
60
60
 
61
- Run `sweep` from any folder (or `python sweep.py` from the repository root):
61
+ Run `sweep` from any folder (or `python -m filesweep.sweep` from the repository root):
62
62
 
63
63
  ```powershell
64
64
  # Launch the interactive menu (when run with no arguments in a terminal)
@@ -93,7 +93,7 @@ sweep --version
93
93
 
94
94
  ### Interactive Mode
95
95
 
96
- Running `sweep` (or `python sweep.py`) with no arguments in an interactive terminal runs an immediate read-only scan and displays a compact dashboard (target folders, scan summary, top extensions, any smart file groups spotted, and the active naming mode, which defaults to `Original names (kebab-case: OFF)`), followed by a 6-option menu:
96
+ Running `sweep` (or `python -m filesweep.sweep`) with no arguments in an interactive terminal runs an immediate read-only scan and displays a compact dashboard (target folders, scan summary, top extensions, any smart file groups spotted, and the active naming mode, which defaults to `Original names (kebab-case: OFF)`), followed by a 6-option menu:
97
97
 
98
98
  1. Guided sort (review groups, preview plan, then apply)
99
99
  2. Switch folder (`Downloads`, `Desktop`, `Documents`, all defaults, or a custom path)
@@ -114,7 +114,7 @@ Redirected or piped output (`sweep > plan.txt`) automatically bypasses interacti
114
114
  | `--rename-only` | Rename eligible loose files in place to lowercase kebab-case without moving into category folders | Off (sort into folders) |
115
115
  | `--rename-folders` | Opt-in: rename safe top-level subfolders (and eligible files inside them when combined with `--rename-only`) to lowercase kebab-case | Off (never rename folders) |
116
116
  | `--target <path>` | Target folder to scan (repeatable) | `Downloads`, `Desktop`, `Documents` |
117
- | `--rules <path>` | Path to `rules.json` | `rules.json` alongside `sweep.py` |
117
+ | `--rules <path>` | Path to `rules.json` | Bundled `filesweep/rules.json` |
118
118
  | `--log-dir <path>` | Directory for write-ahead undo logs | `%USERPROFILE%\.sweep\logs` |
119
119
  | `undo` | Reverse the latest non-undone run | Latest active log |
120
120
  | `undo --run <id>` | Reverse a specific logged run ID | Latest active log |
@@ -145,7 +145,7 @@ Sweep evaluates eligible loose files in four ordered stages:
145
145
 
146
146
  ## Customising `rules.json`
147
147
 
148
- Edit [rules.json](rules.json) to adjust sorting without changing Python code:
148
+ Edit [filesweep/rules.json](filesweep/rules.json) to adjust sorting without changing Python code:
149
149
 
150
150
  * `title_rules`: Ordered list of `{"bucket": "<FolderName>", "keywords": ["..."]}` entries evaluated first against filename stems (multi-word keywords match across spaces, hyphens, and underscores).
151
151
  * `rules`: Ordered list of `{"category": "<FolderName>", "extensions": [".ext", ...]}` entries evaluated when no title rule matches, ending with `"*"` as a catch-all.
@@ -164,10 +164,12 @@ python -m unittest discover -s tests -v
164
164
  filesweep-cli/
165
165
  ├── LICENSE
166
166
  ├── README.md
167
- ├── clustering.py
167
+ ├── filesweep/
168
+ │ ├── __init__.py
169
+ │ ├── clustering.py
170
+ │ ├── rules.json
171
+ │ └── sweep.py
168
172
  ├── pyproject.toml
169
- ├── rules.json
170
- ├── sweep.py
171
173
  └── tests/
172
174
  └── test_sweep.py
173
175
  ```
@@ -1,8 +1,10 @@
1
1
  LICENSE
2
2
  README.md
3
- clustering.py
4
3
  pyproject.toml
5
- sweep.py
4
+ filesweep/__init__.py
5
+ filesweep/clustering.py
6
+ filesweep/rules.json
7
+ filesweep/sweep.py
6
8
  filesweep_cli.egg-info/PKG-INFO
7
9
  filesweep_cli.egg-info/SOURCES.txt
8
10
  filesweep_cli.egg-info/dependency_links.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ sweep = filesweep.sweep:main
@@ -0,0 +1 @@
1
+ filesweep
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "filesweep-cli"
7
- version = "3.0.0"
7
+ version = "3.0.1"
8
8
  description = "Safe, reversible Windows command-line file organiser."
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -29,8 +29,14 @@ Repository = "https://github.com/Joshemmy/sweep-cli"
29
29
  Issues = "https://github.com/Joshemmy/sweep-cli/issues"
30
30
 
31
31
  [project.scripts]
32
- sweep = "sweep:main"
32
+ sweep = "filesweep.sweep:main"
33
33
 
34
34
  [tool.setuptools]
35
- py-modules = ["sweep", "clustering"]
35
+ include-package-data = true
36
+
37
+ [tool.setuptools.packages.find]
38
+ include = ["filesweep*"]
39
+
40
+ [tool.setuptools.package-data]
41
+ filesweep = ["rules.json"]
36
42
 
@@ -3,6 +3,8 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import contextlib
6
+ import errno
7
+ import importlib.resources
6
8
  import io
7
9
  import json
8
10
  import os
@@ -16,11 +18,12 @@ from unittest import mock
16
18
 
17
19
  sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
18
20
 
19
- import sweep # noqa: E402
20
- import clustering # noqa: E402
21
+ from filesweep import clustering # noqa: E402
22
+ from filesweep import sweep # noqa: E402
21
23
 
22
24
  REPO_ROOT = Path(__file__).resolve().parent.parent
23
- DEFAULT_RULES_PATH = REPO_ROOT / "rules.json"
25
+ PACKAGE_DIR = REPO_ROOT / "filesweep"
26
+ DEFAULT_RULES_PATH = PACKAGE_DIR / "rules.json"
24
27
 
25
28
 
26
29
  def _make_old(path: Path, age_hours: float = 48.0, content: bytes = b"data") -> Path:
@@ -906,6 +909,56 @@ class TestSweepV1(unittest.TestCase):
906
909
  self.assertEqual(code, 0)
907
910
  self.assertIn("Title: Receipts", buf.getvalue())
908
911
 
912
+ def test_bundled_rules_load_via_importlib_resources_without_rules_flag(self) -> None:
913
+ _make_old(self.target / "acme_receipt.pdf")
914
+ _make_old(self.target / "snapshot.png")
915
+ real_files = importlib.resources.files
916
+ buf = io.StringIO()
917
+ old_cwd = Path.cwd()
918
+ try:
919
+ os.chdir(self.root)
920
+ with (
921
+ mock.patch("importlib.resources.files", wraps=real_files) as mock_files,
922
+ contextlib.redirect_stdout(buf),
923
+ ):
924
+ code = sweep.main(["--target", str(self.target), "--log-dir", str(self.log_dir)])
925
+ finally:
926
+ os.chdir(old_cwd)
927
+ self.assertEqual(code, 0)
928
+ mock_files.assert_called_once_with("filesweep")
929
+ self.assertIn("Title: Receipts", buf.getvalue())
930
+ self.assertIn("Ext: Images", buf.getvalue())
931
+
932
+ def test_embedded_default_rules_fallback_when_rules_json_unavailable(self) -> None:
933
+ bundled_json = json.loads(DEFAULT_RULES_PATH.read_text(encoding="utf-8"))
934
+ self.assertEqual(sweep.DEFAULT_RULES_DATA, bundled_json)
935
+
936
+ _make_old(self.target / "acme_receipt.pdf")
937
+ _make_old(self.target / "snapshot.png")
938
+ buf = io.StringIO()
939
+ with (
940
+ mock.patch(
941
+ "importlib.resources.files",
942
+ side_effect=FileNotFoundError(errno.ENOENT, "No such file or directory", "rules.json"),
943
+ ),
944
+ contextlib.redirect_stdout(buf),
945
+ ):
946
+ code = sweep.main(["--target", str(self.target), "--log-dir", str(self.log_dir)])
947
+ self.assertEqual(code, 0)
948
+ self.assertIn("Title: Receipts", buf.getvalue())
949
+ self.assertIn("Ext: Images", buf.getvalue())
950
+
951
+ missing_rules = self.root / "missing_rules.json"
952
+ err_buf = io.StringIO()
953
+ with contextlib.redirect_stderr(err_buf):
954
+ err_code = sweep.main([
955
+ "--target", str(self.target),
956
+ "--rules", str(missing_rules),
957
+ "--log-dir", str(self.log_dir),
958
+ ])
959
+ self.assertEqual(err_code, 1)
960
+ self.assertIn("Error loading rules from", err_buf.getvalue())
961
+
909
962
  def test_rename_only_multi_folder_dry_run_apply_and_undo(self) -> None:
910
963
  folder_a = self.root / "BatchA"
911
964
  folder_b = self.root / "BatchB"
@@ -1441,7 +1494,10 @@ class TestSweepV1(unittest.TestCase):
1441
1494
  ])
1442
1495
  self.assertEqual(code_rename, 0)
1443
1496
 
1444
- logs = sorted(self.log_dir.glob("*.json"))
1497
+ logs = sorted(
1498
+ self.log_dir.glob("*.json"),
1499
+ key=lambda p: json.loads(p.read_text(encoding="utf-8"))["created_at"],
1500
+ )
1445
1501
  self.assertEqual(len(logs), 2)
1446
1502
  sort_payload = json.loads(logs[0].read_text(encoding="utf-8"))
1447
1503
  rename_payload = json.loads(logs[1].read_text(encoding="utf-8"))
@@ -1630,17 +1686,18 @@ class TestSweepV1(unittest.TestCase):
1630
1686
  self.assertIn("has already been undone.", reselect_buf.getvalue())
1631
1687
 
1632
1688
  def test_hard_constraints_no_deletion_apis_or_em_dashes(self) -> None:
1633
- sweep_src = (REPO_ROOT / "sweep.py").read_text(encoding="utf-8")
1634
- clustering_src = (REPO_ROOT / "clustering.py").read_text(encoding="utf-8")
1689
+ init_src = (PACKAGE_DIR / "__init__.py").read_text(encoding="utf-8")
1690
+ sweep_src = (PACKAGE_DIR / "sweep.py").read_text(encoding="utf-8")
1691
+ clustering_src = (PACKAGE_DIR / "clustering.py").read_text(encoding="utf-8")
1635
1692
  rules_src = DEFAULT_RULES_PATH.read_text(encoding="utf-8")
1636
1693
  readme_src = (REPO_ROOT / "README.md").read_text(encoding="utf-8")
1637
1694
  pyproject_src = (REPO_ROOT / "pyproject.toml").read_text(encoding="utf-8")
1638
1695
  tests_src = Path(__file__).read_text(encoding="utf-8")
1639
1696
 
1640
- for source in (sweep_src, clustering_src):
1697
+ for source in (init_src, sweep_src, clustering_src):
1641
1698
  for forbidden in ("unlink(", "rmdir(", "rmtree("):
1642
1699
  self.assertNotIn(forbidden, source)
1643
- for content in (sweep_src, clustering_src, rules_src, readme_src, pyproject_src, tests_src):
1700
+ for content in (init_src, sweep_src, clustering_src, rules_src, readme_src, pyproject_src, tests_src):
1644
1701
  self.assertNotIn("\u2014", content)
1645
1702
  self.assertNotIn("\u2192", content)
1646
1703
 
@@ -1,2 +0,0 @@
1
- [console_scripts]
2
- sweep = sweep:main
@@ -1,2 +0,0 @@
1
- clustering
2
- sweep
File without changes
File without changes