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