rolfedh-doc-utils 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl

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.
archive_unused_files.py CHANGED
@@ -1,7 +1,8 @@
1
1
  """
2
2
  Archive Unused AsciiDoc Files
3
3
 
4
- Scans './modules' and './assemblies' for AsciiDoc files not referenced by any other AsciiDoc file in the project. Optionally archives and deletes them.
4
+ Automatically discovers and scans 'modules' and 'assemblies' directories for AsciiDoc files
5
+ not referenced by any other AsciiDoc file in the project. Optionally archives and deletes them.
5
6
 
6
7
  For full documentation and usage examples, see archive_unused_files.md in this directory.
7
8
  """
@@ -11,14 +12,19 @@ from doc_utils.unused_adoc import find_unused_adoc
11
12
  from doc_utils.file_utils import parse_exclude_list_file
12
13
 
13
14
  def main():
14
- parser = argparse.ArgumentParser(description='Archive unused AsciiDoc files.')
15
+ parser = argparse.ArgumentParser(
16
+ description='Archive unused AsciiDoc files.',
17
+ epilog='By default, automatically discovers all modules and assemblies directories in the repository.'
18
+ )
15
19
  parser.add_argument('--archive', action='store_true', help='Move the files to a dated zip in the archive directory.')
20
+ parser.add_argument('--scan-dir', action='append', default=[], help='Specific directory to scan (can be used multiple times). If not specified, auto-discovers directories.')
16
21
  parser.add_argument('--exclude-dir', action='append', default=[], help='Directory to exclude (can be used multiple times).')
17
22
  parser.add_argument('--exclude-file', action='append', default=[], help='File to exclude (can be used multiple times).')
18
23
  parser.add_argument('--exclude-list', type=str, help='Path to a file containing directories or files to exclude, one per line.')
19
24
  args = parser.parse_args()
20
25
 
21
- scan_dirs = ['./modules', './modules/rn', './assemblies']
26
+ # Use provided scan directories or None for auto-discovery
27
+ scan_dirs = args.scan_dir if args.scan_dir else None
22
28
  archive_dir = './archive'
23
29
 
24
30
  exclude_dirs = list(args.exclude_dir)
doc_utils/unused_adoc.py CHANGED
@@ -5,10 +5,77 @@ import re
5
5
  from .file_utils import collect_files, write_manifest_and_archive
6
6
  from .topic_map_parser import detect_repo_type, get_all_topic_map_references
7
7
 
