-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_docstringinator_files.py
More file actions
118 lines (90 loc) · 3.03 KB
/
run_docstringinator_files.py
File metadata and controls
118 lines (90 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/env python3
"""Script to run docstringinator on specific files passed as arguments."""
import sys
from pathlib import Path
# Add the docstringinator package to the path
sys.path.insert(0, str(Path(__file__).parent))
from docstringinator.core import Docstringinator
def should_exclude_file(file_path: str) -> bool:
"""
Determines whether a file should be excluded from analysis based on its path.
Args:
file_path (str, optional): The full path of the file to check. Defaults to None.
Returns:
bool: True if the file should be excluded, False otherwise.
Raises:
TypeError: If file_path is not a string.
Example:
>>> should_exclude_file('/path/to/excluded/file.txt')
True
>>> should_exclude_file(None)
False
"""
exclude_patterns = [
"/tests/",
"/migrations/",
"/venv/",
"/.venv/",
"/.git/",
"/.github/",
"/.vscode/",
"/.idea/",
"/.pytest_cache/",
"/.mypy_cache/",
"/.ruff_cache/",
"/.coverage/",
"/.tox/",
"/.eggs/",
"/.eggs-info/",
"/__pycache__/",
"/build/",
"/dist/",
"/node_modules/",
]
file_path_lower = file_path.lower()
return any(pattern in file_path_lower for pattern in exclude_patterns)
def main() -> None:
"""
Analyse and process files within the specified directory.
This function serves as the entry point for the application, responsible for initiating the file analysis process. It does not accept any parameters and returns no value.
Raises:
FileNotFoundError: If the specified directory does not exist.
PermissionError: If the script lacks permission to access the directory or its contents.
Example:
>>> main()
"""
if len(sys.argv) < 2:
sys.exit(1)
try:
# Initialize docstringinator with the YAML config
docstringinator = Docstringinator(config_path="docstringinator.yaml")
# Get files from command line arguments
files = sys.argv[1:]
# Filter Python files and exclude hidden directories
python_files = [f for f in files if f.endswith(".py")]
files_to_process = [f for f in python_files if not should_exclude_file(f)]
if not files_to_process:
return
# Process each file individually
successful_files = 0
failed_files = 0
for file_path in files_to_process:
try:
result = docstringinator.fix_file(file_path)
if result.success:
if result.changes:
successful_files += 1
else:
pass
else:
failed_files += 1
except Exception:
failed_files += 1
if failed_files > 0:
sys.exit(1)
except Exception:
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
main()