acrolint 0.1.0__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.
acrolint/__init__.py ADDED
@@ -0,0 +1,2 @@
1
+ from .main import acrolint
2
+ from .main import output_file
acrolint/main.py ADDED
@@ -0,0 +1,146 @@
1
+ import re
2
+
3
+ def file_text_extract(file_path):
4
+ """
5
+ Extracts the text content from a file.
6
+
7
+ Args:
8
+ file_path (str): The path to the file.
9
+
10
+ Returns:
11
+ str: The text content of the file.
12
+ """
13
+ try:
14
+ with open(file_path, "r", encoding="utf-8") as f:
15
+ return f.read()
16
+ except Exception as e:
17
+ print(f"Error reading file {file_path}: {e}")
18
+ return ""
19
+ def regex_extract(pattern, text):
20
+ """
21
+ Extracts all matches of a regex pattern from the given text.
22
+
23
+ Args:
24
+ pattern (str): The regex pattern to search for.
25
+ text (str): The text to search within.
26
+
27
+ Returns:
28
+ list: A list of all matches found.
29
+ """
30
+ try:
31
+ return re.findall(pattern, text)
32
+ except re.error as e:
33
+ print(f"Regex error: {e}")
34
+ return []
35
+ def collect_acronyms(text):
36
+ """
37
+ Collects all acronyms from the specified file.
38
+
39
+ Args:
40
+ file_path (str): The path to the file.
41
+
42
+ Returns:
43
+ list: A list of all acronyms found.
44
+ """
45
+
46
+ # Simple regex to find acronyms (uppercase letters)
47
+ return regex_extract(r'\b[A-Z]{2,}\b', text)
48
+ def find_acronym_definitions(text):
49
+ """
50
+ Finds acronym definitions in the given text.
51
+
52
+ Args:
53
+ text (str): The text to search within.
54
+
55
+ Returns:
56
+ list: A list of all acronym definitions found.
57
+ """
58
+ patterns = [
59
+ r'([A-Z][A-Za-z\s\-&]+)\s*\(([A-Z]{2,10})\)',
60
+ r'\b([A-Z]{2,10})\s*\(([A-Z][A-Za-z\s\-&]+)\)']
61
+ results = []
62
+ for pattern in patterns:
63
+ results.extend(regex_extract(pattern, text))
64
+ return results
65
+
66
+ def find_undefined_acronyms(text, defined_acronyms):
67
+ all_acronyms = collect_acronyms(text)
68
+ all_unique_acronyms = set(all_acronyms)
69
+ defined_acronyms_short = [acronym[0] for acronym in defined_acronyms]
70
+
71
+ return [acronym for acronym in all_unique_acronyms if acronym not in defined_acronyms_short]
72
+ def index_to_line(text, index):
73
+ return text[:index].count("\n") + 1
74
+ def firstusage(files, pattern):
75
+ result = []
76
+ for file in files:
77
+ text = file_text_extract(file)
78
+
79
+ for match in re.finditer(pattern, text):
80
+ result.append(
81
+ index_to_line(text, match.start())
82
+ )
83
+
84
+ if match:
85
+ break # Stop searching after the first match in the current file
86
+ return result[0]
87
+ def output_file(file_path, orgonised_data):
88
+ if file_path.endswith(".json"):
89
+ import json
90
+ with open(file_path, "w", encoding="utf-8") as f:
91
+ json.dump(orgonised_data, f, indent=4)
92
+ def acrolint(file_paths):
93
+ """
94
+ Main function to process the given file paths and find acronyms and their definitions.
95
+
96
+ Args:
97
+ file_paths (list): A list of file paths to process.
98
+ Returns:
99
+ dict: A dictionary containing acronyms, their definitions, and first usage information.
100
+ """
101
+ orgonised_data = {}
102
+ for file_path in file_paths:
103
+ text = file_text_extract(file_path)
104
+ acronyms = find_acronym_definitions(text)
105
+ undefined_acronyms = find_undefined_acronyms(text, acronyms)
106
+
107
+ for acronym in undefined_acronyms:
108
+ first_usage = firstusage([file_path], r'\b' + re.escape(acronym) + r'\b')
109
+ orgonised_data[acronym] = {
110
+ "definition": None,
111
+ "first_usage": first_usage,
112
+ "defined": False
113
+ }
114
+
115
+ for acronym in acronyms:
116
+ first_usage = firstusage([file_path], r'\b' + re.escape(acronym[0]) + r'\b')
117
+ orgonised_data[acronym[0]] = {
118
+ "definition": acronym[1],
119
+ "first_usage": first_usage,
120
+ "defined": True
121
+ }
122
+ return orgonised_data
123
+
124
+ def main():
125
+ # Example usage
126
+ file_path = "tests/test_files/main.tex" # Replace with your file path
127
+ text = file_text_extract(file_path)
128
+ acronyms = find_acronym_definitions(text)
129
+ undefined_acronyms = find_undefined_acronyms(text, acronyms)
130
+ orgonised_data = {}
131
+ for acronym in undefined_acronyms:
132
+
133
+ first_usage = firstusage([file_path], r'\bAI\b')
134
+ orgonised_data[acronym] = {
135
+ "definition": None,
136
+ "first_usage": first_usage,
137
+ "defined": False
138
+ }
139
+ for acronym in acronyms:
140
+ first_usage = firstusage([file_path], r'\b' + re.escape(acronym[0]) + r'\b')
141
+ orgonised_data[acronym[0]] = {
142
+ "definition": acronym[1],
143
+ "first_usage": first_usage,
144
+ "defined": True
145
+ }
146
+ output_file("tests/test_files/output.json", orgonised_data)
@@ -0,0 +1,47 @@
1
+ Metadata-Version: 2.4
2
+ Name: acrolint
3
+ Version: 0.1.0
4
+ Summary: A linter for acronyms in text files.
5
+ Author: Mitchell Gerrard
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/Mitchell-Gerrard/acrolint
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Dynamic: license-file
15
+
16
+ # Acrolint
17
+
18
+ **Acrolint** is a extreamly light weight python library for extraction of acronyms used in your latex and text files, that grow to long to remeber where you used your BUAs (Big Ugly Actonyms)
19
+
20
+ ---
21
+
22
+ ## ✨ Features
23
+ - Extracting both the acrronyms and the deffintions for filling in any acronym pages to your work
24
+ - Detect any acronyms you did not define all the UDAs
25
+ - Track where they are first used sao you can fill in the deffinions or check they are deffomed were thy are firt used in your multi file project
26
+ - Suports multiple files
27
+ - JSON file output for the ability to store all of your acronyms and to enable down stream anaylysis
28
+
29
+ ---
30
+
31
+ ## 📦 Installation
32
+
33
+ ```bash
34
+ pip install acrolint
35
+
36
+ ## 💨 Fast start
37
+ from acrolint import acrolint, output_file
38
+
39
+ files = [
40
+ "chapter1.tex",
41
+ "chapter2.tex",
42
+ "chapter3.tex"
43
+ ]
44
+
45
+ result = acrolint(files)
46
+
47
+ output_file(result, "acronyms.json")
@@ -0,0 +1,7 @@
1
+ acrolint/__init__.py,sha256=Pc7tPUF1qzRV8yfESucIyvec79zJ6ruoJQzDmcXkLiw,56
2
+ acrolint/main.py,sha256=fs85Qs5TBJVVTOzAuJcd_sRTuiysCwKBpkMPXjej4Go,4627
3
+ acrolint-0.1.0.dist-info/licenses/LICENSE,sha256=VZ4ClAnzSICkzfnMkzQ8eV_BwidyFQMqlm1QkjumcBs,1072
4
+ acrolint-0.1.0.dist-info/METADATA,sha256=T-vYLW5kdCyfcd5wpSgoVJVZtBpad9LG_4Cboqojkkc,1364
5
+ acrolint-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ acrolint-0.1.0.dist-info/top_level.txt,sha256=kEd35b9DeV6UAeGdd9jOHdRVC_03ZetlRYr0kxhakVw,9
7
+ acrolint-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mitchell Gerrard
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 @@
1
+ acrolint