8
- def find_unused_adoc(scan_dirs, archive_dir, archive=False, exclude_dirs=None, exclude_files=None):
8
+ def find_scan_directories(base_path='.', exclude_dirs=None):
9
+ """
10
+ Automatically find all 'modules' and 'assemblies' directories in the repository.
11
+
12
+ Returns a list of paths to scan.
13
+ """
14
+ scan_dirs = []
15
+ exclude_dirs = exclude_dirs or []
16
+
17
+ for root, dirs, files in os.walk(base_path):
18
+ # Skip symbolic links to prevent issues
19
+ dirs[:] = [d for d in dirs if not os.path.islink(os.path.join(root, d))]
20
+
21
+ # Skip excluded directories
22
+ for exclude_dir in exclude_dirs:
23
+ abs_exclude = os.path.abspath(exclude_dir)
24
+ if os.path.abspath(root).startswith(abs_exclude):
25
+ dirs[:] = [] # Don't descend into excluded directories
26
+ break
27
+
28
+ # Skip hidden directories and common non-content directories
29
+ dirs[:] = [d for d in dirs if not d.startswith('.') and d not in ['node_modules', 'build', 'dist', 'target']]
30
+
31
+ # Look for modules and assemblies directories
32
+ for d in dirs:
33
+ if d in ['modules', 'assemblies']:
34
+ dir_path = os.path.join(root, d)
35
+ # Check if this directory or any subdirectory contains .adoc files
36
+ has_adoc = False
37
+ for subroot, subdirs, subfiles in os.walk(dir_path):
38
+ # Skip symbolic links
39
+ subdirs[:] = [sd for sd in subdirs if not os.path.islink(os.path.join(subroot, sd))]
40
+ if any(f.endswith('.adoc') for f in subfiles):
41
+ has_adoc = True
42
+ break
43
+ if has_adoc:
44
+ scan_dirs.append(dir_path)
45
+
46
+ # Also check for modules/rn pattern if modules exists
47
+ modules_dirs = [d for d in scan_dirs if os.path.basename(d) == 'modules']
48
+ for modules_dir in modules_dirs:
49
+ rn_dir = os.path.join(modules_dir, 'rn')
50
+ if os.path.isdir(rn_dir):
51
+ # Check if rn directory or subdirectories contain .adoc files
52
+ has_adoc = False
53
+ for subroot, subdirs, subfiles in os.walk(rn_dir):
54
+ subdirs[:] = [sd for sd in subdirs if not os.path.islink(os.path.join(subroot, sd))]
55
+ if any(f.endswith('.adoc') for f in subfiles):
56
+ has_adoc = True
57
+ break
58
+ if has_adoc:
59
+ scan_dirs.append(rn_dir)
60
+
61
+ return scan_dirs
62
+
63
+ def find_unused_adoc(scan_dirs=None, archive_dir='./archive', archive=False, exclude_dirs=None, exclude_files=None):
9
64
  # Print safety warning
10
65
  print("\n⚠️ SAFETY: Work in a git branch! Run without --archive first to preview.\n")
11
66
 
67
+ # If no scan_dirs provided, auto-discover them
68
+ if not scan_dirs:
69
+ scan_dirs = find_scan_directories(exclude_dirs=exclude_dirs)
70
+ if scan_dirs:
71
+ print(f"Auto-discovered directories to scan:")
72
+ for dir_path in sorted(scan_dirs):
73
+ print(f" - {dir_path}")
74
+ else:
75
+ print("No 'modules' or 'assemblies' directories found containing .adoc files.")
76
+ print("Please run this tool from your documentation repository root.")
77
+ return
78
+
12
79
  # Detect repository type
13
80
  repo_type = detect_repo_type()
14
81
  print(f"Detected repository type: {repo_type}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rolfedh-doc-utils
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: CLI tools for AsciiDoc documentation projects
5
5
  Author: Rolfe Dlugy-Hegwer
6
6
  License: MIT License
@@ -99,6 +99,7 @@ The following CLI tools are installed:
99
99
  * `archive-unused-files`
100
100
  * `archive-unused-images`
101
101
  * `find-unused-attributes`
102
+ * `format-asciidoc-spacing`
102
103
 
103
104
  These tools can be run from any directory.
104
105
 
@@ -132,7 +133,7 @@ Scans `.adoc` files in the current directory to report:
132
133
  * Paragraphs with too many sentences (default: 3 sentences)
133
134
  * Supports exclusion of files and directories
134
135
 
135
- ➡️ See [`check_scannability.md`](https://github.com/rolfedh/doc-utils/blob/main/check_scannability.md) for details.
136
+ ➡️ See [Scannability Checker for AsciiDoc Files](https://github.com/rolfedh/doc-utils/blob/main/check_scannability.md) for details.
136
137
 
137
138
  ---
138
139
 
@@ -144,7 +145,7 @@ Works with both:
144
145
  - **OpenShift-docs style** repositories (uses `_topic_maps/*.yml` files)
145
146
  - **Traditional AsciiDoc** repositories (uses `master.adoc` files)
146
147
 
147
- ➡️ See [`archive_unused_files.md`](https://github.com/rolfedh/doc-utils/blob/main/archive_unused_files.md).
148
+ ➡️ See [Archive Unused AsciiDoc Files](https://github.com/rolfedh/doc-utils/blob/main/archive_unused_files.md).
148
149
 
149
150
  ---
150
151
 
@@ -152,7 +153,7 @@ Works with both:
152
153
 
153
154
  Finds unused image files (e.g., `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`) in the current directory and optionally archives and deletes them.
154
155
 
155
- ➡️ See [`archive_unused_images.md`](https://github.com/rolfedh/doc-utils/blob/main/archive_unused_images.md).
156
+ ➡️ See [Archive Unused Images](https://github.com/rolfedh/doc-utils/blob/main/archive_unused_images.md).
156
157
 
157
158
  ---
158
159
 
@@ -160,7 +161,22 @@ Finds unused image files (e.g., `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`) in the
160
161
 
161
162
  Scans an attributes file (e.g., `attributes.adoc`) for unused attribute definitions across all `.adoc` files in the current directory.
162
163
 
163
- ➡️ See [`find_unused_attributes.md`](https://github.com/rolfedh/doc-utils/blob/main/find_unused_attributes.md).
164
+ ➡️ See [Find Unused AsciiDoc Attributes](https://github.com/rolfedh/doc-utils/blob/main/find_unused_attributes.md).
165
+
166
+ ---
167
+
168
+ ### `format-asciidoc-spacing`
169
+
170
+ Ensures proper spacing in AsciiDoc files by adding blank lines after headings and around `include::` directives.
171
+
172
+ Formatting rules:
173
+ - Adds blank line after headings (`=`, `==`, `===`, etc.)
174
+ - Adds blank lines before and after `include::` directives
175
+ - Preserves existing spacing where appropriate
176
+
177
+ Implemented as a Python script (`format-asciidoc-spacing.py`).
178
+
179
+ ➡️ See [AsciiDoc Spacing Formatter](https://github.com/rolfedh/doc-utils/blob/main/format_asciidoc_spacing.md).
164
180
 
165
181
  ## Best Practices for Safe Usage
166
182
 
@@ -191,6 +207,7 @@ To run the tools after installation:
191
207
  check-scannability --help
192
208
  archive-unused-files --help
193
209
  find-unused-attributes attributes.adoc
210
+ format-asciidoc-spacing --help
194
211
  ```
195
212
 
196
213
  Or run them directly from source:
@@ -199,6 +216,7 @@ Or run them directly from source:
199
216
  python3 check_scannability.py
200
217
  python3 archive_unused_files.py
201
218
  python3 find_unused_attributes.py attributes.adoc
219
+ python3 format-asciidoc-spacing.py
202
220
  ```
203
221
 
204
222
  ### Directory/File Exclusion
@@ -278,7 +296,7 @@ Contributions are welcome! Please ensure:
278
296
  - Code follows PEP 8 style guidelines
279
297
  - Documentation is updated as needed
280
298
 
281
- See [CONTRIBUTING.md](https://github.com/rolfedh/doc-utils/blob/main/CONTRIBUTING.md) for more details.
299
+ See [Contributing Guidelines](https://github.com/rolfedh/doc-utils/blob/main/CONTRIBUTING.md) for more details.
282
300
 
283
301
  ## License
284
302
 
@@ -1,4 +1,4 @@
1
- archive_unused_files.py,sha256=MFdAtE8CDthida5H5FhvtEHZWrQAZZoAB-DQkTOc6gs,1537
1
+ archive_unused_files.py,sha256=KMC5a1WL3rZ5owoVnncvfpT1YeMKbVXq9giHvadDgbM,1936
2
2
  archive_unused_images.py,sha256=PG2o3haovYckgfhoPhl6KRG_a9czyZuqlLkzkupKTCY,1526
3
3
  check_scannability.py,sha256=gcM-vFXKHGP_yFBz7-V5xbXWhIMmtMzBYIGwP9CFbzI,5140
4
4
  find_unused_attributes.py,sha256=fk-K32eoCVHxoj7RiBNgSmX1arBLuwYfdSAOMc-wIx0,1677
@@ -6,12 +6,12 @@ doc_utils/__init__.py,sha256=qqZR3lohzkP63soymrEZPBGzzk6-nFzi4_tSffjmu_0,74
6
6
  doc_utils/file_utils.py,sha256=fpTh3xx759sF8sNocdn_arsP3KAv8XA6cTQTAVIZiZg,4247
7
7
  doc_utils/scannability.py,sha256=XwlmHqDs69p_V36X7DLjPTy0DUoLszSGqYjJ9wE-3hg,982
8
8
  doc_utils/topic_map_parser.py,sha256=tKcIO1m9r2K6dvPRGue58zqMr0O2zKU1gnZMzEE3U6o,4571
9
- doc_utils/unused_adoc.py,sha256=Bx8TH7twhtuDfxzrPLOWOzTLc5YBhIqrCNaKJJR_V38,2312
9
+ doc_utils/unused_adoc.py,sha256=2cbqcYr1os2EhETUU928BlPRlsZVSdI00qaMhqjSIqQ,5263
10
10
  doc_utils/unused_attributes.py,sha256=HBgmHelqearfWl3TTC2bZGiJytjLADIgiGQUNKqXXPg,1847
11
11
  doc_utils/unused_images.py,sha256=nqn36Bbrmon2KlGlcaruNjJJvTQ8_9H0WU9GvCW7rW8,1456
12
- rolfedh_doc_utils-0.1.4.dist-info/licenses/LICENSE,sha256=vLxtwMVOJA_hEy8b77niTkdmQI9kNJskXHq0dBS36e0,1075
13
- rolfedh_doc_utils-0.1.4.dist-info/METADATA,sha256=lPNDY0Lu9pBKxxzCXZp5TqSe3DuBqvBHYPVFyLWpP14,8152
14
- rolfedh_doc_utils-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- rolfedh_doc_utils-0.1.4.dist-info/entry_points.txt,sha256=i8LqEsp0KD4YyVI_7wQ1TMgCuag32D7gQes6bLufmtM,216
16
- rolfedh_doc_utils-0.1.4.dist-info/top_level.txt,sha256=BkaYN3KbtNvLQjs-QGBKCJb5UAtjEbC_IqxSSIN9P-w,95
17
- rolfedh_doc_utils-0.1.4.dist-info/RECORD,,
12
+ rolfedh_doc_utils-0.1.6.dist-info/licenses/LICENSE,sha256=vLxtwMVOJA_hEy8b77niTkdmQI9kNJskXHq0dBS36e0,1075
13
+ rolfedh_doc_utils-0.1.6.dist-info/METADATA,sha256=JoFOMLPMcQiGaSXBwqXLVZP5jLahLSP0s8_go98X4N8,8787
14
+ rolfedh_doc_utils-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ rolfedh_doc_utils-0.1.6.dist-info/entry_points.txt,sha256=dA-u4qlxKcewUAOFgaeW1NUIrkhsVknuwFuGTn1-84w,271
16
+ rolfedh_doc_utils-0.1.6.dist-info/top_level.txt,sha256=WrYqTa4wbjRPMUl2hgJBfP734XsXLkhbnzUublx8S0s,119
17
+ rolfedh_doc_utils-0.1.6.dist-info/RECORD,,
@@ -3,3 +3,4 @@ archive-unused-files = archive_unused_files:main
3
3
  archive-unused-images = archive_unused_images:main
4
4
  check-scannability = check_scannability:main
5
5
  find-unused-attributes = find_unused_attributes:main
6
+ format-asciidoc-spacing = format_asciidoc_spacing:main
@@ -3,3 +3,4 @@ archive_unused_images
3
3
  check_scannability
4
4
  doc_utils
5
5
  find_unused_attributes
6
+ format_asciidoc_spacing