sphinx-cmd 0.3.0__tar.gz → 0.3.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 (26) hide show
  1. {sphinx_cmd-0.3.0/sphinx_cmd.egg-info → sphinx_cmd-0.3.1}/PKG-INFO +27 -9
  2. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/README.md +25 -8
  3. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/pyproject.toml +1 -0
  4. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd/__init__.py +1 -1
  5. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd/cli.py +12 -0
  6. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd/commands/rm.py +12 -8
  7. sphinx_cmd-0.3.1/sphinx_cmd/config.py +93 -0
  8. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1/sphinx_cmd.egg-info}/PKG-INFO +27 -9
  9. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd.egg-info/requires.txt +1 -0
  10. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/tests/test_config.py +38 -8
  11. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/tests/test_custom_directives.py +3 -5
  12. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/tests/test_rm.py +3 -0
  13. sphinx_cmd-0.3.0/sphinx_cmd/config.py +0 -81
  14. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/LICENSE +0 -0
  15. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/MANIFEST.in +0 -0
  16. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/setup.cfg +0 -0
  17. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd/commands/__init__.py +0 -0
  18. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd/commands/mv.py +0 -0
  19. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd/py.typed +0 -0
  20. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd.egg-info/SOURCES.txt +0 -0
  21. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd.egg-info/dependency_links.txt +0 -0
  22. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd.egg-info/entry_points.txt +0 -0
  23. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/sphinx_cmd.egg-info/top_level.txt +0 -0
  24. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/tests/test_cli.py +0 -0
  25. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/tests/test_integration.py +0 -0
  26. {sphinx_cmd-0.3.0 → sphinx_cmd-0.3.1}/tests/test_mv.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sphinx-cmd
3
- Version: 0.3.0
3
+ Version: 0.3.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
@@ -23,6 +23,7 @@ Requires-Dist: black; extra == "dev"
23
23
  Requires-Dist: flake8; extra == "dev"
24
24
  Requires-Dist: mypy; extra == "dev"
25
25
  Requires-Dist: isort; extra == "dev"
26
+ Requires-Dist: pre-commit; extra == "dev"
26
27
  Provides-Extra: test
27
28
  Requires-Dist: pytest>=7.0.0; extra == "test"
28
29
  Dynamic: license-file
@@ -51,9 +52,12 @@ sphinx-cmd rm path/to/docs
51
52
 
52
53
  # Dry run to preview deletions
53
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
54
58
  ```
55
59
 
56
- ### Features
60
+ #### Features
57
61
 
58
62
  - Configure custom directives to be processed
59
63
 
@@ -73,6 +77,9 @@ sphinx-cmd mv old-file.rst new-file.rst --dry-run
73
77
 
74
78
  # Move without updating references
75
79
  sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
80
+
81
+ # Process additional directives beyond defaults
82
+ sphinx-cmd mv old-file.rst new-file.rst --directives drawio-figure,drawio-image
76
83
  ```
77
84
 
78
85
  #### Features
@@ -82,21 +89,32 @@ sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
82
89
  - Updates `include` and `literalinclude` directives
83
90
  - Handles relative paths correctly
84
91
  - Preserves file relationships
92
+ - Configure custom directives to be processed
85
93
 
86
94
  ## Configuration
87
95
 
88
- You can add custom directives to be processed by creating a `.sphinx-cmd.toml` file in your home directory.
96
+ You can add custom directives to be processed in two ways:
97
+
98
+ ### 1. Command Line
99
+
100
+ Use the `--directives` option with any command to add custom directives for a single run:
101
+
102
+ ```bash
103
+ sphinx-cmd rm path/to/docs --directives drawio-figure,drawio-image
104
+ ```
105
+
106
+ ### 2. Configuration File
89
107
 
90
- Add your custom directives to `[directives]` with their respective regex patterns, for example:
108
+ Create a `.sphinx-cmd.toml` file in your home directory with your custom directives:
91
109
 
92
110
  ```toml
93
- [directives]
94
- drawio-figure = "^\\s*\\.\\.\\s+drawio-figure::\\s+(.+)$"
95
- drawio-image = "^\\s*\\.\\.\\s+drawio-image::\\s+(.+)$"
111
+ directives = [
112
+ "drawio-figure",
113
+ "drawio-image"
114
+ ]
96
115
  ```
