sphinx-cmd 0.4.0__tar.gz → 0.4.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.
Files changed (25) hide show
  1. {sphinx_cmd-0.4.0/sphinx_cmd.egg-info → sphinx_cmd-0.4.1}/PKG-INFO +4 -1
  2. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/README.md +3 -0
  3. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd/__init__.py +1 -1
  4. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd/cli.py +6 -0
  5. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd/commands/mv.py +116 -13
  6. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd/commands/rm.py +105 -9
  7. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1/sphinx_cmd.egg-info}/PKG-INFO +4 -1
  8. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/LICENSE +0 -0
  9. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/MANIFEST.in +0 -0
  10. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/pyproject.toml +0 -0
  11. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/setup.cfg +0 -0
  12. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd/commands/__init__.py +0 -0
  13. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd/config.py +0 -0
  14. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd/py.typed +0 -0
  15. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/SOURCES.txt +0 -0
  16. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/dependency_links.txt +0 -0
  17. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/entry_points.txt +0 -0
  18. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/requires.txt +0 -0
  19. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/top_level.txt +0 -0
  20. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/tests/test_cli.py +0 -0
  21. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/tests/test_config.py +0 -0
  22. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/tests/test_custom_directives.py +0 -0
  23. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/tests/test_integration.py +0 -0
  24. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/tests/test_mv.py +0 -0
  25. {sphinx_cmd-0.4.0 → sphinx_cmd-0.4.1}/tests/test_rm.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sphinx-cmd
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Command-line tools for Sphinx documentation management
5
5
  Author-email: Jared Dillard <jared.dillard@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/jdillard/sphinx-cmd
@@ -58,6 +58,9 @@ sphinx-cmd --dry-run COMMAND
58
58
 
59
59
  # Process additional directives beyond defaults
60
60
  sphinx-cmd --directives drawio-figure,drawio-image COMMAND
61
+
62
+ # Enable verbose output with detailed processing information
63
+ sphinx-cmd --verbose COMMAND
61
64
  ```
62
65
 
63
66
  By default, `sphinx-cmd` will automatically detect the context of your documentation project by finding the nearest `conf.py` file in the directory tree.
@@ -28,6 +28,9 @@ sphinx-cmd --dry-run COMMAND
28
28
 
29
29
  # Process additional directives beyond defaults
30
30
  sphinx-cmd --directives drawio-figure,drawio-image COMMAND
31
+
32
+ # Enable verbose output with detailed processing information
33
+ sphinx-cmd --verbose COMMAND
31
34
  ```
32
35
 
33
36
  By default, `sphinx-cmd` will automatically detect the context of your documentation project by finding the nearest `conf.py` file in the directory tree.
@@ -1,4 +1,4 @@
1
1
  # This file makes sphinx_cmd a Python package
2
2
  """Sphinx command-line utilities."""
3
3
 
4
- __version__ = "0.4.0"
4
+ __version__ = "0.4.1"
@@ -41,6 +41,12 @@ def create_parser():
41
41
  help="Additional directives to process as comma-separated list"
42
42
  " (e.g. 'drawio-figure,drawio-image')",
43
43
  )
44
+ parser.add_argument(
45
+ "-v",
46
+ "--verbose",
47
+ action="store_true",
48
+ help="Enable verbose output with detailed processing information",
49
+ )
44
50
 
45
51
  # Create subparsers for subcommands
