rolfedh-doc-utils 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Rolfe Dlugy-Hegwer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: rolfedh-doc-utils
3
+ Version: 0.1.0
4
+ Summary: CLI tools for AsciiDoc documentation projects
5
+ Author: Rolfe Dlugy-Hegwer
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Rolfe Dlugy-Hegwer
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Dynamic: license-file
32
+
33
+ # doc-utils
34
+
35
+ This repository contains modular Python utilities and CLI scripts to help technical writers with documentation tasks.
36
+
37
+ **Purpose:**
38
+ Each script is now a thin CLI wrapper that delegates to reusable modules in the `doc_utils` package. For details on how to use a script, see the initial docstring, comments, or the corresponding Markdown help file.
39
+
40
+ ## Current Scripts
41
+
42
+ - **check_scannability.py**
43
+ Checks the scannability of AsciiDoc (`.adoc`) files in the current directory. Reports sentences that are too long and paragraphs that contain too many sentences, based on configurable limits. See [check_scannability.md](check_scannability.md) for usage and examples.
44
+
45
+ - **archive_unused_files.py**
46
+ Scans `./modules` and `./assemblies` for AsciiDoc files not referenced by any other AsciiDoc file in the project. Optionally archives and deletes them. See [archive_unused_files.md](archive_unused_files.md) for usage and examples.
47
+
48
+ - **archive_unused_images.py**
49
+ Scans all directories for image files (e.g., `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`) not referenced by any AsciiDoc file in the project. Optionally archives and deletes them. See [archive_unused_images.md](archive_unused_images.md) for usage and examples.
50
+
51
+ - **find_unused_attributes.py**
52
+ Scans a user-specified attributes file (e.g., `attributes.adoc`) for attribute definitions (e.g., `:version:`) and recursively scans all `.adoc` files in the current directory for usages (e.g., `{version}`). Reports any attribute that is defined but not used in any `.adoc` file as **NOT USED** in both the command line output and a timestamped output file. See [find_unused_attributes.md](find_unused_attributes.md) for usage and examples.
53
+
54
+ ## Modular Python Package
55
+
56
+ The core logic for all scripts is implemented in the `doc_utils/` package. You can import and reuse these utilities in your own scripts or tests:
57
+
58
+ - `doc_utils.file_utils` — file collection, manifest, and archiving utilities
59
+ - `doc_utils.unused_images` — logic for finding and archiving unused images
60
+ - `doc_utils.unused_adoc` — logic for finding and archiving unused AsciiDoc files
61
+ - `doc_utils.scannability` — logic for checking AsciiDoc scannability
62
+ - `doc_utils.unused_attributes` — logic for finding unused AsciiDoc attributes
63
+
64
+ ## How to Use
65
+
66
+ 1. Open the script you are interested in (for example, `check_scannability.py` or `find_unused_attributes.py`).
67
+ 2. Read the top of the script or the corresponding `.md` file for instructions, options, and examples.
68
+ 3. Run the script from your terminal as described in the usage section.
69
+
70
+ ## Running Tests
71
+
72
+ To run all tests, install the development requirements and run pytest from the project root:
73
+
74
+ ```sh
75
+ pip install -r requirements-dev.txt
76
+ pytest
77
+ ```
78
+
79
+ All tests and fixtures are located in the `tests/` directory. See `tests/README.md` for details.
80
+
81
+ ---
82
+
83
+ *For licensing information, see [LICENSE](LICENSE).*
@@ -0,0 +1,51 @@
1
+ # doc-utils
2
+
3
+ This repository contains modular Python utilities and CLI scripts to help technical writers with documentation tasks.
4
+
5
+ **Purpose:**
6
+ Each script is now a thin CLI wrapper that delegates to reusable modules in the `doc_utils` package. For details on how to use a script, see the initial docstring, comments, or the corresponding Markdown help file.
7
+
8
+ ## Current Scripts
9
+
10
+ - **check_scannability.py**
11
+ Checks the scannability of AsciiDoc (`.adoc`) files in the current directory. Reports sentences that are too long and paragraphs that contain too many sentences, based on configurable limits. See [check_scannability.md](check_scannability.md) for usage and examples.
12
+
13
+ - **archive_unused_files.py**
14
+ Scans `./modules` and `./assemblies` for AsciiDoc files not referenced by any other AsciiDoc file in the project. Optionally archives and deletes them. See [archive_unused_files.md](archive_unused_files.md) for usage and examples.
15
+
16
+ - **archive_unused_images.py**
17
+ Scans all directories for image files (e.g., `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`) not referenced by any AsciiDoc file in the project. Optionally archives and deletes them. See [archive_unused_images.md](archive_unused_images.md) for usage and examples.
18
+
19
+ - **find_unused_attributes.py**
20
+ Scans a user-specified attributes file (e.g., `attributes.adoc`) for attribute definitions (e.g., `:version:`) and recursively scans all `.adoc` files in the current directory for usages (e.g., `{version}`). Reports any attribute that is defined but not used in any `.adoc` file as **NOT USED** in both the command line output and a timestamped output file. See [find_unused_attributes.md](find_unused_attributes.md) for usage and examples.
21
+
22
+ ## Modular Python Package
23
+
24
+ The core logic for all scripts is implemented in the `doc_utils/` package. You can import and reuse these utilities in your own scripts or tests:
25
+
26
+ - `doc_utils.file_utils` — file collection, manifest, and archiving utilities
27
+ - `doc_utils.unused_images` — logic for finding and archiving unused images
28
+ - `doc_utils.unused_adoc` — logic for finding and archiving unused AsciiDoc files
29
+ - `doc_utils.scannability` — logic for checking AsciiDoc scannability
30
+ - `doc_utils.unused_attributes` — logic for finding unused AsciiDoc attributes
31
+
32
+ ## How to Use
33
+
34
+ 1. Open the script you are interested in (for example, `check_scannability.py` or `find_unused_attributes.py`).
35
+ 2. Read the top of the script or the corresponding `.md` file for instructions, options, and examples.
36
+ 3. Run the script from your terminal as described in the usage section.
37
+
38
+ ## Running Tests
39
+
40
+ To run all tests, install the development requirements and run pytest from the project root:
41
+
42
+ ```sh
43
+ pip install -r requirements-dev.txt
44
+ pytest
45
+ ```
46
+
47
+ All tests and fixtures are located in the `tests/` directory. See `tests/README.md` for details.
48
+
49
+ ---
50
+
51
+ *For licensing information, see [LICENSE](LICENSE).*
@@ -0,0 +1,3 @@
1
+ # doc_utils/__init__.py
2
+
3
+ # This file marks doc_utils as a Python package.
@@ -0,0 +1,60 @@
1
+ # doc_utils/file_utils.py
2
+
3
+ import os
4
+ import re
5
+ import zipfile
6
+ from datetime import datetime
7
+
8
+
9
+ def collect_files(scan_dirs, extensions, exclude_dirs=None, exclude_files=None):
10
+ """
11
+ Recursively collect files with given extensions from scan_dirs, excluding symlinks, exclude_dirs, and exclude_files.
12
+ Returns a list of normalized file paths.
13
+ """
14
+ exclude_dirs = set(os.path.abspath(os.path.normpath(d)) for d in (exclude_dirs or []))
15
+ exclude_files = set(os.path.abspath(os.path.normpath(f)) for f in (exclude_files or []))
16
+ found_files = []
17
+ for base_dir in scan_dirs:
18
+ for root, dirs, files in os.walk(base_dir):
19
+ abs_root = os.path.abspath(root)
20
+ # Exclude directories by absolute path
21
+ dirs[:] = [d for d in dirs if not os.path.islink(os.path.join(root, d)) and os.path.abspath(os.path.join(root, d)) not in exclude_dirs]
22
+ for f in files:
23
+ file_path = os.path.normpath(os.path.join(root, f))
24
+ abs_file_path = os.path.abspath(file_path)
25
+ if os.path.islink(file_path):
26
+ continue
27
+ if abs_file_path in exclude_files:
28
+ continue
29
+ if os.path.splitext(f)[1].lower() in extensions:
30
+ found_files.append(file_path)
31
+ return list(dict.fromkeys(found_files))
32
+
33
+
34
+ def write_manifest_and_archive(unused_files, archive_dir, manifest_prefix, archive_prefix, archive=False):
35
+ """
36
+ Write a manifest of unused files and optionally archive and delete them.
37
+ Returns the manifest path and (if archive=True) the archive path.
38
+ """
39
+ if not unused_files:
40
+ print("No unused files found. No manifest or ZIP archive created.")
41
+ return None, None
42
+ now = datetime.now()
43
+ datetime_str = now.strftime('%Y-%m-%d_%H%M%S')
44
+ output_file = f'{manifest_prefix}-{datetime_str}.txt'
45
+ os.makedirs(archive_dir, exist_ok=True)
46
+ manifest_path = os.path.join(archive_dir, output_file)
47
+ with open(manifest_path, 'w') as f:
48
+ for file in unused_files:
49
+ print(file)
50
+ f.write(file + '\n')
51
+ archive_path = None
52
+ if archive:
53
+ archive_path = os.path.join(archive_dir, f"{archive_prefix}-{datetime_str}.zip")
54
+ with zipfile.ZipFile(archive_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
55
+ for file in unused_files:
56
+ arcname = os.path.relpath(file)
57
+ print(f"Archiving: {file} -> {archive_path} ({arcname})")
58
+ zipf.write(file, arcname)
59
+ os.remove(file)
60
+ return manifest_path, archive_path
@@ -0,0 +1,23 @@
1
+ # doc_utils/scannability.py
2
+
3
+ import os
4
+ import re
5
+
6
+ def check_scannability(adoc_files, max_sentence_length=22, max_paragraph_sentences=3):
7
+ long_sentences = []
8
+ long_paragraphs = []
9
+ for file_path in adoc_files:
10
+ try:
11
+ with open(file_path, 'r', encoding='utf-8') as f:
12
+ content = f.read()
13
+ paragraphs = content.split('\n\n')
14
+ for i, para in enumerate(paragraphs):
15
+ sentences = re.split(r'(?<=[.!?]) +', para.strip())
16
+ for sent in sentences:
17
+ if len(sent.split()) > max_sentence_length:
18
+ long_sentences.append((file_path, i+1, sent.strip()))
19
+ if len(sentences) > max_paragraph_sentences:
20
+ long_paragraphs.append((file_path, i+1, len(sentences)))
21
+ except Exception as e:
22
+ print(f"Warning: could not read {file_path}: {e}")
23
+ return long_sentences, long_paragraphs
@@ -0,0 +1,24 @@
1
+ # doc_utils/unused_adoc.py
2
+
3
+ import os
4
+ import re
5
+ from .file_utils import collect_files, write_manifest_and_archive
6
+
7
+ def find_unused_adoc(scan_dirs, archive_dir, archive=False, exclude_dirs=None, exclude_files=None):
8
+ asciidoc_files = collect_files(scan_dirs, {'.adoc'}, exclude_dirs, exclude_files)
9
+ include_pattern = re.compile(r'include::(.+?)\[')
10
+ included_files = set()
11
+ adoc_files = collect_files(['.'], {'.adoc'}, exclude_dirs, exclude_files)
12
+ for file_path in adoc_files:
13
+ try:
14
+ with open(file_path, 'r', encoding='utf-8') as f:
15
+ content = f.read()
16
+ includes = include_pattern.findall(content)
17
+ included_files.update(os.path.basename(include) for include in includes)
18
+ except Exception as e:
19
+ print(f"Warning: could not read {file_path}: {e}")
20
+ unused_files = [f for f in asciidoc_files if os.path.basename(f) not in included_files]
21
+ unused_files = list(dict.fromkeys(unused_files))
22
+ return write_manifest_and_archive(
23
+ unused_files, archive_dir, 'to-archive', 'to-archive', archive=archive
24
+ )
@@ -0,0 +1,50 @@
1
+ """
2
+ Module for finding unused AsciiDoc attributes.
3
+
4
+ Functions:
5
+ - parse_attributes_file: Parse attribute names from an attributes.adoc file.
6
+ - find_adoc_files: Recursively find all .adoc files in a directory (ignoring symlinks).
7
+ - scan_for_attribute_usage: Find which attributes are used in a set of .adoc files.
8
+ - find_unused_attributes: Main function to return unused attributes.
9
+ """
10
+
11
+ import os
12
+ import re
13
+ from typing import Set, List
14
+
15
+ def parse_attributes_file(attr_file: str) -> Set[str]:
16
+ attributes = set()
17
+ with open(attr_file, 'r', encoding='utf-8') as f:
18
+ for line in f:
19
+ match = re.match(r'^:([\w-]+):', line.strip())
20
+ if match:
21
+ attributes.add(match.group(1))
22
+ return attributes
23
+
24
+ def find_adoc_files(root_dir: str) -> List[str]:
25
+ adoc_files = []
26
+ for dirpath, dirnames, filenames in os.walk(root_dir, followlinks=False):
27
+ for fname in filenames:
28
+ if fname.endswith('.adoc'):
29
+ full_path = os.path.join(dirpath, fname)
30
+ if not os.path.islink(full_path):
31
+ adoc_files.append(full_path)
32
+ return adoc_files
33
+
34
+ def scan_for_attribute_usage(adoc_files: List[str], attributes: Set[str]) -> Set[str]:
35
+ used = set()
36
+ attr_pattern = re.compile(r'\{([\w-]+)\}')
37
+ for file in adoc_files:
38
+ with open(file, 'r', encoding='utf-8') as f:
39
+ for line in f:
40
+ for match in attr_pattern.findall(line):
41
+ if match in attributes:
42
+ used.add(match)
43
+ return used
44
+
45
+ def find_unused_attributes(attr_file: str, adoc_root: str = '.') -> List[str]:
46
+ attributes = parse_attributes_file(attr_file)
47
+ adoc_files = find_adoc_files(adoc_root)
48
+ used = scan_for_attribute_usage(adoc_files, attributes)
49
+ unused = sorted(attributes - used)
50
+ return unused
@@ -0,0 +1,28 @@
1
+ # doc_utils/unused_images.py
2
+
3
+ import os
4
+ import re
5
+ from .file_utils import collect_files, write_manifest_and_archive
6
+
7
+ IMAGE_EXTENSIONS = {'.png', '.jpg', '.jpeg', '.gif', '.svg'}
8
+
9
+ def find_unused_images(scan_dirs, archive_dir, archive=False, exclude_dirs=None, exclude_files=None):
10
+ image_files = collect_files(scan_dirs, IMAGE_EXTENSIONS, exclude_dirs, exclude_files)
11
+ adoc_files = collect_files(['.'], {'.adoc'}, exclude_dirs, exclude_files)
12
+ referenced_images = set()
13
+ image_ref_pattern = re.compile(r'(?i)image::([^\[]+)[\[]|image:([^\[]+)[\[]|"([^"\s]+\.(?:png|jpg|jpeg|gif|svg))"')
14
+ for adoc_file in adoc_files:
15
+ try:
16
+ with open(adoc_file, 'r', encoding='utf-8') as f:
17
+ content = f.read()
18
+ for match in image_ref_pattern.findall(content):
19
+ for group in match:
20
+ if group:
21
+ referenced_images.add(os.path.basename(group))
22
+ except Exception as e:
23
+ print(f"Warning: could not read {adoc_file}: {e}")
24
+ unused_images = [f for f in image_files if os.path.basename(f) not in referenced_images]
25
+ unused_images = list(dict.fromkeys(unused_images))
26
+ return write_manifest_and_archive(
27
+ unused_images, archive_dir, 'unused-images', 'unused-images', archive=archive
28
+ )
@@ -0,0 +1,25 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "rolfedh-doc-utils"
7
+ version = "0.1.0"
8
+ description = "CLI tools for AsciiDoc documentation projects"
9
+ readme = "README.md"
10
+ requires-python = ">=3.8"
11
+ license = { file = "LICENSE" }
12
+ authors = [
13
+ { name="Rolfe Dlugy-Hegwer" }
14
+ ]
15
+ dependencies = []
16
+
17
+ [project.scripts]
18
+ check-scannability = "check_scannability:main"
19
+ archive-unused-files = "archive_unused_files:main"
20
+ archive-unused-images = "archive_unused_images:main"
21
+ find-unused-attributes = "find_unused_attributes:main"
22
+
23
+ [tool.setuptools.packages.find]
24
+ where = ["."]
25
+ include = ["doc_utils*"]
@@ -0,0 +1,83 @@
1
+ Metadata-Version: 2.4
2
+ Name: rolfedh-doc-utils
3
+ Version: 0.1.0
4
+ Summary: CLI tools for AsciiDoc documentation projects
5
+ Author: Rolfe Dlugy-Hegwer
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Rolfe Dlugy-Hegwer
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Dynamic: license-file
32
+
33
+ # doc-utils
34
+
35
+ This repository contains modular Python utilities and CLI scripts to help technical writers with documentation tasks.
36
+
37
+ **Purpose:**
38
+ Each script is now a thin CLI wrapper that delegates to reusable modules in the `doc_utils` package. For details on how to use a script, see the initial docstring, comments, or the corresponding Markdown help file.
39
+
40
+ ## Current Scripts
41
+
42
+ - **check_scannability.py**
43
+ Checks the scannability of AsciiDoc (`.adoc`) files in the current directory. Reports sentences that are too long and paragraphs that contain too many sentences, based on configurable limits. See [check_scannability.md](check_scannability.md) for usage and examples.
44
+
45
+ - **archive_unused_files.py**
46
+ Scans `./modules` and `./assemblies` for AsciiDoc files not referenced by any other AsciiDoc file in the project. Optionally archives and deletes them. See [archive_unused_files.md](archive_unused_files.md) for usage and examples.
47
+
48
+ - **archive_unused_images.py**
49
+ Scans all directories for image files (e.g., `.png`, `.jpg`, `.jpeg`, `.gif`, `.svg`) not referenced by any AsciiDoc file in the project. Optionally archives and deletes them. See [archive_unused_images.md](archive_unused_images.md) for usage and examples.
50
+
51
+ - **find_unused_attributes.py**
52
+ Scans a user-specified attributes file (e.g., `attributes.adoc`) for attribute definitions (e.g., `:version:`) and recursively scans all `.adoc` files in the current directory for usages (e.g., `{version}`). Reports any attribute that is defined but not used in any `.adoc` file as **NOT USED** in both the command line output and a timestamped output file. See [find_unused_attributes.md](find_unused_attributes.md) for usage and examples.
53
+
54
+ ## Modular Python Package
55
+
56
+ The core logic for all scripts is implemented in the `doc_utils/` package. You can import and reuse these utilities in your own scripts or tests:
57
+
58
+ - `doc_utils.file_utils` — file collection, manifest, and archiving utilities
59
+ - `doc_utils.unused_images` — logic for finding and archiving unused images
60
+ - `doc_utils.unused_adoc` — logic for finding and archiving unused AsciiDoc files
61
+ - `doc_utils.scannability` — logic for checking AsciiDoc scannability
62
+ - `doc_utils.unused_attributes` — logic for finding unused AsciiDoc attributes
63
+
64
+ ## How to Use
65
+
66
+ 1. Open the script you are interested in (for example, `check_scannability.py` or `find_unused_attributes.py`).
67
+ 2. Read the top of the script or the corresponding `.md` file for instructions, options, and examples.
68
+ 3. Run the script from your terminal as described in the usage section.
69
+
70
+ ## Running Tests
71
+
72
+ To run all tests, install the development requirements and run pytest from the project root:
73
+
74
+ ```sh
75
+ pip install -r requirements-dev.txt
76
+ pytest
77
+ ```
78
+
79
+ All tests and fixtures are located in the `tests/` directory. See `tests/README.md` for details.
80
+
81
+ ---
82
+
83
+ *For licensing information, see [LICENSE](LICENSE).*
@@ -0,0 +1,18 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ doc_utils/__init__.py
5
+ doc_utils/file_utils.py
6
+ doc_utils/scannability.py
7
+ doc_utils/unused_adoc.py
8
+ doc_utils/unused_attributes.py
9
+ doc_utils/unused_images.py
10
+ rolfedh_doc_utils.egg-info/PKG-INFO
11
+ rolfedh_doc_utils.egg-info/SOURCES.txt
12
+ rolfedh_doc_utils.egg-info/dependency_links.txt
13
+ rolfedh_doc_utils.egg-info/entry_points.txt
14
+ rolfedh_doc_utils.egg-info/top_level.txt
15
+ tests/test_archive_unused_files.py
16
+ tests/test_archive_unused_images.py
17
+ tests/test_check_scannability.py
18
+ tests/test_unused_attributes.py
@@ -0,0 +1,5 @@
1
+ [console_scripts]
2
+ archive-unused-files = archive_unused_files:main
3
+ archive-unused-images = archive_unused_images:main
4
+ check-scannability = check_scannability:main
5
+ find-unused-attributes = find_unused_attributes:main
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,46 @@
1
+ import os
2
+ import sys
3
+ import tempfile
4
+ import shutil
5
+ import pytest
6
+ from test_fixture_archive_unused_files import setup_test_fixture_archive_unused_files
7
+ import subprocess
8
+
9
+ SCRIPT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'archive_unused_files.py'))
10
+
11
+ def run_script(args, cwd):
12
+ result = subprocess.run([sys.executable, SCRIPT] + args, cwd=cwd, capture_output=True, text=True)
13
+ return result
14
+
15
+ def test_archive_unused_files_basic():
16
+ with tempfile.TemporaryDirectory() as tmpdir:
17
+ setup_test_fixture_archive_unused_files(tmpdir)
18
+ result = run_script([], cwd=tmpdir)
19
+ assert 'unused1.adoc' in result.stdout
20
+ assert 'unused2.adoc' in result.stdout
21
+ assert 'used.adoc' not in result.stdout
22
+ # Manifest file should be created in archive
23
+ archive_dir = os.path.join(tmpdir, 'archive')
24
+ manifest_files = [f for f in os.listdir(archive_dir) if f.startswith('to-archive-') and f.endswith('.txt')]
25
+ assert manifest_files
26
+
27
+ @pytest.mark.parametrize('exclude_args,should_find', [
28
+ (['--exclude-file', './modules/unused1.adoc'], 'unused2.adoc'),
29
+ (['--exclude-dir', './modules'], None),
30
+ ])
31
+ def test_archive_unused_files_exclusions(exclude_args, should_find):
32
+ with tempfile.TemporaryDirectory() as tmpdir:
33
+ setup_test_fixture_archive_unused_files(tmpdir)
34
+ result = run_script(exclude_args, cwd=tmpdir)
35
+ archive_dir = os.path.join(tmpdir, 'archive')
36
+ manifest_files = [f for f in os.listdir(archive_dir) if f.startswith('to-archive-') and f.endswith('.txt')]
37
+ assert manifest_files
38
+ manifest_path = os.path.join(archive_dir, manifest_files[0])
39
+ with open(manifest_path, 'r', encoding='utf-8') as f:
40
+ manifest_content = f.read()
41
+ if should_find:
42
+ assert should_find in manifest_content
43
+ else:
44
+ # If all modules are excluded, no unused files from './modules' should be present
45
+ assert 'modules/unused1.adoc' not in manifest_content
46
+ assert 'modules/unused2.adoc' not in manifest_content
@@ -0,0 +1,41 @@
1
+ import os
2
+ import sys
3
+ import tempfile
4
+ import shutil
5
+ import pytest
6
+ from test_fixture_archive_unused_images import setup_test_fixture
7
+ import subprocess
8
+
9
+ SCRIPT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'archive_unused_images.py'))
10
+
11
+ def run_script(args, cwd):
12
+ result = subprocess.run([sys.executable, SCRIPT] + args, cwd=cwd, capture_output=True, text=True)
13
+ return result
14
+
15
+ def test_archive_unused_images_basic():
16
+ with tempfile.TemporaryDirectory() as tmpdir:
17
+ setup_test_fixture(tmpdir)
18
+ result = run_script([], cwd=tmpdir)
19
+ assert 'unused1.png' in result.stdout
20
+ assert 'unused2.jpg' in result.stdout
21
+ assert 'used1.png' not in result.stdout
22
+ assert 'used2.jpg' not in result.stdout
23
+ # Manifest file should be created in archive
24
+ archive_dir = os.path.join(tmpdir, 'archive')
25
+ manifest_files = [f for f in os.listdir(archive_dir) if f.startswith('unused-images-') and f.endswith('.txt')]
26
+ assert manifest_files
27
+
28
+ @pytest.mark.parametrize('exclude_args,should_find', [
29
+ (['--exclude-file', './images/unused1.png'], 'unused2.jpg'),
30
+ (['--exclude-dir', './images'], None),
31
+ ])
32
+ def test_archive_unused_images_exclusions(exclude_args, should_find):
33
+ with tempfile.TemporaryDirectory() as tmpdir:
34
+ setup_test_fixture(tmpdir)
35
+ result = run_script(exclude_args, cwd=tmpdir)
36
+ if should_find:
37
+ assert should_find in result.stdout
38
+ else:
39
+ # If all images are excluded, no unused images from './images' should be present
40
+ assert 'images/unused1.png' not in result.stdout
41
+ assert 'images/unused2.jpg' not in result.stdout
@@ -0,0 +1,53 @@
1
+ import sys
2
+ import os
3
+ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
4
+
5
+ import tempfile
6
+ import pytest
7
+ from test_fixture_check_scannability import setup_test_fixture_check_scannability
8
+ import subprocess
9
+
10
+ SCRIPT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'check_scannability.py'))
11
+
12
+ def run_script(args, cwd):
13
+ result = subprocess.run([sys.executable, SCRIPT] + args, cwd=cwd, capture_output=True, text=True)
14
+ return result
15
+
16
+ def test_check_scannability_basic():
17
+ with tempfile.TemporaryDirectory() as tmpdir:
18
+ setup_test_fixture_check_scannability(tmpdir)
19
+ result = run_script([], cwd=tmpdir)
20
+ # Should flag the long sentence and long paragraph in test1.adoc
21
+ assert 'Sentence exceeds' in result.stdout or 'Paragraph exceeds' in result.stdout
22
+ # Should not flag test2.adoc
23
+ assert 'test2.adoc' not in result.stderr
24
+
25
+ @pytest.mark.parametrize('args,should_flag', [
26
+ (['--max-sentence-length', '10'], True),
27
+ (['--max-paragraph-sentences', '3'], True),
28
+ ])
29
+ def test_check_scannability_custom_limits(args, should_flag):
30
+ with tempfile.TemporaryDirectory() as tmpdir:
31
+ setup_test_fixture_check_scannability(tmpdir)
32
+ result = run_script(args, cwd=tmpdir)
33
+ if should_flag:
34
+ assert 'Sentence exceeds' in result.stdout or 'Paragraph exceeds' in result.stdout
35
+
36
+ def test_check_scannability_short_options():
37
+ with tempfile.TemporaryDirectory() as tmpdir:
38
+ setup_test_fixture_check_scannability(tmpdir)
39
+ # Use short options -s and -p
40
+ result = run_script(['-s', '10', '-p', '2'], cwd=tmpdir)
41
+ assert 'Sentence exceeds' in result.stdout or 'Paragraph exceeds' in result.stdout
42
+
43
+ def test_check_scannability_defaults():
44
+ with tempfile.TemporaryDirectory() as tmpdir:
45
+ setup_test_fixture_check_scannability(tmpdir)
46
+ # No options: should use 22 and 3 as limits
47
+ result = run_script([], cwd=tmpdir)
48
+ # Should flag the long sentence and long paragraph in test1.adoc
49
+ assert 'Sentence exceeds' in result.stdout or 'Paragraph exceeds' in result.stdout
50
+
51
+ def test_check_scannability_help():
52
+ result = run_script(['-h'], cwd=os.getcwd())
53
+ assert 'Scannability Checker' in result.stdout or 'usage' in result.stdout
@@ -0,0 +1,44 @@
1
+ import os
2
+ import tempfile
3
+ from doc_utils.unused_attributes import parse_attributes_file, find_adoc_files, scan_for_attribute_usage, find_unused_attributes
4
+
5
+ def make_file(path, content):
6
+ with open(path, 'w', encoding='utf-8') as f:
7
+ f.write(content)
8
+
9
+ def test_parse_attributes_file():
10
+ with tempfile.TemporaryDirectory() as tmpdir:
11
+ attr_path = os.path.join(tmpdir, 'attributes.adoc')
12
+ make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
13
+ attrs = parse_attributes_file(attr_path)
14
+ assert 'foo' in attrs
15
+ assert 'bar' in attrs
16
+ assert 'unused' in attrs
17
+
18
+ def test_find_adoc_files_and_usage():
19
+ with tempfile.TemporaryDirectory() as tmpdir:
20
+ attr_path = os.path.join(tmpdir, 'attributes.adoc')
21
+ make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
22
+ adoc1 = os.path.join(tmpdir, 'a.adoc')
23
+ adoc2 = os.path.join(tmpdir, 'b.adoc')
24
+ make_file(adoc1, "This uses {foo} and {bar}.")
25
+ make_file(adoc2, "No attributes here.")
26
+ adoc_files = find_adoc_files(tmpdir)
27
+ attrs = parse_attributes_file(attr_path)
28
+ used = scan_for_attribute_usage(adoc_files, attrs)
29
+ assert 'foo' in used
30
+ assert 'bar' in used
31
+ assert 'unused' not in used
32
+
33
+ def test_find_unused_attributes():
34
+ with tempfile.TemporaryDirectory() as tmpdir:
35
+ attr_path = os.path.join(tmpdir, 'attributes.adoc')
36
+ make_file(attr_path, ":foo: bar\n:bar: baz\n:unused: 123\n")
37
+ adoc1 = os.path.join(tmpdir, 'a.adoc')
38
+ adoc2 = os.path.join(tmpdir, 'b.adoc')
39
+ make_file(adoc1, "This uses {foo} and {bar}.")
40
+ make_file(adoc2, "No attributes here.")
41
+ unused = find_unused_attributes(attr_path, tmpdir)
42
+ assert 'unused' in unused
43
+ assert 'foo' not in unused
44
+ assert 'bar' not in unused