97
116
 
98
- > [!NOTE]
99
- > Each regex pattern must include a capturing group `(.+)` to extract the file path.
117
+ Command line directives will be combined with those in the configuration file and the built-in defaults.
100
118
 
101
119
 
102
120
  ## Development
@@ -22,9 +22,12 @@ sphinx-cmd rm path/to/docs
22
22
 
23
23
  # Dry run to preview deletions
24
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
25
28
  ```
26
29
 
27
- ### Features
30
+ #### Features
28
31
 
29
32
  - Configure custom directives to be processed
30
33
 
@@ -44,6 +47,9 @@ sphinx-cmd mv old-file.rst new-file.rst --dry-run
44
47
 
45
48
  # Move without updating references
46
49
  sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
50
+
51
+ # Process additional directives beyond defaults
52
+ sphinx-cmd mv old-file.rst new-file.rst --directives drawio-figure,drawio-image
47
53
  ```
48
54
 
49
55
  #### Features
@@ -53,21 +59,32 @@ sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
53
59
  - Updates `include` and `literalinclude` directives
54
60
  - Handles relative paths correctly
55
61
  - Preserves file relationships
62
+ - Configure custom directives to be processed
56
63
 
57
64
  ## Configuration
58
65
 
59
- You can add custom directives to be processed by creating a `.sphinx-cmd.toml` file in your home directory.
66
+ You can add custom directives to be processed in two ways:
67
+
68
+ ### 1. Command Line
69
+
70
+ Use the `--directives` option with any command to add custom directives for a single run:
71
+
72
+ ```bash
73
+ sphinx-cmd rm path/to/docs --directives drawio-figure,drawio-image
74
+ ```
75
+
76
+ ### 2. Configuration File
60
77
 
61
- Add your custom directives to `[directives]` with their respective regex patterns, for example:
78
+ Create a `.sphinx-cmd.toml` file in your home directory with your custom directives:
62
79
 
63
80
  ```toml
64
- [directives]
65
- drawio-figure = "^\\s*\\.\\.\\s+drawio-figure::\\s+(.+)$"
66
- drawio-image = "^\\s*\\.\\.\\s+drawio-image::\\s+(.+)$"
81
+ directives = [
82
+ "drawio-figure",
83
+ "drawio-image"
84
+ ]
67
85
  ```
68
86
 
69
- > [!NOTE]
70
- > Each regex pattern must include a capturing group `(.+)` to extract the file path.
87
+ Command line directives will be combined with those in the configuration file and the built-in defaults.
71
88
 
72
89
 
73
90
  ## Development
@@ -37,6 +37,7 @@ dev = [
37
37
  "flake8",
38
38
  "mypy",
39
39
  "isort",
40
+ "pre-commit",
40
41
  ]
41
42
  test = [
42
43
  "pytest>=7.0.0",
@@ -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.0"
4
+ __version__ = "0.3.1"
@@ -39,6 +39,12 @@ def create_parser():
39
39
  action="store_true",
40
40
  help="Preview deletions without removing files",
41
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
+ )
42
48
  rm_parser.set_defaults(command_name="rm")
43
49
 
44
50
  # Add 'mv' subcommand
@@ -58,6 +64,12 @@ def create_parser():
58
64
  action="store_true",
59
65
  help="Do not update references to the moved file",
60
66
  )
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
+ )
61
73
  mv_parser.set_defaults(command_name="mv")
62
74
 
63
75
  return parser
@@ -21,7 +21,7 @@ def find_rst_files(path):
21
21
  return rst_files
22
22
 
23
23
 
24
- def extract_assets(file_path, visited=None):
24
+ def extract_assets(file_path, visited=None, cli_directives=None):
25
25
  """Extract asset references from an .rst file, recursively parsing includes."""
26
26
  if visited is None:
27
27
  visited = set()
@@ -33,7 +33,7 @@ def extract_assets(file_path, visited=None):
33
33
  visited.add(abs_path)
34
34
 
35
35
  asset_directives = {}
36
- directive_patterns = get_directive_patterns()
36
+ directive_patterns = get_directive_patterns(cli_directives)
37
37
 
38
38
  # If file doesn't exist, skip it
39
39
  if not os.path.exists(file_path):
@@ -63,14 +63,14 @@ def extract_assets(file_path, visited=None):
63
63
  return asset_directives
64
64
 
65
65
 
66
- def build_asset_index(rst_files):
66
+ def build_asset_index(rst_files, cli_directives=None):
67
67
  """Build an index of assets and which files reference them."""
68
68
  asset_to_files = defaultdict(set)
69
69
  file_to_assets = {}
70
70
  asset_directive_map = {}
71
71
 
72
72
  for rst in rst_files:
73
- asset_directives = extract_assets(rst)
73
+ asset_directives = extract_assets(rst, cli_directives=cli_directives)
74
74
  file_to_assets[rst] = set(asset_directives.keys())
75
75
  for asset, directive in asset_directives.items():
76
76
  asset_to_files[asset].add(rst)
@@ -78,7 +78,7 @@ def build_asset_index(rst_files):
78
78
  return asset_to_files, file_to_assets, asset_directive_map
79
79
 
80
80
 
81
- def get_transitive_includes(file_path, visited=None):
81
+ def get_transitive_includes(file_path, visited=None, cli_directives=None):
82
82
  """Get all files included transitively from a file."""
83
83
  if visited is None:
84
84
  visited = set()
@@ -94,7 +94,7 @@ def get_transitive_includes(file_path, visited=None):
94
94
  if not os.path.exists(file_path):
95
95
  return includes
96
96
 
97
- directive_patterns = get_directive_patterns()
97
+ directive_patterns = get_directive_patterns(cli_directives)
98
98
 
99
99
  try:
100
100
  with open(file_path, encoding="utf-8") as f:
@@ -110,7 +110,9 @@ def get_transitive_includes(file_path, visited=None):
110
110
  includes.add(include_full_path)
111
111
  # Recursively get includes from the included file
112
112
  includes.update(
113
- get_transitive_includes(include_full_path, visited.copy())
113
+ get_transitive_includes(
114
+ include_full_path, visited.copy(), cli_directives
115
+ )
114
116
  )
115
117
  except Exception as e:
116
118
  print(f"Warning: Could not read {file_path}: {e}")
@@ -237,7 +239,9 @@ def execute(args):
237
239
  """Execute the rm command."""
238
240
  original_path = os.path.abspath(args.path)
239
241
  rst_files = find_rst_files(args.path)
240
- asset_to_files, file_to_assets, asset_directive_map = build_asset_index(rst_files)
242
+ asset_to_files, file_to_assets, asset_directive_map = build_asset_index(
243
+ rst_files, cli_directives=args.directives
244
+ )
241
245
  deleted_pages, deleted_assets, affected_dirs = delete_unused_assets_and_pages(
242
246
  asset_to_files, file_to_assets, asset_directive_map, args.dry_run
243
247
  )
