- Removed trailing whitespace and ensured files end with a single newline in cleanup_unused_files.py. - Added fix_trailing_whitespace.py to batch remove trailing whitespace from Python files. - Updated install_dependencies.py to improve dependency installation prompts. - Cleaned up pick_coords.py by removing unnecessary whitespace and improving code readability. - Enhanced region_selector.py by disabling specific pylint checks for better compatibility with third-party libraries. - Improved WPS流程图生成工具.py by cleaning up whitespace and enhancing readability. - Updated __init__.py in typings to remove unnecessary lines. - Modified app.js to adjust default configuration values and clean up unused code.
47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""批量移除 Python 文件尾随空白并确保文件以单一换行结束。"""
|
|
import os
|
|
import io
|
|
|
|
def should_skip(path):
|
|
parts = path.split(os.sep)
|
|
return any(p.startswith('.') or p == '__pycache__' or p == '.venv' for p in parts)
|
|
|
|
root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
|
|
count = 0
|
|
changed_files = []
|
|
for dirpath, dirnames, filenames in os.walk(root):
|
|
# skip venv and hidden dirs
|
|
if should_skip(dirpath):
|
|
continue
|
|
for fname in filenames:
|
|
if not fname.endswith('.py'):
|
|
continue
|
|
fpath = os.path.join(dirpath, fname)
|
|
if should_skip(fpath):
|
|
continue
|
|
try:
|
|
with io.open(fpath, 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
except Exception:
|
|
continue
|
|
new_lines = [line.rstrip() + '\n' for line in lines]
|
|
# remove extra final newlines: ensure exactly one final newline
|
|
if new_lines:
|
|
# strip trailing empty lines
|
|
while len(new_lines) > 1 and new_lines[-1].strip() == '':
|
|
new_lines.pop()
|
|
if not new_lines[-1].endswith('\n'):
|
|
new_lines[-1] = new_lines[-1] + '\n'
|
|
new_text = ''.join(new_lines)
|
|
old_text = ''.join(lines)
|
|
if new_text != old_text:
|
|
with io.open(fpath, 'w', encoding='utf-8', newline='\n') as f:
|
|
f.write(new_text)
|
|
changed_files.append(fpath)
|
|
count += 1
|
|
|
|
print(f"Processed {count} files; modified: {len(changed_files)}")
|
|
for p in changed_files:
|
|
print(p)
|