rolfedh-doc-utils 0.1.16__py3-none-any.whl → 0.1.17__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.
- doc_utils/unused_attributes.py +50 -0
- find_unused_attributes.py +12 -1
- {rolfedh_doc_utils-0.1.16.dist-info → rolfedh_doc_utils-0.1.17.dist-info}/METADATA +1 -1
- {rolfedh_doc_utils-0.1.16.dist-info → rolfedh_doc_utils-0.1.17.dist-info}/RECORD +8 -8
- {rolfedh_doc_utils-0.1.16.dist-info → rolfedh_doc_utils-0.1.17.dist-info}/WHEEL +0 -0
- {rolfedh_doc_utils-0.1.16.dist-info → rolfedh_doc_utils-0.1.17.dist-info}/entry_points.txt +0 -0
- {rolfedh_doc_utils-0.1.16.dist-info → rolfedh_doc_utils-0.1.17.dist-info}/licenses/LICENSE +0 -0
- {rolfedh_doc_utils-0.1.16.dist-info → rolfedh_doc_utils-0.1.17.dist-info}/top_level.txt +0 -0
doc_utils/unused_attributes.py
CHANGED
|
@@ -50,13 +50,22 @@ def find_adoc_files(root_dir: str) -> List[str]:
|
|
|
50
50
|
|
|
51
51
|
def scan_for_attribute_usage(adoc_files: List[str], attributes: Set[str]) -> Set[str]:
|
|
52
52
|
used = set()
|
|
53
|
+
# Pattern for attribute references: {attribute-name}
|
|
53
54
|
attr_pattern = re.compile(r'\{([\w-]+)\}')
|
|
55
|
+
# Patterns for conditional directives: ifdef::attr[], ifndef::attr[], endif::attr[]
|
|
56
|
+
conditional_pattern = re.compile(r'(?:ifdef|ifndef|endif)::([\w-]+)\[')
|
|
57
|
+
|
|
54
58
|
for file in adoc_files:
|
|
55
59
|
with open(file, 'r', encoding='utf-8') as f:
|
|
56
60
|
for line in f:
|
|
61
|
+
# Check for {attribute} references
|
|
57
62
|
for match in attr_pattern.findall(line):
|
|
58
63
|
if match in attributes:
|
|
59
64
|
used.add(match)
|
|
65
|
+
# Check for ifdef::attribute[], ifndef::attribute[], endif::attribute[]
|
|
66
|
+
for match in conditional_pattern.findall(line):
|
|
67
|
+
if match in attributes:
|
|
68
|
+
used.add(match)
|
|
60
69
|
return used
|
|
61
70
|
|
|
62
71
|
def find_attributes_files(root_dir: str = '.') -> List[str]:
|
|
@@ -136,3 +145,44 @@ def find_unused_attributes(attr_file: str, adoc_root: str = '.') -> List[str]:
|
|
|
136
145
|
used = scan_for_attribute_usage(adoc_files, attributes)
|
|
137
146
|
unused = sorted(attributes - used)
|
|
138
147
|
return unused
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def comment_out_unused_attributes(attr_file: str, unused_attrs: List[str]) -> int:
|
|
151
|
+
"""
|
|
152
|
+
Comment out unused attributes in the attributes file.
|
|
153
|
+
|
|
154
|
+
Args:
|
|
155
|
+
attr_file: Path to the attributes file
|
|
156
|
+
unused_attrs: List of unused attribute names
|
|
157
|
+
|
|
158
|
+
Returns:
|
|
159
|
+
Number of attributes commented out
|
|
160
|
+
"""
|
|
161
|
+
if not unused_attrs:
|
|
162
|
+
return 0
|
|
163
|
+
|
|
164
|
+
# Read the file
|
|
165
|
+
with open(attr_file, 'r', encoding='utf-8') as f:
|
|
166
|
+
lines = f.readlines()
|
|
167
|
+
|
|
168
|
+
# Create a set for faster lookup
|
|
169
|
+
unused_set = set(unused_attrs)
|
|
170
|
+
commented_count = 0
|
|
171
|
+
|
|
172
|
+
# Process each line
|
|
173
|
+
new_lines = []
|
|
174
|
+
for line in lines:
|
|
175
|
+
# Check if this line defines an attribute
|
|
176
|
+
match = re.match(r'^:([\w-]+):', line)
|
|
177
|
+
if match and match.group(1) in unused_set:
|
|
178
|
+
# Comment out this line
|
|
179
|
+
new_lines.append(f'// Unused {line}')
|
|
180
|
+
commented_count += 1
|
|
181
|
+
else:
|
|
182
|
+
new_lines.append(line)
|
|
183
|
+
|
|
184
|
+
# Write back to the file
|
|
185
|
+
with open(attr_file, 'w', encoding='utf-8') as f:
|
|
186
|
+
f.writelines(new_lines)
|
|
187
|
+
|
|
188
|
+
return commented_count
|
find_unused_attributes.py
CHANGED
|
@@ -12,7 +12,7 @@ import argparse
|
|
|
12
12
|
import os
|
|
13
13
|
import sys
|
|
14
14
|
from datetime import datetime
|
|
15
|
-
from doc_utils.unused_attributes import find_unused_attributes, find_attributes_files, select_attributes_file
|
|
15
|
+
from doc_utils.unused_attributes import find_unused_attributes, find_attributes_files, select_attributes_file, comment_out_unused_attributes
|
|
16
16
|
from doc_utils.spinner import Spinner
|
|
17
17
|
from doc_utils.version_check import check_version_on_startup
|
|
18
18
|
|
|
@@ -26,6 +26,7 @@ def main():
|
|
|
26
26
|
help='Path to the attributes file. If not specified, auto-discovers attributes files.'
|
|
27
27
|
)
|
|
28
28
|
parser.add_argument('-o', '--output', action='store_true', help='Write results to a timestamped txt file in your home directory.')
|
|
29
|
+
parser.add_argument('-c', '--comment-out', action='store_true', help='Comment out unused attributes in the attributes file with "// Unused".')
|
|
29
30
|
args = parser.parse_args()
|
|
30
31
|
|
|
31
32
|
# Determine which attributes file to use
|
|
@@ -84,6 +85,16 @@ def main():
|
|
|
84
85
|
f.write(output + '\n')
|
|
85
86
|
print(f'Results written to: {filename}')
|
|
86
87
|
|
|
88
|
+
if args.comment_out and output:
|
|
89
|
+
# Ask for confirmation before modifying the file
|
|
90
|
+
print(f'\nThis will comment out {len(unused)} unused attributes in: {attr_file}')
|
|
91
|
+
response = input('Continue? (y/n): ').strip().lower()
|
|
92
|
+
if response == 'y':
|
|
93
|
+
commented_count = comment_out_unused_attributes(attr_file, unused)
|
|
94
|
+
print(f'Commented out {commented_count} unused attributes in: {attr_file}')
|
|
95
|
+
else:
|
|
96
|
+
print('Operation cancelled.')
|
|
97
|
+
|
|
87
98
|
return 0
|
|
88
99
|
|
|
89
100
|
if __name__ == '__main__':
|
|
@@ -2,7 +2,7 @@ archive_unused_files.py,sha256=VL4hEN40CTYJzScyevY1fn7Fs2O083qfJUYdrv5JxxM,2142
|
|
|
2
2
|
archive_unused_images.py,sha256=uZ4-OSMja98toyraDaeG6OMjV7kU2hq-QsTjnDl-BfQ,1732
|
|
3
3
|
check_scannability.py,sha256=IdHwzQtBWzx95zIDOx3B7OyzoKxTVtpn0wJUErFQRC0,5346
|
|
4
4
|
extract_link_attributes.py,sha256=bfWC6h4QWj6YvwZ3-tc3K7oMC2wN4QdA4YMCKcYdKCg,3384
|
|
5
|
-
find_unused_attributes.py,sha256=
|
|
5
|
+
find_unused_attributes.py,sha256=KYVhIgJobEtMzzVI4P7wkMym7Z6N27IdxQmg3qySvAo,4131
|
|
6
6
|
format_asciidoc_spacing.py,sha256=B3Bo68_i_RJNlUdNLZ4TiYUslrbwhSkzX3Dyd9JWRo0,4080
|
|
7
7
|
replace_link_attributes.py,sha256=OGD-COUG3JUCYOoARa32xqaSEcA-p31AJLk-d-FPUUQ,7492
|
|
8
8
|
validate_links.py,sha256=KmN4dULwLiLM2lUyteXwbBuTuQHcNkCq0nhiaZ48BtI,6013
|
|
@@ -15,13 +15,13 @@ doc_utils/scannability.py,sha256=XwlmHqDs69p_V36X7DLjPTy0DUoLszSGqYjJ9wE-3hg,982
|
|
|
15
15
|
doc_utils/spinner.py,sha256=lJg15qzODiKoR0G6uFIk2BdVNgn9jFexoTRUMrjiWvk,3554
|
|
16
16
|
doc_utils/topic_map_parser.py,sha256=tKcIO1m9r2K6dvPRGue58zqMr0O2zKU1gnZMzEE3U6o,4571
|
|
17
17
|
doc_utils/unused_adoc.py,sha256=2cbqcYr1os2EhETUU928BlPRlsZVSdI00qaMhqjSIqQ,5263
|
|
18
|
-
doc_utils/unused_attributes.py,sha256=
|
|
18
|
+
doc_utils/unused_attributes.py,sha256=EhbqPITy-f3PU8j2om5sUq0OtN1QwtyWD0G2TEx9rH8,6889
|
|
19
19
|
doc_utils/unused_images.py,sha256=nqn36Bbrmon2KlGlcaruNjJJvTQ8_9H0WU9GvCW7rW8,1456
|
|
20
20
|
doc_utils/validate_links.py,sha256=iBGXnwdeLlgIT3fo3v01ApT5k0X2FtctsvkrE6E3VMk,19610
|
|
21
21
|
doc_utils/version_check.py,sha256=1ySC6Au21OqUMZr7AkIa3nMNh3M6wLQmPQCi-ZFIqoE,6338
|
|
22
|
-
rolfedh_doc_utils-0.1.
|
|
23
|
-
rolfedh_doc_utils-0.1.
|
|
24
|
-
rolfedh_doc_utils-0.1.
|
|
25
|
-
rolfedh_doc_utils-0.1.
|
|
26
|
-
rolfedh_doc_utils-0.1.
|
|
27
|
-
rolfedh_doc_utils-0.1.
|
|
22
|
+
rolfedh_doc_utils-0.1.17.dist-info/licenses/LICENSE,sha256=vLxtwMVOJA_hEy8b77niTkdmQI9kNJskXHq0dBS36e0,1075
|
|
23
|
+
rolfedh_doc_utils-0.1.17.dist-info/METADATA,sha256=xj4KXU_A1ORuau9OuBst8DewvduJZ8rmdcBTEOKTXYw,7824
|
|
24
|
+
rolfedh_doc_utils-0.1.17.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
25
|
+
rolfedh_doc_utils-0.1.17.dist-info/entry_points.txt,sha256=2J4Ojc3kkuArpe2xcUOPc0LxSWCmnctvw8hy8zpnbO4,418
|
|
26
|
+
rolfedh_doc_utils-0.1.17.dist-info/top_level.txt,sha256=1w0JWD7w7gnM5Sga2K4fJieNZ7CHPTAf0ozYk5iIlmo,182
|
|
27
|
+
rolfedh_doc_utils-0.1.17.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|