@@ -0,0 +1,93 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Configuration handling for sphinx-cmd.
4
+ """
5
+
6
+ import re
7
+ import sys
8
+ from pathlib import Path
9
+ from typing import Dict, Optional
10
+
11
+ # Use the standard library tomllib if Python 3.11+, otherwise use tomli package
12
+ if sys.version_info >= (3, 11):
13
+ import tomllib
14
+ else:
15
+ import tomli as tomllib
16
+
17
+ # Default configuration with built-in directives
18
+ DEFAULT_CONFIG = {"directives": ["image", "figure", "include"]}
19
+
20
+
21
+ def get_config_path() -> Optional[Path]:
22
+ """Get the path to the configuration file."""
23
+ # Check for config in user's home directory
24
+ home_config = Path.home() / ".sphinx-cmd.toml"
25
+ if home_config.exists():
26
+ return home_config
27
+
28
+ return None
29
+
30
+
31
+ def load_config(cli_directives=None) -> Dict:
32
+ """
33
+ Load configuration from a TOML file and merge with CLI directives.
34
+
35
+ The function looks for a config file at:
36
+ - user's home directory
37
+
38
+ Args:
39
+ cli_directives: Optional list of directive names passed from the command line
40
+
41
+ Returns:
42
+ Dict: The merged configuration (defaults + user config + CLI directives)
43
+ """
44
+ config = DEFAULT_CONFIG.copy()
45
+
46
+ config_path = get_config_path()
47
+ if config_path:
48
+ try:
49
+ with open(config_path, "rb") as f:
50
+ user_config = tomllib.load(f)
51
+
52
+ # Merge user directives with default directives
53
+ if "directives" in user_config:
54
+ # If user config has list of directive names, extend default list
55
+ config["directives"].extend(
56
+ [
57
+ name
58
+ for name in user_config["directives"]
59
+ if name not in config["directives"]
60
+ ]
61
+ )
62
+
63
+ except Exception as e:
64
+ print(f"Warning: Error loading config from {config_path}: {e}")
65
+
66
+ # Add CLI directives if provided
67
+ if cli_directives:
68
+ config["directives"].extend(
69
+ [name for name in cli_directives if name not in config["directives"]]
70
+ )
71
+
72
+ return config
73
+
74
+
75
+ def get_directive_patterns(cli_directives=None) -> Dict[str, re.Pattern]:
76
+ """
77
+ Get compiled regex patterns for all directives.
78
+
79
+ Args:
80
+ cli_directives: Optional list of directive names passed from the command line
81
+
82
+ Returns:
83
+ Dict[str, re.Pattern]: Dictionary of directive names to compiled regex patterns
84
+ """
85
+ config = load_config(cli_directives)
86
+ patterns = {}
87
+
88
+ for name in config["directives"]:
89
+ # Generate regex pattern from directive name
90
+ pattern = rf"^\s*\.\.\s+{name}::\s+(.+)$"
91
+ patterns[name] = re.compile(pattern, re.MULTILINE)
92
+
93
+ return patterns
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sphinx-cmd
3
- Version: 0.3.0
3
+ Version: 0.3.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
@@ -23,6 +23,7 @@ Requires-Dist: black; extra == "dev"
23
23
  Requires-Dist: flake8; extra == "dev"
24
24
  Requires-Dist: mypy; extra == "dev"
25
25
  Requires-Dist: isort; extra == "dev"
26
+ Requires-Dist: pre-commit; extra == "dev"
26
27
  Provides-Extra: test
27
28
  Requires-Dist: pytest>=7.0.0; extra == "test"
28
29
  Dynamic: license-file
@@ -51,9 +52,12 @@ sphinx-cmd rm path/to/docs
51
52
 
52
53
  # Dry run to preview deletions
53
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
54
58
  ```
55
59
 
56
- ### Features
60
+ #### Features
57
61
 
58
62
  - Configure custom directives to be processed
59
63
 
@@ -73,6 +77,9 @@ sphinx-cmd mv old-file.rst new-file.rst --dry-run
73
77
 
74
78
  # Move without updating references
75
79
  sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
80
+
81
+ # Process additional directives beyond defaults
82
+ sphinx-cmd mv old-file.rst new-file.rst --directives drawio-figure,drawio-image
76
83
  ```
77
84
 
78
85
  #### Features
@@ -82,21 +89,32 @@ sphinx-cmd mv old-file.rst new-file.rst --no-update-refs
82
89
  - Updates `include` and `literalinclude` directives
83
90
  - Handles relative paths correctly
84
91
  - Preserves file relationships
92
+ - Configure custom directives to be processed
85
93
 
86
94
  ## Configuration
87
95
 
88
- You can add custom directives to be processed by creating a `.sphinx-cmd.toml` file in your home directory.
96
+ You can add custom directives to be processed in two ways:
97
+
98
+ ### 1. Command Line
99
+
100
+ Use the `--directives` option with any command to add custom directives for a single run:
101
+
102
+ ```bash
103
+ sphinx-cmd rm path/to/docs --directives drawio-figure,drawio-image
104
+ ```
105
+
106
+ ### 2. Configuration File
89
107
 
90
- Add your custom directives to `[directives]` with their respective regex patterns, for example:
108
+ Create a `.sphinx-cmd.toml` file in your home directory with your custom directives:
91
109
 
92
110
  ```toml
93
- [directives]
94
- drawio-figure = "^\\s*\\.\\.\\s+drawio-figure::\\s+(.+)$"
95
- drawio-image = "^\\s*\\.\\.\\s+drawio-image::\\s+(.+)$"
111
+ directives = [
112
+ "drawio-figure",
113
+ "drawio-image"
114
+ ]
96
115
  ```
97
116
 
98
- > [!NOTE]
99
- > Each regex pattern must include a capturing group `(.+)` to extract the file path.
117
+ Command line directives will be combined with those in the configuration file and the built-in defaults.
100
118
 
101
119
 
102
120
  ## Development
@@ -8,6 +8,7 @@ black
8
8
  flake8
9
9
  mypy
10
10
  isort
11
+ pre-commit
11
12
 
12
13
  [test]
13
14
  pytest>=7.0.0
@@ -24,12 +24,7 @@ def test_load_custom_config():
24
24
 
25
25
  # Create a custom config file with proper TOML syntax
26
26
  toml_content = """