46
52
  subparsers = parser.add_subparsers(
@@ -42,17 +42,23 @@ def find_all_rst_files(root_path: str) -> List[str]:
42
42
 
43
43
 
44
44
  def extract_references(
45
- file_path: str, context_path: Optional[str] = None
45
+ file_path: str, context_path: Optional[str] = None, verbose: bool = False
46
46
  ) -> Dict[str, List[str]]:
47
47
  """Extract all file references from an .rst file."""
48
48
  references = defaultdict(list)
49
49
 
50
+ if verbose:
51
+ print(f"Extracting references from: {file_path}")
52
+
50
53
  with open(file_path, "r", encoding="utf-8") as f:
51
54
  content = f.read()
52
55
 
53
56
  # Find toctree entries
54
57
  toctree_matches = TOCTREE_PATTERN.findall(content)
55
58
  for toctree_content in toctree_matches:
59
+ if verbose:
60
+ print(f"Found toctree directive in {file_path}")
61
+
56
62
  # Extract file references from toctree
57
63
  lines = toctree_content.split("\n")
58
64
  for line in lines:
@@ -62,6 +68,8 @@ def extract_references(
62
68
  ref_file = line.split()[0] if line.split() else ""
63
69
  if ref_file:
64
70
  references["toctree"].append(ref_file)
71
+ if verbose:
72
+ print(f"Found toctree entry: {ref_file}")
65
73
 
66
74
  # Find other types of references
67
75
  for ref_type, pattern in REFERENCE_PATTERNS.items():
@@ -75,25 +83,41 @@ def extract_references(
75
83
  else:
76
84
  ref_path = match
77
85
  references[ref_type].append(ref_path)
86
+ if verbose:
87
+ print(f"Found {ref_type} reference: {ref_path}")
88
+
89
+ if verbose and not references:
90
+ print(f"No references found in {file_path}")
78
91
 
79
92
  return dict(references)
80
93
 
81
94
 
82
95
  def find_files_referencing(
83
- target_file: str, all_files: List[str], context_path: Optional[str] = None
96
+ target_file: str,
97
+ all_files: List[str],
98
+ context_path: Optional[str] = None,
99
+ verbose: bool = False,
84
100
  ) -> List[Tuple[str, str]]:
85
101
  """Find all files that reference the target file."""
86
102
  referencing_files = []
87
103
  target_path = Path(target_file)
88
104
  target_stem = target_path.stem # filename without extension
89
105
 
106
+ if verbose:
107
+ print(f"Searching for references to {target_file} (stem: {target_stem})")
108
+ print(f"Checking {len(all_files)} files for references...")
109
+
90
110
  for file_path in all_files:
91
111
  if file_path == target_file:
112
+ if verbose:
113
+ print(f"Skipping the target file itself: {file_path}")
92
114
  continue
93
115
 
94
116
  try:
95
117
  # Extract references using context from conf.py if provided
96
- references = extract_references(file_path, context_path=context_path)
118
+ references = extract_references(
119
+ file_path, context_path=context_path, verbose=verbose
120
+ )
97
121
 
98
122
  for ref_type, ref_list in references.items():
99
123
  for ref in ref_list:
@@ -107,20 +131,31 @@ def find_files_referencing(
107
131
  or str(ref_path.with_suffix(".rst")) == target_file
108
132
  ):
109
133
  referencing_files.append((file_path, ref_type))
134
+ if verbose:
135
+ print(f"Found reference in {file_path} ({ref_type}): {ref}")
110
136
  break
111
137
  except Exception as e:
112
138
  print(f"Warning: Could not analyze {file_path}: {e}")
113
139
 
140
+ if verbose:
141
+ print(f"Found {len(referencing_files)} files referencing {target_file}")
142
+
114
143
  return referencing_files
115
144
 
116
145
 
117
- def update_references_in_file(file_path: str, old_ref: str, new_ref: str) -> bool:
146
+ def update_references_in_file(
147
+ file_path: str, old_ref: str, new_ref: str, verbose: bool = False
148
+ ) -> bool:
118
149
  """Update references to the moved file in a single file."""
119
150
  old_path = Path(old_ref)
120
151
  new_path = Path(new_ref)
121
152
  old_stem = old_path.stem
122
153
  new_stem = new_path.stem
123
154
 
155
+ if verbose:
156
+ print(f"Updating references in {file_path}")
157
+ print(f" Replacing references from '{old_stem}' to '{new_stem}'")
158
+
124
159
  try:
125
160
  with open(file_path, "r", encoding="utf-8") as f:
126
161
  content = f.read()
@@ -129,39 +164,55 @@ def update_references_in_file(file_path: str, old_ref: str, new_ref: str) -> boo
129
164
 
130
165
  # Update different types of references
131
166
  # 1. Toctree entries
132
- content = re.sub(
167
+ new_content = re.sub(
133
168
  rf"^\s*{re.escape(old_stem)}\s*$",
134
169
  f" {new_stem}",
135
170
  content,
136
171
  flags=re.MULTILINE,
137
172
  )
173
+ if new_content != content and verbose:
174
+ print(f" Updated toctree entries in {file_path}")
175
+ content = new_content
138
176
 
139
177
  # 2. :doc: references
140
- content = re.sub(
178
+ new_content = re.sub(
141
179
  rf":doc:`{re.escape(old_stem)}`", f":doc:`{new_stem}`", content
142
180
  )
181
+ if new_content != content and verbose:
182
+ print(f" Updated :doc: references in {file_path}")
183
+ content = new_content
143
184
 
144
185
  # 3. Include directives
145
186
  for directive in ["include", "literalinclude"]:
146
- content = re.sub(
187
+ new_content = re.sub(
147
188
  rf"^\s*\.\.\s+{directive}::\s+{re.escape(old_ref)}",
148
189
  f".. {directive}:: {new_ref}",
149
190
  content,
150
191
  flags=re.MULTILINE,
151
192
  )
193
+ if new_content != content and verbose:
194
+ print(f" Updated {directive} directive in {file_path}")
195
+ content = new_content
152
196
 
153
197
  # 4. Internal links
154
- content = re.sub(
198
+ new_content = re.sub(
155
199
  rf"`([^<>`]+)\s+<{re.escape(old_ref)}>`__?", rf"`\1 <{new_ref}>`_", content
156
200
  )
201
+ if new_content != content and verbose:
202
+ print(f" Updated internal links in {file_path}")
203
+ content = new_content
157
204
 
158
205
  # Write back if changes were made
159
206
  if content != original_content:
160
207
  with open(file_path, "w", encoding="utf-8") as f:
161
208
  f.write(content)
209
+ if verbose:
210
+ print(f" Successfully updated references in {file_path}")
162
211
  return True
163
-
164
- return False
212
+ else:
213
+ if verbose:
214
+ print(f" No changes needed in {file_path}")
215
+ return False
165
216
 
166
217
  except Exception as e:
167
218
  print(f"Error updating references in {file_path}: {e}")
@@ -174,11 +225,17 @@ def move_rst_file(
174
225
  update_references: bool = True,
175
226
  dry_run: bool = False,
176
227
  context_path: Optional[str] = None,
228
+ verbose: bool = False,
177
229
  ) -> None:
178
230
  """Move an RST file and optionally update all references to it."""
179
231
  source_path = Path(source).resolve()
180
232
  dest_path = Path(destination).resolve()
181
233
 
234
+ if verbose:
235
+ print(f"Preparing to move file from {source} to {destination}")
236
+ print(f"Source full path: {source_path}")
237
+ print(f"Destination full path: {dest_path}")
238
+
182
239
  if not source_path.exists():
183
240
  raise FileNotFoundError(f"Source file not found: {source}")
184
241
 
@@ -187,8 +244,15 @@ def move_rst_file(
187
244
 
188
245
  # If destination is a directory, use the same filename
189
246
  if dest_path.is_dir():
247
+ if verbose:
248
+ print(
249
+ f"Destination is a directory, using original filename:"
250
+ f" {source_path.name}"
251
+ )
190
252
  dest_path = dest_path / source_path.name
191
253
  elif not dest_path.suffix:
254
+ if verbose:
255
+ print(f"Adding .rst extension to destination: {dest_path}")
192
256
  dest_path = dest_path.with_suffix(".rst")
193
257
 
194
258
  # Get the relative paths for updating references
@@ -196,28 +260,46 @@ def move_rst_file(
196
260
  try:
197
261
  source_rel = source_path.relative_to(Path.cwd())
198
262
  dest_rel = dest_path.relative_to(Path.cwd())
263
+ if verbose:
264
+ print(f"Using relative paths from current directory: {Path.cwd()}")
199
265
  except ValueError:
200
266
  # Fall back to absolute paths if no common root
201
267
  source_rel = source_path
202
268
  dest_rel = dest_path
269
+ if verbose:
270
+ print("No common root found, using absolute paths")
203
271
 
204
272
  print(f"Moving: {source_rel} -> {dest_rel}")
205
273
 
206
274
  if not dry_run:
207
275
  # Create destination directory if it doesn't exist
208
- dest_path.parent.mkdir(parents=True, exist_ok=True)
276
+ if not dest_path.parent.exists():
277
+ if verbose:
278
+ print(f"Creating parent directory: {dest_path.parent}")
279
+ dest_path.parent.mkdir(parents=True, exist_ok=True)
209
280
 
210
281
  # Move the file
282
+ if verbose:
283
+ print("Executing file move operation")
211
284
  shutil.move(str(source_path), str(dest_path))
285
+ if verbose:
286
+ print("File moved successfully")
212
287
 
213
288
  if update_references:
289
+ if verbose:
290
+ print("Updating references to the moved file")
291
+
214
292
  # Find all .rst files that might reference this file
215
293
  root_dir = Path.cwd() # Or use a smarter root detection
294
+ if verbose:
295
+ print(f"Searching for all RST files from root directory: {root_dir}")
216
296
  all_files = find_all_rst_files(str(root_dir))
297
+ if verbose:
298
+ print(f"Found {len(all_files)} RST files to check")
217
299
 
218
300
  # Find files that reference the moved file, using context if provided
219
301
  referencing_files = find_files_referencing(
220
- str(source_rel), all_files, context_path=context_path
302
+ str(source_rel), all_files, context_path=context_path, verbose=verbose
221
303
  )
222
304
 
223
305
  if referencing_files:
@@ -230,9 +312,15 @@ def move_rst_file(
230
312
  source_stem = source_path.stem
231
313
  dest_stem = dest_path.stem
232
314
 
315
+ if verbose:
316
+ print(
317
+ f"Updating references from {source_stem} to"
318
+ f" {dest_stem} in {ref_file}"
319
+ )
320
+
233
321
  # Update the references
234
322
  updated = update_references_in_file(
235
- ref_file, source_stem, dest_stem
323
+ ref_file, source_stem, dest_stem, verbose=verbose
236
324
  )
237
325
 
238
326
  if updated:
@@ -253,6 +341,17 @@ def execute(args):
253
341
  # Get global options
254
342
  context_path = getattr(args, "context", None)
255
343
  dry_run = getattr(args, "dry_run", False)
344
+ verbose = getattr(args, "verbose", False)
345
+
346
+ if verbose:
347
+ print("Starting sphinx-cmd mv operation")
348
+ print(f"Source: {args.source}")
349
+ print(f"Destination: {args.destination}")
350
+ print(
351
+ f"Options: dry-run={dry_run},"
352
+ f" update-references={update_references},"
353
+ f" context={context_path}"
354
+ )
256
355
 
257
356
  # Perform the move
258
357
  move_rst_file(
@@ -261,6 +360,7 @@ def execute(args):
261
360
  update_references=update_references,
262
361
  dry_run=dry_run,
263
362
  context_path=context_path,
363
+ verbose=verbose,
264
364
  )
265
365
 
266
366
  if not dry_run:
@@ -268,6 +368,9 @@ def execute(args):
268
368
  else:
269
369
  print("\n[Dry run complete - no files were actually moved]")
270
370
 
371
+ if verbose:
372
+ print("Operation completed successfully")
373
+
271
374
  except Exception as e:
272
375
  print(f"Error: {e}")
273
376
  raise
@@ -21,7 +21,9 @@ def find_rst_files(path):
21
21
  return rst_files
22
22
 
23
23
 
24
- def extract_assets(file_path, visited=None, cli_directives=None, context_path=None):
24
+ def extract_assets(
25
+ file_path, visited=None, cli_directives=None, context_path=None, verbose=False
26
+ ):
25
27
  """Extract asset references from an .rst file, recursively parsing includes."""
26
28
  if visited is None:
27
29
  visited = set()
@@ -32,11 +34,16 @@ def extract_assets(file_path, visited=None, cli_directives=None, context_path=No
32
34
  return {}
33
35
  visited.add(abs_path)
34
36
 
37
+ if verbose:
38
+ print(f"Processing file: {file_path}")
39
+
35
40
  asset_directives = {}
36
41
  directive_patterns = get_directive_patterns(cli_directives, context_path)
37
42
 
38
43
  # If file doesn't exist, skip it
39
44
  if not os.path.exists(file_path):
45
+ if verbose:
46
+ print(f"Skipping non-existent file: {file_path}")
40
47
  return asset_directives
41
48
 
42
49
  try:
@@ -49,13 +56,19 @@ def extract_assets(file_path, visited=None, cli_directives=None, context_path=No
49
56
  os.path.join(os.path.dirname(file_path), asset_path)
50
57
  )
51
58
 
59
+ if verbose:
60
+ print(f"Found {directive}: {asset_path}")
61
+
52
62
  if directive == "include":
63
+ if verbose:
64
+ print(f"Parsing include: {asset_full_path}")
53
65
  # Recursively extract assets from included files
54
66
  included_assets = extract_assets(
55
67
  asset_full_path,
56
68
  visited.copy(),
57
69
  cli_directives,
58
70
  context_path,
71
+ verbose,
59
72
  )
60
73
  asset_directives.update(included_assets)
61
74
 
@@ -66,25 +79,35 @@ def extract_assets(file_path, visited=None, cli_directives=None, context_path=No
66
79
  return asset_directives
67
80
 
68
81
 
69
- def build_asset_index(rst_files, cli_directives=None, context_path=None):
82
+ def build_asset_index(rst_files, cli_directives=None, context_path=None, verbose=False):
70
83
  """Build an index of assets and which files reference them."""
71
84
  asset_to_files = defaultdict(set)
72
85
  file_to_assets = {}
73
86
  asset_directive_map = {}
74
87
 
88
+ if verbose:
89
+ print(f"Building asset index for {len(rst_files)} RST files...")
90
+
75
91
  for rst in rst_files:
76
92
  asset_directives = extract_assets(
77
- rst, cli_directives=cli_directives, context_path=context_path
93
+ rst,
94
+ cli_directives=cli_directives,
95
+ context_path=context_path,
96
+ verbose=verbose,
78
97
  )
79
98
  file_to_assets[rst] = set(asset_directives.keys())
80
99
  for asset, directive in asset_directives.items():
81
100
  asset_to_files[asset].add(rst)
82
101
  asset_directive_map[asset] = directive
102
+
103
+ if verbose:
104
+ print(f"Found {len(asset_to_files)} unique assets across all files")
105
+
83
106
  return asset_to_files, file_to_assets, asset_directive_map
84
107
 
85
108
 
86
109
  def get_transitive_includes(
87
- file_path, visited=None, cli_directives=None, context_path=None
110
+ file_path, visited=None, cli_directives=None, context_path=None, verbose=False
88
111
  ):
89
112
  """Get all files included transitively from a file."""
90
113
  if visited is None:
@@ -96,9 +119,14 @@ def get_transitive_includes(
96
119
  return set()
97
120
  visited.add(abs_path)
98
121
 
122
+ if verbose:
123
+ print(f"Checking for includes in: {file_path}")
124
+
99
125
  includes = set()
100
126
 
101
127
  if not os.path.exists(file_path):
128
+ if verbose:
129
+ print(f"Skipping non-existent file: {file_path}")
102
130
  return includes
103
131
 
104
132
  directive_patterns = get_directive_patterns(cli_directives, context_path)
@@ -115,6 +143,9 @@ def get_transitive_includes(
115
143
  os.path.join(os.path.dirname(file_path), include_path)
116
144
  )
117
145
  includes.add(include_full_path)
146
+ if verbose:
147
+ print(f"Found include: {include_path}")
148
+
118
149
  # Recursively get includes from the included file
119
150
  includes.update(
120
151
  get_transitive_includes(
@@ -122,6 +153,7 @@ def get_transitive_includes(
122
153
  visited.copy(),
123
154
  cli_directives,
124
155
  context_path,
156
+ verbose,
125
157
  )
126
158
  )
127
159
  except Exception as e:
@@ -136,6 +168,7 @@ def delete_unused_assets_and_pages(
136
168
  asset_directive_map,
137
169
  dry_run=False,
138
170
  context_path=None,
171
+ verbose=False,
139
172
  ):
140
173
  """
141
174
  Delete files and their unique assets if not used elsewhere.
@@ -151,15 +184,33 @@ def delete_unused_assets_and_pages(
151
184
  # Track which files have been processed to avoid duplicates
152
185
  processed_files = set()
153
186
 
187
+ if verbose:
188
+ print("Analyzing files and assets for removal...")
189
+
154
190
  for rst_file, assets in file_to_assets.items():
155
191
  # Skip if already processed (can happen with transitive includes)
156
192
  if rst_file in processed_files:
193
+ if verbose:
194
+ print(f"Skipping already processed file: {rst_file}")
157
195
  continue
158
196
 
159
197
  unused_assets = [a for a in assets if len(asset_to_files[a]) == 1]
198
+
199
+ if verbose:
200
+ print(
201
+ f"File: {rst_file} has {len(assets)} assets, {len(unused_assets)}"
202
+ " are unique"
203
+ )
204
+
160
205
  if len(unused_assets) == len(assets): # All assets are unique to this file
206
+ if verbose:
207
+ print(f"File {rst_file} has no shared assets, processing for removal")
208
+
161
209
  # Get all files transitively included by this file
162
- included_files = get_transitive_includes(rst_file)
210
+ included_files = get_transitive_includes(rst_file, verbose=verbose)
211
+
212
+ if verbose and included_files:
213
+ print(f"Found {len(included_files)} transitively included files")
163
214
 
164
215
  # Process the main file and all its includes
165
216
  for file_to_process in [rst_file] + list(included_files):
@@ -167,6 +218,8 @@ def delete_unused_assets_and_pages(
167
218
  file_to_process in processed_files
168
219
  or file_to_process not in file_to_assets
169
220
  ):
221
+ if verbose and file_to_process in processed_files:
222
+ print(f"Skipping already processed include: {file_to_process}")
170
223
  continue
171
224
 
172
225
  processed_files.add(file_to_process)
@@ -193,6 +246,8 @@ def delete_unused_assets_and_pages(
193
246
  f"[dry-run] Skipping {directive} (outside context):"
194
247
  f" {asset}"
195
248
  )
249
+ elif verbose:
250
+ print(f"Skipping asset (outside context): {asset}")
196
251
  continue
197
252
 
198
253
  if dry_run:
@@ -204,6 +259,8 @@ def delete_unused_assets_and_pages(
204
259
  )
205
260
  would_delete_something = True
206
261
  else:
262
+ if verbose:
263
+ print(f"Removing asset: {asset}")
207
264
  affected_dirs.add(os.path.dirname(asset))
208
265
  os.remove(asset)
209
266
  deleted_assets.append(asset)
@@ -224,6 +281,11 @@ def delete_unused_assets_and_pages(
224
281
  f"[dry-run] Skipping included file (outside context):"
225
282
  f" {file_to_process}"
226
283
  )
284
+ elif verbose:
285
+ print(
286
+ "Skipping included file (outside context):"
287
+ f" {file_to_process}"
288
+ )
227
289
  continue
228
290
 
229
291
  if dry_run:
@@ -232,6 +294,8 @@ def delete_unused_assets_and_pages(
232
294
  )
233
295
  would_delete_something = True
234
296
  else:
297
+ if verbose:
298
+ print(f"Removing included file: {file_to_process}")
235
299
  affected_dirs.add(os.path.dirname(file_to_process))
236
300
  os.remove(file_to_process)
237
301
  deleted_pages.append(file_to_process)
@@ -249,12 +313,16 @@ def delete_unused_assets_and_pages(
249
313
  if not is_in_context:
250
314
  if dry_run:
251
315
  print(f"[dry-run] Skipping page (outside context): {rst_file}")
316
+ elif verbose:
317
+ print(f"Skipping page (outside context): {rst_file}")
252
318
  continue
253
319
 
254
320
  if dry_run:
255
321
  print(f"[dry-run] Would delete page: {rst_file}")
256
322
  would_delete_something = True
257
323
  else:
324
+ if verbose:
325
+ print(f"Removing page: {rst_file}")
258
326
  affected_dirs.add(os.path.dirname(rst_file))
259
327
  os.remove(rst_file)
260
328
  deleted_pages.append(rst_file)
@@ -262,10 +330,13 @@ def delete_unused_assets_and_pages(
262
330
  return deleted_pages, deleted_assets, affected_dirs, would_delete_something
263
331
 
264
332
 
265
- def remove_empty_dirs(dirs, original_path, dry_run=False):
333
+ def remove_empty_dirs(dirs, original_path, dry_run=False, verbose=False):
266
334
  """Remove empty directories, bottom-up."""
267
335
  deleted_dirs = []
268
336
 
337
+ if verbose:
338
+ print(f"Checking for empty directories in {len(dirs)} affected paths...")
339
+
269
340
  # Add parent directories to the affected dirs set
270
341
  all_dirs = set(dirs)
271
342
  for dir_path in dirs:
@@ -278,9 +349,14 @@ def remove_empty_dirs(dirs, original_path, dry_run=False):
278
349
  # Sort by path depth (deepest first)
279
350
  sorted_dirs = sorted(all_dirs, key=lambda d: d.count(os.sep), reverse=True)
280
351
 
352
+ if verbose:
353
+ print(f"Scanning {len(sorted_dirs)} directories for emptiness...")
354
+
281
355
  # Process directories from deepest to shallowest
282
356
  for dir_path in sorted_dirs:
283
357
  if not os.path.exists(dir_path) or not os.path.isdir(dir_path):
358
+ if verbose:
359
+ print(f"Skipping non-existent or non-directory path: {dir_path}")
284
360
  continue
285
361
 
286
362
  # Check if directory is empty
@@ -288,8 +364,12 @@ def remove_empty_dirs(dirs, original_path, dry_run=False):
288
364
  if dry_run:
289
365
  print(f"[dry-run] Would delete empty directory: {dir_path}")
290
366
  else:
367
+ if verbose:
368
+ print(f"Removing empty directory: {dir_path}")
291
369
  os.rmdir(dir_path)
292
370
  deleted_dirs.append(dir_path)
371
+ elif verbose:
372
+ print(f"Directory not empty, skipping: {dir_path}")
293
373
 
294
374
  # Check if the original path (if it's a directory) is now empty and should
295
375
  # be removed
@@ -297,6 +377,8 @@ def remove_empty_dirs(dirs, original_path, dry_run=False):
297
377
  if dry_run:
298
378
  print(f"[dry-run] Would delete empty directory: {original_path}")
299
379
  else:
380
+ if verbose:
381
+ print(f"Removing empty original directory: {original_path}")
300
382
  os.rmdir(original_path)
301
383
  deleted_dirs.append(original_path)
302
384
 
@@ -306,12 +388,21 @@ def remove_empty_dirs(dirs, original_path, dry_run=False):
306
388
  def execute(args):
307
389
  """Execute the rm command."""
308
390
  original_path = os.path.abspath(args.path)
309
- rst_files = find_rst_files(args.path)
310
391
 
311
392
  # Get global options
312
393
  context_path = getattr(args, "context", None)
313
394
  dry_run = getattr(args, "dry_run", False)
314
395
  directives = getattr(args, "directives", None)
396
+ verbose = getattr(args, "verbose", False)
397
+
398
+ if verbose:
399
+ print(f"Starting sphinx-cmd rm operation on path: {original_path}")
400
+ print(f"Options: dry-run={dry_run}, directives={directives}")
401
+
402
+ rst_files = find_rst_files(args.path)
403
+
404
+ if verbose:
405
+ print(f"Found {len(rst_files)} RST files to analyze")
315
406
 
316
407
  # Display context information
317
408
  if context_path:
@@ -322,8 +413,9 @@ def execute(args):
322
413
  print("Context path not set - all unused files will be removed")
323
414
 
324
415
  asset_to_files, file_to_assets, asset_directive_map = build_asset_index(
325
- rst_files, cli_directives=directives, context_path=context_path
416
+ rst_files, cli_directives=directives, context_path=context_path, verbose=verbose
326
417
  )
418
+
327
419
  deleted_pages, deleted_assets, affected_dirs, would_delete_something = (
328
420
  delete_unused_assets_and_pages(
329
421
  asset_to_files,
@@ -331,12 +423,13 @@ def execute(args):
331
423
  asset_directive_map,
332
424
  dry_run,
333
425
  context_path,
426
+ verbose,
334
427
  )
335
428
  )
336
429
 
337
430
  deleted_dirs = []
338
431
  if affected_dirs:
339
- deleted_dirs = remove_empty_dirs(affected_dirs, original_path, dry_run)
432
+ deleted_dirs = remove_empty_dirs(affected_dirs, original_path, dry_run, verbose)
340
433
 
341
434
  if dry_run:
342
435
  # In dry-run mode, show a summary of what would be deleted
@@ -357,3 +450,6 @@ def execute(args):
357
450
  print(f"\nDeleted {len(deleted_dirs)} empty directory/directories:")
358
451
  for d in deleted_dirs:
359
452
  print(f" - {d}")
453
+
454
+ if verbose:
455
+ print("Operation completed successfully")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sphinx-cmd
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Command-line tools for Sphinx documentation management
5
5
  Author-email: Jared Dillard <jared.dillard@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/jdillard/sphinx-cmd
@@ -58,6 +58,9 @@ sphinx-cmd --dry-run COMMAND
58
58
 
59
59
  # Process additional directives beyond defaults
60
60
  sphinx-cmd --directives drawio-figure,drawio-image COMMAND
61
+
62
+ # Enable verbose output with detailed processing information
63
+ sphinx-cmd --verbose COMMAND
61
64
  ```
62
65
 
63
66
  By default, `sphinx-cmd` will automatically detect the context of your documentation project by finding the nearest `conf.py` file in the directory tree.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes