sphinx-cmd 0.3.1__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.3.1/sphinx_cmd.egg-info → sphinx_cmd-0.4.1}/PKG-INFO +34 -14
  2. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/README.md +33 -13
  3. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd/__init__.py +1 -1
  4. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd/cli.py +32 -24
  5. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd/commands/mv.py +135 -18
  6. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd/commands/rm.py +208 -19
  7. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd/config.py +72 -4
  8. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1/sphinx_cmd.egg-info}/PKG-INFO +34 -14
  9. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/tests/test_cli.py +18 -0
  10. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/tests/test_config.py +83 -1
  11. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/tests/test_custom_directives.py +1 -0
  12. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/tests/test_integration.py +2 -2
  13. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/tests/test_mv.py +3 -1
  14. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/tests/test_rm.py +122 -15
  15. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/LICENSE +0 -0
  16. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/MANIFEST.in +0 -0
  17. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/pyproject.toml +0 -0
  18. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/setup.cfg +0 -0
  19. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd/commands/__init__.py +0 -0
  20. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd/py.typed +0 -0
  21. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/SOURCES.txt +0 -0
  22. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/dependency_links.txt +0 -0
  23. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/entry_points.txt +0 -0
  24. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/requires.txt +0 -0
  25. {sphinx_cmd-0.3.1 → sphinx_cmd-0.4.1}/sphinx_cmd.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sphinx-cmd
3
- Version: 0.3.1
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
@@ -32,6 +32,9 @@ Dynamic: license-file
32
32
 
33
33
  A collection of command-line tools for managing Sphinx documentation.
34
34
 
35
+ [![PyPI version](https://img.shields.io/pypi/v/sphinx-cmd.svg)](https://pypi.python.org/pypi/sphinx-cmd)
36
+ [![Downloads](https://static.pepy.tech/badge/sphinx-cmd/month)](https://pepy.tech/project/sphinx-cmd)
37
+
35
38
  ## Installation
36
39
 
37
40
  ```bash
@@ -42,6 +45,26 @@ pip install sphinx-cmd
42
45
 
43
46
  The `sphinx-cmd` tool provides subcommands for different Sphinx documentation management tasks.
44
47
 
48
+ ### Global Options
49
+
50
+ Options that apply to all commands:
51
+
52
+ ```bash
53
+ # Specify a context path (directory containing conf.py)
54
+ sphinx-cmd --context /path/to/docs COMMAND
55
+
56
+ # Dry run to preview changes without executing them
57
+ sphinx-cmd --dry-run COMMAND
58
+
59
+ # Process additional directives beyond defaults
60
+ sphinx-cmd --directives drawio-figure,drawio-image COMMAND
61
+
62
+ # Enable verbose output with detailed processing information
63
+ sphinx-cmd --verbose COMMAND
64
+ ```
65
+
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.
67
+
45
68
  ### `sphinx-cmd rm`
46
69
 
47
70
  Delete unused .rst files and their unique assets (images, includes, etc) if not used elsewhere.
@@ -50,16 +73,14 @@ Delete unused .rst files and their unique assets (images, includes, etc) if not
50
73
  # Remove files and assets
51
74
  sphinx-cmd rm path/to/docs
52
75
 
53
- # Dry run to preview deletions
54
- sphinx-cmd rm path/to/docs --dry-run
55
-
56
- # Process additional directives beyond defaults
57
- sphinx-cmd rm path/to/docs --directives drawio-figure,drawio-image
76
+ # Using global options
77
+ sphinx-cmd --dry-run --directives drawio-figure,drawio-image rm path/to/docs
58
78
  ```
59
79
 
60
80
  #### Features
61
81
 
62
82
  - Configure custom directives to be processed
83
+ - Only deletes unused unique assets in the provided context path
63
84
 
64
85
  ### `sphinx-cmd mv`
65
86
 
@@ -72,14 +93,11 @@ sphinx-cmd mv old-file.rst new-file.rst
72
93
  # Move to a different directory
73
94
  sphinx-cmd mv chapter1.rst topics/chapter1.rst
74
95
 
75
- # Preview the move without making changes
76
- sphinx-cmd mv old-file.rst new-file.rst --dry-run
77
-
78
96
  # Move without updating references
79
97
  sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
80
98
 
81
- # Process additional directives beyond defaults
82
- sphinx-cmd mv old-file.rst new-file.rst --directives drawio-figure,drawio-image
99
+ # Using global options
100
+ sphinx-cmd --dry-run --directives drawio-figure mv old-file.rst new-file.rst
83
101
  ```
84
102
 
85
103
  #### Features
@@ -97,10 +115,10 @@ You can add custom directives to be processed in two ways:
97
115
 
98
116
  ### 1. Command Line
99
117
 
100
- Use the `--directives` option with any command to add custom directives for a single run:
118
+ Use the `--directives` global option with any command to add custom directives for a single run:
101
119
 
102
120
  ```bash
103
- sphinx-cmd rm path/to/docs --directives drawio-figure,drawio-image
121
+ sphinx-cmd --directives drawio-figure,drawio-image rm path/to/docs
104
122
  ```
105
123
 
106
124
  ### 2. Configuration File
@@ -132,6 +150,7 @@ pytest
132
150
 
133
151
  # Run linters
134
152
  black sphinx_cmd tests
153
+ isort sphinx_cmd tests
135
154
  flake8 sphinx_cmd tests
136
155
  mypy sphinx_cmd
137
156
 
@@ -141,7 +160,7 @@ sphinx-cmd rm --help
141
160
  sphinx-cmd mv --help
142
161
  ```
143
162
 
144
- ## Adding New Commands
163
+ ### Adding New Commands
145
164
 
146
165
  The architecture is designed to make adding new commands easy:
147
166
 
@@ -149,6 +168,7 @@ The architecture is designed to make adding new commands easy:
149
168
  2. Implement an `execute(args)` function in your new file
150
169
  3. Import the command in `sphinx_cmd/cli.py`
151
170
  4. Add a new subparser for your command in `create_parser()`
171
+ 5. Create new tests (e.g., `tests/test_new_command.py`)
152
172
 
153
173
  ## License
154
174
 
@@ -2,6 +2,9 @@
2
2
 
3
3
  A collection of command-line tools for managing Sphinx documentation.
4
4
 
5
+ [![PyPI version](https://img.shields.io/pypi/v/sphinx-cmd.svg)](https://pypi.python.org/pypi/sphinx-cmd)
6
+ [![Downloads](https://static.pepy.tech/badge/sphinx-cmd/month)](https://pepy.tech/project/sphinx-cmd)
7
+
5
8
  ## Installation
6
9
 
7
10
  ```bash
@@ -12,6 +15,26 @@ pip install sphinx-cmd
12
15
 
13
16
  The `sphinx-cmd` tool provides subcommands for different Sphinx documentation management tasks.
14
17
 
18
+ ### Global Options
19
+
20
+ Options that apply to all commands:
21
+
22
+ ```bash
23
+ # Specify a context path (directory containing conf.py)
24
+ sphinx-cmd --context /path/to/docs COMMAND
25
+
26
+ # Dry run to preview changes without executing them
27
+ sphinx-cmd --dry-run COMMAND
28
+
29
+ # Process additional directives beyond defaults
30
+ sphinx-cmd --directives drawio-figure,drawio-image COMMAND
31
+
32
+ # Enable verbose output with detailed processing information
33
+ sphinx-cmd --verbose COMMAND
34
+ ```
35
+
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.
37
+
15
38
  ### `sphinx-cmd rm`
16
39
 
17
40
  Delete unused .rst files and their unique assets (images, includes, etc) if not used elsewhere.
@@ -20,16 +43,14 @@ Delete unused .rst files and their unique assets (images, includes, etc) if not
20
43
  # Remove files and assets
21
44
  sphinx-cmd rm path/to/docs
22
45
 
23
- # Dry run to preview deletions
24
- sphinx-cmd rm path/to/docs --dry-run
25
-
26
- # Process additional directives beyond defaults
27
- sphinx-cmd rm path/to/docs --directives drawio-figure,drawio-image
46
+ # Using global options
47
+ sphinx-cmd --dry-run --directives drawio-figure,drawio-image rm path/to/docs
28
48
  ```
29
49
 
30
50
  #### Features
31
51
 
32
52
  - Configure custom directives to be processed
53
+ - Only deletes unused unique assets in the provided context path
33
54
 
34
55
  ### `sphinx-cmd mv`
35
56
 
@@ -42,14 +63,11 @@ sphinx-cmd mv old-file.rst new-file.rst
42
63
  # Move to a different directory
43
64
  sphinx-cmd mv chapter1.rst topics/chapter1.rst
44
65
 
45
- # Preview the move without making changes
46
- sphinx-cmd mv old-file.rst new-file.rst --dry-run
47
-
48
66
  # Move without updating references
49
67
  sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
50
68
 
51
- # Process additional directives beyond defaults
52
- sphinx-cmd mv old-file.rst new-file.rst --directives drawio-figure,drawio-image
69
+ # Using global options
70
+ sphinx-cmd --dry-run --directives drawio-figure mv old-file.rst new-file.rst
53
71
  ```
54
72
 
55
73
  #### Features
@@ -67,10 +85,10 @@ You can add custom directives to be processed in two ways:
67
85
 
68
86
  ### 1. Command Line
69
87
 
70
- Use the `--directives` option with any command to add custom directives for a single run:
88
+ Use the `--directives` global option with any command to add custom directives for a single run:
71
89
 
72
90
  ```bash
73
- sphinx-cmd rm path/to/docs --directives drawio-figure,drawio-image
91
+ sphinx-cmd --directives drawio-figure,drawio-image rm path/to/docs
74
92
  ```
75
93
 
76
94
  ### 2. Configuration File
@@ -102,6 +120,7 @@ pytest
102
120
 
103
121
  # Run linters
104
122
  black sphinx_cmd tests
123
+ isort sphinx_cmd tests
105
124
  flake8 sphinx_cmd tests
106
125
  mypy sphinx_cmd
107
126
 
@@ -111,7 +130,7 @@ sphinx-cmd rm --help
111
130
  sphinx-cmd mv --help
112
131
  ```
113
132
 
114
- ## Adding New Commands
133
+ ### Adding New Commands
115
134
 
116
135
  The architecture is designed to make adding new commands easy:
117
136
 
@@ -119,6 +138,7 @@ The architecture is designed to make adding new commands easy:
119
138
  2. Implement an `execute(args)` function in your new file
120
139
  3. Import the command in `sphinx_cmd/cli.py`
121
140
  4. Add a new subparser for your command in `create_parser()`
141
+ 5. Create new tests (e.g., `tests/test_new_command.py`)
122
142
 
123
143
  ## License
124
144
 
@@ -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.3.1"
4
+ __version__ = "0.4.1"
@@ -4,6 +4,7 @@ Main CLI entry point for sphinx-cmd with subcommands.
4
4
  """
5
5
 
6
6
  import argparse
7
+ import os
7
8
  import sys
8
9
 
9
10
  from sphinx_cmd import __version__
@@ -21,6 +22,32 @@ def create_parser():
21
22
  "--version", action="version", version=f"%(prog)s {__version__}"
22
23
  )
23
24
 
25
+ # Add global options
26
+ parser.add_argument(
27
+ "--context",
28
+ "-c",
29
+ help="Path to Sphinx documentation context"
30
+ "(will auto-detect nearest conf.py by default)",
31
+ )
32
+ parser.add_argument(
33
+ "-n",
34
+ "--dry-run",
35
+ action="store_true",
36
+ help="Preview operations without making any changes",
37
+ )
38
+ parser.add_argument(
39
+ "--directives",
40
+ type=lambda s: [x.strip() for x in s.split(",")],
41
+ help="Additional directives to process as comma-separated list"
42
+ " (e.g. 'drawio-figure,drawio-image')",
43
+ )
44
+ parser.add_argument(
45
+ "-v",
46
+ "--verbose",
47
+ action="store_true",
48
+ help="Enable verbose output with detailed processing information",
49
+ )
50
+
24
51
  # Create subparsers for subcommands
25
52
  subparsers = parser.add_subparsers(
26
53
  dest="command", help="Available commands", metavar="COMMAND"
@@ -33,18 +60,6 @@ def create_parser():
33
60
  rm_parser.add_argument(
34
61
  "path", help="Path to a single .rst file or a directory of .rst files"
35
62
  )
36
- rm_parser.add_argument(
37
- "-n",
38
- "--dry-run",
39
- action="store_true",
40
- help="Preview deletions without removing files",
41
- )
42
- rm_parser.add_argument(
43
- "--directives",
44
- type=lambda s: [x.strip() for x in s.split(",")],
45
- help="Additional directives to process as comma-separated list"
46
- " (e.g. 'drawio-figure,drawio-image')",
47
- )
48
63
  rm_parser.set_defaults(command_name="rm")
49
64
 
50
65
  # Add 'mv' subcommand
@@ -53,23 +68,11 @@ def create_parser():
53
68
  )
54
69
  mv_parser.add_argument("source", help="Source file to move")
55
70
  mv_parser.add_argument("destination", help="Destination file or directory")
56
- mv_parser.add_argument(
57
- "-n",
58
- "--dry-run",
59
- action="store_true",
60
- help="Preview move without actually moving files",
61
- )
62
71
  mv_parser.add_argument(
63
72
  "--no-update-refs",
64
73
  action="store_true",
65
74
  help="Do not update references to the moved file",
66
75
  )
67
- mv_parser.add_argument(
68
- "--directives",
69
- type=lambda s: [x.strip() for x in s.split(",")],
70
- help="Additional directives to process as comma-separated list"
71
- " (e.g. 'drawio-figure,drawio-image')",
72
- )
73
76
  mv_parser.set_defaults(command_name="mv")
74
77
 
75
78
  return parser
@@ -85,6 +88,11 @@ def main():
85
88
  parser.print_help()
86
89
  sys.exit(1)
87
90
 
91
+ # If context path is provided, check that it exists
92
+ if args.context and not os.path.exists(args.context):
93
+ print(f"Error: Context path does not exist: {args.context}", file=sys.stderr)
94
+ sys.exit(1)
95
+
88
96
  # Import and execute the appropriate command
89
97
  try:
90
98
  if args.command_name == "rm":
@@ -7,7 +7,7 @@ import re
7
7
  import shutil
8
8
  from collections import defaultdict
9
9
  from pathlib import Path
10
- from typing import Dict, List, Tuple
10
+ from typing import Dict, List, Optional, Tuple
11
11
 
12
12
  # Regex patterns for different types of references in reStructuredText
13
13
  REFERENCE_PATTERNS = {
@@ -41,16 +41,24 @@ def find_all_rst_files(root_path: str) -> List[str]:
41
41
  return rst_files
42
42
 
43
43
 
44
- def extract_references(file_path: str) -> Dict[str, List[str]]:
44
+ def extract_references(
45
+ file_path: str, context_path: Optional[str] = None, verbose: bool = False
46
+ ) -> Dict[str, List[str]]:
45
47
  """Extract all file references from an .rst file."""
46
48
  references = defaultdict(list)
47
49
 
50
+ if verbose:
51
+ print(f"Extracting references from: {file_path}")
52
+
48
53
  with open(file_path, "r", encoding="utf-8") as f:
49
54
  content = f.read()
50
55
 
51
56
  # Find toctree entries
52
57
  toctree_matches = TOCTREE_PATTERN.findall(content)
53
58
  for toctree_content in toctree_matches:
59
+ if verbose:
60
+ print(f"Found toctree directive in {file_path}")
61
+
54
62
  # Extract file references from toctree
55
63
  lines = toctree_content.split("\n")
56
64
  for line in lines:
@@ -60,6 +68,8 @@ def extract_references(file_path: str) -> Dict[str, List[str]]:
60
68
  ref_file = line.split()[0] if line.split() else ""
61
69
  if ref_file:
62
70
  references["toctree"].append(ref_file)
71
+ if verbose:
72
+ print(f"Found toctree entry: {ref_file}")
63
73
 
64
74
  # Find other types of references
65
75
  for ref_type, pattern in REFERENCE_PATTERNS.items():
@@ -73,24 +83,41 @@ def extract_references(file_path: str) -> Dict[str, List[str]]:
73
83
  else:
74
84
  ref_path = match
75
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}")
76
91
 
77
92
  return dict(references)
78
93
 
79
94
 
80
95
  def find_files_referencing(
81
- target_file: str, all_files: List[str]
96
+ target_file: str,
97
+ all_files: List[str],
98
+ context_path: Optional[str] = None,
99
+ verbose: bool = False,
82
100
  ) -> List[Tuple[str, str]]:
83
101
  """Find all files that reference the target file."""
84
102
  referencing_files = []
85
103
  target_path = Path(target_file)
86
104
  target_stem = target_path.stem # filename without extension
87
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
+
88
110
  for file_path in all_files:
89
111
  if file_path == target_file:
112
+ if verbose:
113
+ print(f"Skipping the target file itself: {file_path}")
90
114
  continue
91
115
 
92
116
  try:
93
- references = extract_references(file_path)
117
+ # Extract references using context from conf.py if provided
118
+ references = extract_references(
119
+ file_path, context_path=context_path, verbose=verbose
120
+ )
94
121
 
95
122
  for ref_type, ref_list in references.items():
96
123
  for ref in ref_list:
@@ -104,20 +131,31 @@ def find_files_referencing(
104
131
  or str(ref_path.with_suffix(".rst")) == target_file
105
132
  ):
106
133
  referencing_files.append((file_path, ref_type))
134
+ if verbose:
135
+ print(f"Found reference in {file_path} ({ref_type}): {ref}")
107
136
  break
108
137
  except Exception as e:
109
138
  print(f"Warning: Could not analyze {file_path}: {e}")
110
139
 
140
+ if verbose:
141
+ print(f"Found {len(referencing_files)} files referencing {target_file}")
142
+
111
143
  return referencing_files
112
144
 
113
145
 
114
- 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:
115
149
  """Update references to the moved file in a single file."""
116
150
  old_path = Path(old_ref)
117
151
  new_path = Path(new_ref)
118
152
  old_stem = old_path.stem
119
153
  new_stem = new_path.stem
120
154
 
155
+ if verbose:
156
+ print(f"Updating references in {file_path}")
157
+ print(f" Replacing references from '{old_stem}' to '{new_stem}'")
158
+
121
159
  try:
122
160
  with open(file_path, "r", encoding="utf-8") as f:
123
161
  content = f.read()
@@ -126,39 +164,55 @@ def update_references_in_file(file_path: str, old_ref: str, new_ref: str) -> boo
126
164
 
127
165
  # Update different types of references
128
166
  # 1. Toctree entries
129
- content = re.sub(
167
+ new_content = re.sub(
130
168
  rf"^\s*{re.escape(old_stem)}\s*$",
131
169
  f" {new_stem}",
132
170
  content,
133
171
  flags=re.MULTILINE,
134
172
  )
173
+ if new_content != content and verbose:
174
+ print(f" Updated toctree entries in {file_path}")
175
+ content = new_content
135
176
 
136
177
  # 2. :doc: references
137
- content = re.sub(
178
+ new_content = re.sub(
138
179
  rf":doc:`{re.escape(old_stem)}`", f":doc:`{new_stem}`", content
139
180
  )
181
+ if new_content != content and verbose:
182
+ print(f" Updated :doc: references in {file_path}")
183
+ content = new_content
140
184
 
141
185
  # 3. Include directives
142
186
  for directive in ["include", "literalinclude"]:
143
- content = re.sub(
187
+ new_content = re.sub(
144
188
  rf"^\s*\.\.\s+{directive}::\s+{re.escape(old_ref)}",
145
189
  f".. {directive}:: {new_ref}",
146
190
  content,
147
191
  flags=re.MULTILINE,
148
192
  )
193
+ if new_content != content and verbose:
194
+ print(f" Updated {directive} directive in {file_path}")
195
+ content = new_content
149
196
 
150
197
  # 4. Internal links
151
- content = re.sub(
198
+ new_content = re.sub(
152
199
  rf"`([^<>`]+)\s+<{re.escape(old_ref)}>`__?", rf"`\1 <{new_ref}>`_", content
153
200
  )
201
+ if new_content != content and verbose:
202
+ print(f" Updated internal links in {file_path}")
203
+ content = new_content
154
204
 
155
205
  # Write back if changes were made
156
206
  if content != original_content:
157
207
  with open(file_path, "w", encoding="utf-8") as f:
158
208
  f.write(content)
209
+ if verbose:
210
+ print(f" Successfully updated references in {file_path}")
159
211
  return True
160
-
161
- return False
212
+ else:
213
+ if verbose:
214
+ print(f" No changes needed in {file_path}")
215
+ return False
162
216
 
163
217
  except Exception as e:
164
218
  print(f"Error updating references in {file_path}: {e}")
@@ -166,12 +220,22 @@ def update_references_in_file(file_path: str, old_ref: str, new_ref: str) -> boo
166
220
 
167
221
 
168
222
  def move_rst_file(
169
- source: str, destination: str, update_references: bool = True, dry_run: bool = False
223
+ source: str,
224
+ destination: str,
225
+ update_references: bool = True,
226
+ dry_run: bool = False,
227
+ context_path: Optional[str] = None,
228
+ verbose: bool = False,
170
229
  ) -> None:
171
230
  """Move an RST file and optionally update all references to it."""
172
231
  source_path = Path(source).resolve()
173
232
  dest_path = Path(destination).resolve()
174
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
+
175
239
  if not source_path.exists():
176
240
  raise FileNotFoundError(f"Source file not found: {source}")
177
241
 
@@ -180,8 +244,15 @@ def move_rst_file(
180
244
 
181
245
  # If destination is a directory, use the same filename
182
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
+ )
183
252
  dest_path = dest_path / source_path.name
184
253
  elif not dest_path.suffix:
254
+ if verbose:
255
+ print(f"Adding .rst extension to destination: {dest_path}")
185
256
  dest_path = dest_path.with_suffix(".rst")
186
257
 
187
258
  # Get the relative paths for updating references
@@ -189,27 +260,47 @@ def move_rst_file(
189
260
  try:
190
261
  source_rel = source_path.relative_to(Path.cwd())
191
262
  dest_rel = dest_path.relative_to(Path.cwd())
263
+ if verbose:
264
+ print(f"Using relative paths from current directory: {Path.cwd()}")
192
265
  except ValueError:
193
266
  # Fall back to absolute paths if no common root
194
267
  source_rel = source_path
195
268
  dest_rel = dest_path
269
+ if verbose:
270
+ print("No common root found, using absolute paths")
196
271
 
197
272
  print(f"Moving: {source_rel} -> {dest_rel}")
198
273
 
199
274
  if not dry_run:
200
275
  # Create destination directory if it doesn't exist
201
- 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)
202
280
 
203
281
  # Move the file
282
+ if verbose:
283
+ print("Executing file move operation")
204
284
  shutil.move(str(source_path), str(dest_path))
285
+ if verbose:
286
+ print("File moved successfully")
205
287
 
206
288
  if update_references:
289
+ if verbose:
290
+ print("Updating references to the moved file")
291
+
207
292
  # Find all .rst files that might reference this file
208
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}")
209
296
  all_files = find_all_rst_files(str(root_dir))
297
+ if verbose:
298
+ print(f"Found {len(all_files)} RST files to check")
210
299
 
211
- # Find files that reference the moved file
212
- referencing_files = find_files_referencing(str(source_rel), all_files)
300
+ # Find files that reference the moved file, using context if provided
301
+ referencing_files = find_files_referencing(
302
+ str(source_rel), all_files, context_path=context_path, verbose=verbose
303
+ )
213
304
 
214
305
  if referencing_files:
215
306
  print(f"\nUpdating references in {len(referencing_files)} file(s):")
@@ -221,9 +312,15 @@ def move_rst_file(
221
312
  source_stem = source_path.stem
222
313
  dest_stem = dest_path.stem
223
314
 
315
+ if verbose:
316
+ print(
317
+ f"Updating references from {source_stem} to"
318
+ f" {dest_stem} in {ref_file}"
319
+ )
320
+
224
321
  # Update the references
225
322
  updated = update_references_in_file(
226
- ref_file, source_stem, dest_stem
323
+ ref_file, source_stem, dest_stem, verbose=verbose
227
324
  )
228
325
 
229
326
  if updated:
@@ -241,19 +338,39 @@ def execute(args):
241
338
  update_refs = getattr(args, "no_update_refs", False)
242
339
  update_references = not update_refs
243
340
 
341
+ # Get global options
342
+ context_path = getattr(args, "context", None)
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
+ )
355
+
244
356
  # Perform the move
245
357
  move_rst_file(
246
358
  args.source,
247
359
  args.destination,
248
360
  update_references=update_references,
249
- dry_run=getattr(args, "dry_run", False),
361
+ dry_run=dry_run,
362
+ context_path=context_path,
363
+ verbose=verbose,
250
364
  )
251
365
 
252
- if not getattr(args, "dry_run", False):
366
+ if not dry_run:
253
367
  print("\n✓ Move completed successfully!")
254
368
  else:
255
369
  print("\n[Dry run complete - no files were actually moved]")
256
370
 
371
+ if verbose:
372
+ print("Operation completed successfully")
373
+
257
374
  except Exception as e:
258
375
  print(f"Error: {e}")
259
376
  raise