27
- [directives]
28
- image = "^\\\\s*\\\\.\\\\.\\\\s+image::\\\\s+(.+)$"
29
- figure = "^\\\\s*\\\\.\\\\.\\\\s+figure::\\\\s+(.+)$"
30
- include = "^\\\\s*\\\\.\\\\.\\\\s+include::\\\\s+(.+)$"
31
- drawio-figure = "^\\\\s*\\\\.\\\\.\\\\s+drawio-figure::\\\\s+(.+)$"
32
- drawio-image = "^\\\\s*\\\\.\\\\.\\\\s+drawio-image::\\\\s+(.+)$"
27
+ directives = ["image", "figure", "include", "drawio-figure", "drawio-image"]
33
28
  """
34
29
  with open(config_path, "wb") as f:
35
30
  f.write(toml_content.encode())
@@ -55,8 +50,7 @@ def test_get_directive_patterns():
55
50
 
56
51
  # Create a custom config file with drawio directives with proper TOML syntax
57
52
  toml_content = """
58
- [directives]
59
- drawio-figure = "^\\\\s*\\\\.\\\\.\\\\s+drawio-figure::\\\\s+(.+)$"
53
+ directives = ["drawio-figure"]
60
54
  """
61
55
  with open(config_path, "wb") as f:
62
56
  f.write(toml_content.encode())
@@ -77,3 +71,39 @@ drawio-figure = "^\\\\s*\\\\.\\\\.\\\\s+drawio-figure::\\\\s+(.+)$"
77
71
  match = patterns["drawio-figure"].findall(test_string)
78
72
  assert len(match) == 1
79
73
  assert match[0] == "path/to/diagram.drawio"
74
+
75
+
76
+ def test_cli_directives():
77
+ """Test that CLI directives are properly merged with config directives."""
78
+ with tempfile.TemporaryDirectory() as tmpdir:
79
+ config_path = Path(tmpdir) / ".sphinx-cmd.toml"
80
+
81
+ # Create a custom config file with some directives
82
+ toml_content = """
83
+ directives = ["drawio-figure"]
84
+ """
85
+ with open(config_path, "wb") as f:
86
+ f.write(toml_content.encode())
87
+
88
+ with patch("sphinx_cmd.config.get_config_path", return_value=config_path):
89
+ # Add CLI directives
90
+ cli_directives = ["drawio-image", "custom-directive"]
91
+ patterns = get_directive_patterns(cli_directives)
92
+
93
+ # Default patterns should be included
94
+ assert "image" in patterns
95
+ assert "figure" in patterns
96
+ assert "include" in patterns
97
+
98
+ # Config file directives should be included
99
+ assert "drawio-figure" in patterns
100
+
101
+ # CLI directives should be included
102
+ assert "drawio-image" in patterns
103
+ assert "custom-directive" in patterns
104
+
105
+ # Test a CLI directive pattern works
106
+ test_string = ".. custom-directive:: path/to/custom.file"
107
+ match = patterns["custom-directive"].findall(test_string)
108
+ assert len(match) == 1
109
+ assert match[0] == "path/to/custom.file"
@@ -14,9 +14,7 @@ def test_custom_directive_extraction():
14
14
 
15
15
  # Create config with proper TOML syntax
16
16
  toml_content = """
17
- [directives]
18
- drawio-figure = "^\\\\s*\\\\.\\\\.\\\\s+drawio-figure::\\\\s+(.+)$"
19
- drawio-image = "^\\\\s*\\\\.\\\\.\\\\s+drawio-image::\\\\s+(.+)$"
17
+ directives = ["drawio-figure", "drawio-image"]
20
18
  """
21
19
  with open(config_path, "wb") as f:
22
20
  f.write(toml_content.encode())
@@ -66,8 +64,7 @@ def test_rm_command_with_custom_directives():
66
64
 
67
65
  # Create config with proper TOML syntax
68
66
  toml_content = """
69
- [directives]
70
- drawio-figure = "^\\\\s*\\\\.\\\\.\\\\s+drawio-figure::\\\\s+(.+)$"
67
+ directives = ["drawio-figure"]
71
68
  """
72
69
  with open(config_path, "wb") as f:
73
70
  f.write(toml_content.encode())
@@ -104,6 +101,7 @@ Test Page
104
101
  args = Mock()
105
102
  args.path = test_dir
106
103
  args.dry_run = True
104
+ args.directives = None
107
105
 
108
106
  # Run with dry-run to test detection
109
107
  execute(args)
@@ -84,6 +84,7 @@ Test Page
84
84
  args = Mock()
85
85
  args.path = test_dir
86
86
  args.dry_run = True
87
+ args.directives = None
87
88
  execute(args)
88
89
 
89
90
  # Verify files still exist after dry run
@@ -127,6 +128,7 @@ def test_empty_directory_removal():
127
128
  args = Mock()
128
129
  args.path = docs_dir
129
130
  args.dry_run = False
131
+ args.directives = None
130
132
 
131
133
  # Execute the command to remove files
132
134
  execute(args)
@@ -169,6 +171,7 @@ def test_non_empty_directory_retained():
169
171
  args = Mock()
170
172
  args.path = docs_dir
171
173
  args.dry_run = False
174
+ args.directives = None
172
175
 
173
176
  # Execute the command to remove files
174
177
  execute(args)
@@ -1,81 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Configuration handling for sphinx-cmd.
4
- """
5
-
6
- import re
7
- import sys
8
- from pathlib import Path
9
- from typing import Dict, Optional
10
-
11
- # Use the standard library tomllib if Python 3.11+, otherwise use tomli package
12
- if sys.version_info >= (3, 11):
13
- import tomllib
14
- else:
15
- import tomli as tomllib
16
-
17
- # Default configuration with built-in directives
18
- DEFAULT_CONFIG = {
19
- "directives": {
20
- "image": r"^\s*\.\.\s+image::\s+(.+)$",
21
- "figure": r"^\s*\.\.\s+figure::\s+(.+)$",
22
- "include": r"^\s*\.\.\s+include::\s+(.+)$",
23
- }
24
- }
25
-
26
-
27
- def get_config_path() -> Optional[Path]:
28
- """Get the path to the configuration file."""
29
- # Check for config in user's home directory
30
- home_config = Path.home() / ".sphinx-cmd.toml"
31
- if home_config.exists():
32
- return home_config
33
-
34
- return None
35
-
36
-
37
- def load_config() -> Dict:
38
- """
39
- Load configuration from a TOML file.
40
-
41
- The function looks for a config file at:
42
- - user's home directory
43
-
44
- Returns:
45
- Dict: The merged configuration (defaults + user config)
46
- """
47
- config = DEFAULT_CONFIG.copy()
48
-
49
- config_path = get_config_path()
50
- if not config_path:
51
- return config
52
-
53
- try:
54
- with open(config_path, "rb") as f:
55
- user_config = tomllib.load(f)
56
-
57
- # Merge user directives with default directives
58
- if "directives" in user_config:
59
- for name, pattern in user_config["directives"].items():
60
- config["directives"][name] = pattern
61
-
62
- except Exception as e:
63
- print(f"Warning: Error loading config from {config_path}: {e}")
64
-
65
- return config
66
-
67
-
68
- def get_directive_patterns() -> Dict[str, re.Pattern]:
69
- """
70
- Get compiled regex patterns for all directives.
71
-
72
- Returns:
73
- Dict[str, re.Pattern]: Dictionary of directive names to compiled regex patterns
74
- """
75
- config = load_config()
76
- patterns = {}
77
-
78
- for name, pattern in config["directives"].items():
79
- patterns[name] = re.compile(pattern, re.MULTILINE)
80
-
81
- return patterns
File without changes
File without changes
File without changes
File without changes
File without changes